protected function manufacturerImportOne($info, $shop_is_feature_active, $regenerate, $force_ids, $validateOnly = false) { AdminImportController::setDefaultValues($info); if ($force_ids && isset($info['id']) && (int) $info['id']) { $manufacturer = new Manufacturer((int) $info['id']); } else { if (array_key_exists('id', $info) && (int) $info['id'] && Manufacturer::existsInDatabase((int) $info['id'], 'manufacturer')) { $manufacturer = new Manufacturer((int) $info['id']); } else { $manufacturer = new Manufacturer(); } } AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $manufacturer); $res = false; if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) { if ($manufacturer->id && $manufacturer->manufacturerExists($manufacturer->id)) { $res = $validateOnly || $manufacturer->update(); } $manufacturer->force_id = (bool) $force_ids; if (!$res) { $res = $validateOnly || $manufacturer->add(); } //copying images of manufacturer if (!$validateOnly && isset($manufacturer->image) && !empty($manufacturer->image)) { if (!AdminImportController::copyImg($manufacturer->id, null, $manufacturer->image, 'manufacturers', !$regenerate)) { $this->warnings[] = $manufacturer->image . ' ' . $this->trans('cannot be copied.', array(), 'Admin.Parameters.Notification'); } } if (!$validateOnly && $res) { // Associate supplier to group shop if ($shop_is_feature_active && $manufacturer->shop) { Db::getInstance()->execute(' DELETE FROM ' . _DB_PREFIX_ . 'manufacturer_shop WHERE id_manufacturer = ' . (int) $manufacturer->id); $manufacturer->shop = explode($this->multiple_value_separator, $manufacturer->shop); $shops = array(); foreach ($manufacturer->shop as $shop) { if (empty($shop)) { continue; } $shop = trim($shop); if (!is_numeric($shop)) { $shop = ShopGroup::getIdByName($shop); } $shops[] = $shop; } $manufacturer->associateTo($shops); } } } if (!$res) { if (!$validateOnly) { $this->errors[] = Db::getInstance()->getMsgError() . ' ' . sprintf($this->trans('%1$s (ID: %2$s) cannot be saved', array(), 'Admin.Parameters.Notification'), isset($info['name']) && !empty($info['name']) ? Tools::safeOutput($info['name']) : 'No Name', isset($info['id']) && !empty($info['id']) ? Tools::safeOutput($info['id']) : 'No 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(); } } }
public function manufacturerImport() { $this->receiveTab(); $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); if (array_key_exists('id', $info) && (int) $info['id'] && Manufacturer::existsInDatabase((int) $info['id'], 'manufacturer')) { $manufacturer = new Manufacturer((int) $info['id']); } else { $manufacturer = new Manufacturer(); } self::array_walk($info, array('AdminImport', 'fillInfo'), $manufacturer); $res = false; if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) { if ($manufacturer->id && $manufacturer->manufacturerExists($manufacturer->id)) { $res = $manufacturer->update(); } if (!$res) { $res = $manufacturer->add(); } } if (!$res) { $this->_errors[] = mysql_error() . ' ' . $info['name'] . (isset($info['id']) ? ' (ID ' . $info['id'] . ')' : '') . ' ' . Tools::displayError('Cannot be saved'); $this->_errors[] = ($field_error !== true ? $field_error : '') . ($lang_field_error !== true ? $lang_field_error : '') . mysql_error(); } } $this->closeCsvFile($handle); }
public function manufacturerImport() { $this->receiveTab(); $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); if (Tools::getValue('forceIDs') && isset($info['id']) && (int) $info['id']) { $manufacturer = new Manufacturer((int) $info['id']); } else { if (array_key_exists('id', $info) && (int) $info['id'] && Manufacturer::existsInDatabase((int) $info['id'], 'manufacturer')) { $manufacturer = new Manufacturer((int) $info['id']); } else { $manufacturer = new Manufacturer(); } } AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $manufacturer); $res = false; if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) { if ($manufacturer->id && $manufacturer->manufacturerExists($manufacturer->id)) { $res = $manufacturer->update(); } $manufacturer->force_id = (bool) Tools::getValue('forceIDs'); if (!$res) { $res = $manufacturer->add(); } //copying images of manufacturer if (isset($manufacturer->image) && !empty($manufacturer->image)) { if (!AdminImportController::copyImg($manufacturer->id, null, $manufacturer->image, 'manufacturers', !Tools::getValue('regenerate'))) { $this->warnings[] = $manufacturer->image . ' ' . Tools::displayError('cannot be copied.'); } } if ($res) { // Associate supplier to group shop if (Shop::isFeatureActive() && $manufacturer->shop) { Db::getInstance()->execute(' DELETE FROM ' . _DB_PREFIX_ . 'manufacturer_shop WHERE id_manufacturer = ' . (int) $manufacturer->id); $manufacturer->shop = explode($this->multiple_value_separator, $manufacturer->shop); $shops = array(); foreach ($manufacturer->shop as $shop) { if (empty($shop)) { continue; } $shop = trim($shop); if (!is_numeric($shop)) { $shop = ShopGroup::getIdByName($shop); } $shops[] = $shop; } $manufacturer->associateTo($shops); } } } if (!$res) { $this->errors[] = Db::getInstance()->getMsgError() . ' ' . sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), isset($info['name']) && !empty($info['name']) ? Tools::safeOutput($info['name']) : 'No Name', isset($info['id']) && !empty($info['id']) ? Tools::safeOutput($info['id']) : 'No ID'); $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } } $this->closeCsvFile($handle); }