本文整理汇总了PHP中Manufacturer::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Manufacturer::add方法的具体用法?PHP Manufacturer::add怎么用?PHP Manufacturer::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Manufacturer
的用法示例。
在下文中一共展示了Manufacturer::add方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addressImportOne
protected function addressImportOne($info, $force_ids, $validateOnly = false)
{
AdminImportController::setDefaultValues($info);
if ($force_ids && isset($info['id']) && (int) $info['id']) {
$address = new Address((int) $info['id']);
} else {
if (array_key_exists('id', $info) && (int) $info['id'] && Address::addressExists((int) $info['id'])) {
$address = new Address((int) $info['id']);
} else {
$address = new Address();
}
}
AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $address);
if (isset($address->country) && is_numeric($address->country)) {
if (Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), (int) $address->country)) {
$address->id_country = (int) $address->country;
}
} elseif (isset($address->country) && is_string($address->country) && !empty($address->country)) {
if ($id_country = Country::getIdByName(null, $address->country)) {
$address->id_country = (int) $id_country;
} else {
$country = new Country();
$country->active = 1;
$country->name = AdminImportController::createMultiLangField($address->country);
$country->id_zone = 0;
// Default zone for country to create
$country->iso_code = Tools::strtoupper(Tools::substr($address->country, 0, 2));
// Default iso for country to create
$country->contains_states = 0;
// Default value for country to create
$lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true);
if (($field_error = $country->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $country->add()) {
$address->id_country = (int) $country->id;
} else {
if (!$validateOnly) {
$default_language_id = (int) Configuration::get('PS_LANG_DEFAULT');
$this->errors[] = sprintf($this->trans('%s cannot be saved', array(), 'Admin.Parameters.Notification'), $country->name[$default_language_id]);
}
if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) {
$this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
}
}
}
}
if (isset($address->state) && is_numeric($address->state)) {
if (State::getNameById((int) $address->state)) {
$address->id_state = (int) $address->state;
}
} elseif (isset($address->state) && is_string($address->state) && !empty($address->state)) {
if ($id_state = State::getIdByName($address->state)) {
$address->id_state = (int) $id_state;
} else {
$state = new State();
$state->active = 1;
$state->name = $address->state;
$state->id_country = isset($country->id) ? (int) $country->id : 0;
$state->id_zone = 0;
// Default zone for state to create
$state->iso_code = Tools::strtoupper(Tools::substr($address->state, 0, 2));
// Default iso for state to create
$state->tax_behavior = 0;
if (($field_error = $state->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $state->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $state->add()) {
$address->id_state = (int) $state->id;
} else {
if (!$validateOnly) {
$this->errors[] = sprintf($this->trans('%s cannot be saved', array(), 'Admin.Parameters.Notification'), $state->name);
}
if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) {
$this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
}
}
}
}
if (isset($address->customer_email) && !empty($address->customer_email)) {
if (Validate::isEmail($address->customer_email)) {
// a customer could exists in different shop
$customer_list = Customer::getCustomersByEmail($address->customer_email);
if (count($customer_list) == 0) {
$this->errors[] = sprintf(Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s), and therefore cannot be ' . ($validateOnly ? 'validated' : 'saved')), Db::getInstance()->getMsgError(), $address->customer_email, isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null');
}
} else {
$this->errors[] = sprintf($this->trans('"%s" is not a valid email address.', array(), 'Admin.Parameters.Notification'), $address->customer_email);
return;
}
} elseif (isset($address->id_customer) && !empty($address->id_customer)) {
if (Customer::customerIdExistsStatic((int) $address->id_customer)) {
$customer = new Customer((int) $address->id_customer);
// a customer could exists in different shop
$customer_list = Customer::getCustomersByEmail($customer->email);
if (count($customer_list) == 0) {
$this->errors[] = sprintf(Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s), and therefore cannot be ' . ($validateOnly ? 'validated' : 'saved')), Db::getInstance()->getMsgError(), $customer->email, (int) $address->id_customer);
}
} else {
$this->errors[] = sprintf(Tools::displayError('The customer ID #%d does not exist in the database, and therefore cannot be ' . ($validateOnly ? 'validated' : 'saved')), $address->id_customer);
}
} else {
$customer_list = array();
$address->id_customer = 0;
}
if (isset($address->manufacturer) && is_numeric($address->manufacturer) && Manufacturer::manufacturerExists((int) $address->manufacturer)) {
//.........这里部分代码省略.........
示例2: addressImport
public function addressImport()
{
$this->receiveTab();
$defaultLanguageId = (int) Configuration::get('PS_LANG_DEFAULT');
$handle = $this->openCsvFile();
self::setLocale();
for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, Tools::getValue('separator')); $current_line++) {
if (Tools::getValue('convert')) {
$line = $this->utf8_encode_array($line);
}
$info = self::getMaskedRow($line);
self::setDefaultValues($info);
$address = new Address();
self::array_walk($info, array('AdminImport', 'fillInfo'), $address);
if (isset($address->country) and is_numeric($address->country)) {
if (Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), (int) $address->country)) {
$address->id_country = (int) $address->country;
}
} elseif (isset($address->country) and is_string($address->country) and !empty($address->country)) {
if ($id_country = Country::getIdByName(NULL, $address->country)) {
$address->id_country = (int) $id_country;
} else {
$country = new Country();
$country->active = 1;
$country->name = self::createMultiLangField($address->country);
$country->id_zone = 0;
// Default zone for country to create
$country->iso_code = strtoupper(substr($address->country, 0, 2));
// Default iso for country to create
$country->contains_states = 0;
// Default value for country to create
$langFieldError = $country->validateFieldsLang(UNFRIENDLY_ERROR, true);
if (($fieldError = $country->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $country->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $country->add()) {
$address->id_country = (int) $country->id;
} else {
$this->_errors[] = $country->name[$defaultLanguageId] . ' ' . Tools::displayError('Cannot be saved');
$this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
}
}
}
if (isset($address->state) and is_numeric($address->state)) {
if (State::getNameById((int) $address->state)) {
$address->id_state = (int) $address->state;
}
} elseif (isset($address->state) and is_string($address->state) and !empty($address->state)) {
if ($id_state = State::getIdByName($address->state)) {
$address->id_state = (int) $id_state;
} else {
$state = new State();
$state->active = 1;
$state->name = $address->state;
$state->id_country = isset($country->id) ? (int) $country->id : 0;
$state->id_zone = 0;
// Default zone for state to create
$state->iso_code = strtoupper(substr($address->state, 0, 2));
// Default iso for state to create
$state->tax_behavior = 0;
if (($fieldError = $state->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $state->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $state->add()) {
$address->id_state = (int) $state->id;
} else {
$this->_errors[] = $state->name . ' ' . Tools::displayError('Cannot be saved');
$this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
}
}
}
if (isset($address->customer_email) and !empty($address->customer_email)) {
if (Validate::isEmail($address->customer_email)) {
$customer = Customer::customerExists($address->customer_email, true);
if ($customer) {
$address->id_customer = (int) $customer;
} else {
$this->_errors[] = mysql_error() . ' ' . $address->customer_email . ' ' . Tools::displayError('does not exist in database') . ' ' . (isset($info['id']) ? ' (ID ' . $info['id'] . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
}
} else {
$this->_errors[] = '"' . $address->customer_email . '" :' . Tools::displayError('Is not a valid Email');
}
}
if (isset($address->manufacturer) and is_numeric($address->manufacturer) and Manufacturer::manufacturerExists((int) $address->manufacturer)) {
$address->id_manufacturer = (int) $address->manufacturer;
} elseif (isset($address->manufacturer) and is_string($address->manufacturer) and !empty($address->manufacturer)) {
$manufacturer = new Manufacturer();
$manufacturer->name = $address->manufacturer;
if (($fieldError = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $manufacturer->add()) {
$address->id_manufacturer = (int) $manufacturer->id;
} else {
$this->_errors[] = mysql_error() . ' ' . $manufacturer->name . (isset($manufacturer->id) ? ' (' . $manufacturer->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
$this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
}
}
if (isset($address->supplier) and is_numeric($address->supplier) and Supplier::supplierExists((int) $address->supplier)) {
$address->id_supplier = (int) $address->supplier;
} elseif (isset($address->supplier) and is_string($address->supplier) and !empty($address->supplier)) {
$supplier = new Supplier();
$supplier->name = $address->supplier;
if (($fieldError = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $supplier->add()) {
$address->id_supplier = (int) $supplier->id;
} else {
$this->_errors[] = mysql_error() . ' ' . $supplier->name . (isset($supplier->id) ? ' (' . $supplier->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
$this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
}
//.........这里部分代码省略.........
示例3: rtrim
}
$line = rtrim($line);
if (empty($line)) {
continue;
}
if ($line[0] != '\t') {
$id = strtolower(substr($line, 0, 4));
$name = addslashes(trim(substr($line, 4)));
if ($registeredid->getFromDBByQuery("WHERE `itemtype` = 'Manufacturer'
AND `name` = '$id'
AND `device_type` = '$type'")) {
$manufacturer->getFromDB($registeredid->fields['items_id']);
} else {
if (!$manufacturer->getFromDBByQuery("WHERE `name` = '$name'")) {
$input = array('name' => $name);
$manufacturer->add($input);
}
$input = array('itemtype' => $manufacturer->getType(),
'items_id' => $manufacturer->getID(),
'device_type' => $type,
'name' => $id);
$registeredid->add($input);
}
continue;
}
// if (($line[0] == "\t") && ($line[1] != '\t')) {
// $line = trim($line);
// $id = strtolower(substr($line, 0, 4));
// $name = addslashes(trim(substr($line, 4)));
// continue;
// }
示例4: generateGlobalDropdowns
/** Generate bigdump : generate global dropdowns
**/
function generateGlobalDropdowns() {
global $MAX, $DB;
$items = array("CD", "CD-RW", "DVD-R", "DVD+R", "DVD-RW", "DVD+RW", "ramette papier",
"disk'ette", "ZIP");
$dp = new ConsumableItemType();
for ($i=0 ; $i<$MAX['consumable_type'] ; $i++) {
if (isset($items[$i])) {
$val = $items[$i];
} else {
$val = "type d' consommable $i";
}
$dp->add(toolbox::addslashes_deep(array('name' => $val,
'comment' => "comment $val")));
}
$items = array("phone d'power");
$dp = new PhonePowerSupply();
for ($i=0 ; $i<$MAX['phone_power'] ; $i++) {
if (isset($items[$i])) {
$val = $items[$i];
} else {
$val = "power ' $i";
}
$dp->add(toolbox::addslashes_deep(array('name' => $val,
'comment' => "comment $val")));
}
$items = array("Grand", "Moyen", "Mic'ro", "1U", "5U");
$dp = new DeviceCaseType();
for ($i=0 ; $i<$MAX['case_type'] ; $i++) {
if (isset($items[$i])) {
$val = $items[$i];
} else {
$val = "power ' $i";
}
$dp->add(toolbox::addslashes_deep(array('name' => $val,
'comment' => "comment $val")));
}
$items = array("Laser", "Jet d'Encre", "Encre Solide");
$dp = new CartridgeItemType();
for ($i=0 ; $i<$MAX['cartridge_type'] ; $i++) {
if (isset($items[$i])) {
$val = $items[$i];
} else {
$val = "type d' cartouche $i";
}
$dp->add(toolbox::addslashes_deep(array('name' => $val,
'comment' => "comment $val")));
}
$items = array("Technicien", "Commercial", "Technico-Commercial", "President", "Secretaire",
"Directeur d'agence");
$dp = new ContactType();
for ($i=0 ; $i<$MAX['contact_type'] ; $i++) {
if (isset($items[$i])) {
$val = $items[$i];
} else {
$val = "type d' contact $i";
}
$dp->add(toolbox::addslashes_deep(array('name' => $val,
'comment' => "comment $val")));
}
$items = array("Maintenance", "Support", "Location", "Adhesion");
$dp = new ContractType();
for ($i=0 ; $i<$MAX['contract_type'] ; $i++) {
if (isset($items[$i])) {
$val = $items[$i];
} else {
$val = "type d' crontact $i";
}
$dp->add(toolbox::addslashes_deep(array('name' => $val,
'comment' => "comment $val")));
}
$items = array("Fournisseur", "Transporteur", "SSII", "Revendeur d'", "Assembleur", "SSLL",
"Financeur", "Assureur");
$dp = new SupplierType();
for ($i=0 ; $i<$MAX['enttype'] ; $i++) {
if (isset($items[$i])) {
$val = $items[$i];
} else {
$val = "type d'entreprise $i";
}
$dp->add(toolbox::addslashes_deep(array('name' => $val,
'comment' => "comment $val")));
}
$items = array("H.07.02", "I.07.56", "P51", "P52", "1.60", "4.06", "43-4071299", "1.0.14",
//.........这里部分代码省略.........
示例5: addressImport
public function addressImport()
{
$this->receiveTab();
$default_language_id = (int) Configuration::get('PS_LANG_DEFAULT');
$handle = $this->openCsvFile();
AdminImportController::setLocale();
for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) {
if (Tools::getValue('convert')) {
$line = $this->utf8EncodeArray($line);
}
$info = AdminImportController::getMaskedRow($line);
AdminImportController::setDefaultValues($info);
$address = new Address();
AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $address);
if (isset($address->country) && is_numeric($address->country)) {
if (Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), (int) $address->country)) {
$address->id_country = (int) $address->country;
}
} elseif (isset($address->country) && is_string($address->country) && !empty($address->country)) {
if ($id_country = Country::getIdByName(null, $address->country)) {
$address->id_country = (int) $id_country;
} else {
$country = new Country();
$country->active = 1;
$country->name = AdminImportController::createMultiLangField($address->country);
$country->id_zone = 0;
// Default zone for country to create
$country->iso_code = Tools::strtoupper(Tools::substr($address->country, 0, 2));
// Default iso for country to create
$country->contains_states = 0;
// Default value for country to create
$lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true);
if (($field_error = $country->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $country->add()) {
$address->id_country = (int) $country->id;
} else {
$this->errors[] = sprintf(Tools::displayError('%s cannot be saved'), $country->name[$default_language_id]);
$this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
}
}
}
if (isset($address->state) && is_numeric($address->state)) {
if (State::getNameById((int) $address->state)) {
$address->id_state = (int) $address->state;
}
} elseif (isset($address->state) && is_string($address->state) && !empty($address->state)) {
if ($id_state = State::getIdByName($address->state)) {
$address->id_state = (int) $id_state;
} else {
$state = new State();
$state->active = 1;
$state->name = $address->state;
$state->id_country = isset($country->id) ? (int) $country->id : 0;
$state->id_zone = 0;
// Default zone for state to create
$state->iso_code = Tools::strtoupper(Tools::substr($address->state, 0, 2));
// Default iso for state to create
$state->tax_behavior = 0;
if (($field_error = $state->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $state->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $state->add()) {
$address->id_state = (int) $state->id;
} else {
$this->errors[] = sprintf(Tools::displayError('%s cannot be saved'), $state->name);
$this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
}
}
}
if (isset($address->customer_email) && !empty($address->customer_email)) {
if (Validate::isEmail($address->customer_email)) {
// a customer could exists in different shop
$customer_list = Customer::getCustomersByEmail($address->customer_email);
if (count($customer_list) == 0) {
$this->errors[] = sprintf(Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s), and therefore cannot be saved.'), Db::getInstance()->getMsgError(), $address->customer_email, isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null');
}
} else {
$this->errors[] = sprintf(Tools::displayError('"%s" is not a valid email address.'), $address->customer_email);
continue;
}
} elseif (isset($address->id_customer) && !empty($address->id_customer)) {
if (Customer::customerIdExistsStatic((int) $address->id_customer)) {
$customer = new Customer((int) $address->id_customer);
// a customer could exists in different shop
$customer_list = Customer::getCustomersByEmail($customer->email);
if (count($customer_list) == 0) {
$this->errors[] = sprintf(Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s), and therefore cannot be saved.'), Db::getInstance()->getMsgError(), $customer->email, (int) $address->id_customer);
}
} else {
$this->errors[] = sprintf(Tools::displayError('The customer ID #%d does not exist in the database, and therefore cannot be saved.'), $address->id_customer);
}
} else {
$customer_list = array();
$address->id_customer = 0;
}
if (isset($address->manufacturer) && is_numeric($address->manufacturer) && Manufacturer::manufacturerExists((int) $address->manufacturer)) {
$address->id_manufacturer = (int) $address->manufacturer;
} elseif (isset($address->manufacturer) && is_string($address->manufacturer) && !empty($address->manufacturer)) {
$manufacturer = new Manufacturer();
$manufacturer->name = $address->manufacturer;
if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $manufacturer->add()) {
$address->id_manufacturer = (int) $manufacturer->id;
} else {
$this->errors[] = Db::getInstance()->getMsgError() . ' ' . sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $manufacturer->name, isset($manufacturer->id) && !empty($manufacturer->id) ? $manufacturer->id : 'null');
//.........这里部分代码省略.........
示例6: productImport
public function productImport()
{
$this->receiveTab();
$handle = $this->openCsvFile();
$default_language_id = (int) Configuration::get('PS_LANG_DEFAULT');
$id_lang = Language::getIdByIso(Tools::getValue('iso_lang'));
if (!Validate::isUnsignedId($id_lang)) {
$id_lang = $default_language_id;
}
AdminImportController::setLocale();
$shop_ids = Shop::getCompleteListOfShopsID();
for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) {
if (Tools::getValue('convert')) {
$line = $this->utf8EncodeArray($line);
}
$info = AdminImportController::getMaskedRow($line);
if (self::ignoreRow($info)) {
continue;
}
if (Tools::getValue('forceIDs') && isset($info['id']) && (int) $info['id']) {
$product = new Product((int) $info['id']);
} elseif (Tools::getValue('match_ref') && array_key_exists('reference', $info)) {
$datas = Db::getInstance()->getRow('
SELECT p.`id_product`
FROM `' . _DB_PREFIX_ . 'product` p
' . Shop::addSqlAssociation('product', 'p') . '
WHERE p.`reference` = "' . pSQL($info['reference']) . '"
');
if (isset($datas['id_product']) && $datas['id_product']) {
$product = new Product((int) $datas['id_product']);
} else {
$product = new Product();
}
} else {
if (array_key_exists('id', $info) && is_string($info['id'])) {
$prod = self::findProductByName($default_language_id, $info['id'], $info['name']);
if ($prod['id_product']) {
$info['id'] = (int) $prod['id_product'];
}
}
if (array_key_exists('id', $info) && (int) $info['id'] && Product::existsInDatabase((int) $info['id'], 'product')) {
$product = new Product((int) $info['id']);
$product->loadStockData();
$category_data = Product::getProductCategories((int) $product->id);
if (is_array($category_data)) {
foreach ($category_data as $tmp) {
if (!isset($product->category) || !$product->category || is_array($product->category)) {
$product->category[] = $tmp;
}
}
}
} else {
$product = new Product();
}
}
AdminImportController::setEntityDefaultValues($product);
AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $product);
if (!Shop::isFeatureActive()) {
$product->shop = 1;
} elseif (!isset($product->shop) || empty($product->shop)) {
$product->shop = implode($this->multiple_value_separator, Shop::getContextListShopID());
}
if (!Shop::isFeatureActive()) {
$product->id_shop_default = 1;
} else {
$product->id_shop_default = (int) Context::getContext()->shop->id;
}
// link product to shops
$product->id_shop_list = array();
foreach (explode($this->multiple_value_separator, $product->shop) as $shop) {
if (!empty($shop) && !is_numeric($shop)) {
$product->id_shop_list[] = Shop::getIdByName($shop);
} elseif (!empty($shop)) {
$product->id_shop_list[] = $shop;
}
}
if ((int) $product->id_tax_rules_group != 0) {
if (Validate::isLoadedObject(new TaxRulesGroup($product->id_tax_rules_group))) {
$address = $this->context->shop->getAddress();
$tax_manager = TaxManagerFactory::getManager($address, $product->id_tax_rules_group);
$product_tax_calculator = $tax_manager->getTaxCalculator();
$product->tax_rate = $product_tax_calculator->getTotalRate();
} else {
$this->addProductWarning('id_tax_rules_group', $product->id_tax_rules_group, Tools::displayError('Invalid tax rule group ID. You first need to create a group with this ID.'));
}
}
if (isset($product->manufacturer) && is_numeric($product->manufacturer) && Manufacturer::manufacturerExists((int) $product->manufacturer)) {
$product->id_manufacturer = (int) $product->manufacturer;
} elseif (isset($product->manufacturer) && is_string($product->manufacturer) && !empty($product->manufacturer)) {
if ($manufacturer = Manufacturer::getIdByName($product->manufacturer)) {
$product->id_manufacturer = (int) $manufacturer;
} else {
$manufacturer = new Manufacturer();
$manufacturer->name = $product->manufacturer;
if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $manufacturer->add()) {
$product->id_manufacturer = (int) $manufacturer->id;
} else {
$this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $manufacturer->name, isset($manufacturer->id) && !empty($manufacturer->id) ? $manufacturer->id : 'null');
$this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
}
//.........这里部分代码省略.........
示例7: import_parts
/**
* @brief Import Parts (create Parts, and if neccessary, Categories, Footprints and so on)
*
* @note This function uses database transactions. If an error occurs, all changes will be rolled back.
*
* @param Database &$database reference to the database object
* @param User &$current_user reference to the user which is logged in
* @param Log &$log reference to the Log-object
* @param array $data The import data array from "extract_import_data_from_request()"
* @param boolean $only_check_data If true, this function will only check if all values in "$data" are valid.
* In this case, no parts will be imported!
*
* @retval array All new Part objects (only if "$only_check_data == false")
*
* @throws Exception if there was an error (maybe the passed data is not valid)
*/
function import_parts(&$database, &$current_user, &$log, $data, $only_check_data = false)
{
$parts = array();
try {
$transaction_id = $database->begin_transaction();
// start transaction
// Get the category, footprint, storelocation, ... which are named "Import", or create them.
// We need this elements as parent for new elements, which will be created while import parts.
$import_categories = Category::search($database, $current_user, $log, 'Import', true);
if (count($import_categories) > 0) {
$import_category = $import_categories[0];
$import_category_created = false;
} else {
$import_category = Category::add($database, $current_user, $log, 'Import', NULL);
$import_category_created = true;
// we can delete it later if we didn't need it
}
$import_storelocations = Storelocation::search($database, $current_user, $log, 'Import', true);
if (count($import_storelocations) > 0) {
$import_storelocation = $import_storelocations[0];
$import_storelocation_created = false;
} else {
$import_storelocation = Storelocation::add($database, $current_user, $log, 'Import', NULL);
$import_storelocation_created = true;
// we can delete it later if we didn't need it
}
$import_footprints = Footprint::search($database, $current_user, $log, 'Import', true);
if (count($import_footprints) > 0) {
$import_footprint = $import_footprints[0];
$import_footprint_created = false;
} else {
$import_footprint = Footprint::add($database, $current_user, $log, 'Import', NULL);
$import_footprint_created = true;
// we can delete it later if we didn't need it
}
$import_suppliers = Supplier::search($database, $current_user, $log, 'Import', true);
if (count($import_suppliers) > 0) {
$import_supplier = $import_suppliers[0];
$import_supplier_created = false;
} else {
$import_supplier = Supplier::add($database, $current_user, $log, 'Import', NULL);
$import_supplier_created = true;
// we can delete it later if we didn't need it
}
$import_manufacturers = Manufacturer::search($database, $current_user, $log, 'Import', true);
if (count($import_manufacturers) > 0) {
$import_manufacturer = $import_manufacturers[0];
$import_manufacturer_created = false;
} else {
$import_manufacturer = Manufacturer::add($database, $current_user, $log, 'Import', NULL);
$import_manufacturer_created = true;
// we can delete it later if we didn't need it
}
$import_category_used = false;
$import_storelocation_used = false;
$import_footprint_used = false;
$import_supplier_used = false;
$import_manufacturer_used = false;
// start import
$row_index = 0;
foreach ($data as $row) {
$name = $row['part_name'];
$description = $row['part_description'];
$instock = $row['part_instock'];
$mininstock = $row['part_mininstock'];
$comment = $row['part_comment'];
$category_name = $row['part_category_name'];
$footprint_name = $row['part_footprint_name'];
$storelocation_name = $row['part_storelocation_name'];
$manufacturer_name = $row['part_manufacturer_name'];
$supplier_name = $row['part_supplier_name'];
$supplierpartnr = $row['part_supplierpartnr'];
$price = $row['part_price'];
// search elements / create them if they don't exist already
if (strlen($category_name) > 0) {
$categories = Category::search($database, $current_user, $log, $category_name, true);
if (count($categories) > 0) {
$category = $categories[0];
} else {
$category = Category::add($database, $current_user, $log, $category_name, $import_category->get_id());
$import_category_used = true;
}
} else {
throw new Exception('Jedes Bauteil muss eine Kategorie haben!');
//.........这里部分代码省略.........
示例8: catch
$selected_manufacturer = NULL;
}
} catch (Exception $e) {
$messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
$fatal_error = true;
}
/********************************************************************************
*
* Execute actions
*
*********************************************************************************/
if (!$fatal_error) {
switch ($action) {
case 'add':
try {
$new_manufacturer = Manufacturer::add($database, $current_user, $log, $new_name, $new_parent_id, $new_address, $new_phone_number, $new_fax_number, $new_email_address, $new_website, $new_auto_product_url);
if (!$add_more) {
$selected_manufacturer = $new_manufacturer;
$selected_id = $selected_manufacturer->get_id();
}
} catch (Exception $e) {
$messages[] = array('text' => 'Der neue Hersteller konnte nicht angelegt werden!', 'strong' => true, 'color' => 'red');
$messages[] = array('text' => 'Fehlermeldung: ' . nl2br($e->getMessage()), 'color' => 'red');
}
break;
case 'delete':
try {
if (!is_object($selected_manufacturer)) {
throw new Exception('Es ist kein Hersteller markiert oder es trat ein Fehler auf!');
}
$parts = $selected_manufacturer->get_parts();
示例9: importManufacturers
protected function importManufacturers()
{
$this->truncateTables(array('manufacturer', 'manufacturer_lang', 'manufacturer_shop'));
$handle = $this->openCsvFile('manufacturers.csv');
for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, ';'); $current_line++) {
$res = false;
$fields = $this->filterFields('Manufacturer', $this->manufacturers_fields, $line);
if (!isset($fields['id'])) {
$manufacturer = new Manufacturer($line[0]);
$manufacturer->id = $line[0];
} else {
$manufacturer = new Manufacturer($fields['id']);
}
foreach ($fields as $key => $field) {
if ($key == 'description' || $key == 'short_description' || $key == 'meta_title' || $key == 'meta_keywords' || $key == 'meta_description') {
$manufacturer->{$key} = $this->multilFild($field);
} else {
$manufacturer->{$key} = $field;
}
}
$manufacturer->force_id = true;
if (!$res) {
$res = $manufacturer->add();
}
}
$this->closeCsvFile($handle);
return true;
}