From 5d28d38a2250f497a78b4c6b7b855578aab4d7be Mon Sep 17 00:00:00 2001 From: gRoussac Date: Wed, 23 Oct 2013 01:18:09 +0200 Subject: [PATCH] [-] BO : Fix bug #PSCFV-7907 AdminImport, add custom field to features --- classes/FeatureValue.php | 24 ++++++++++++--------- controllers/admin/AdminImportController.php | 15 ++++++------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/classes/FeatureValue.php b/classes/FeatureValue.php index 25c0fb4fd..b43abfb58 100644 --- a/classes/FeatureValue.php +++ b/classes/FeatureValue.php @@ -128,32 +128,36 @@ class FeatureValueCore extends ObjectModel return $tab['value']; } - public static function addFeatureValueImport($id_feature, $value, $id_product = null, $id_lang = null) + public static function addFeatureValueImport($id_feature, $value, $id_product, $id_lang = null, $custom = false) { $id_feature_value = false; if (!is_null($id_product) && $id_product) { $id_feature_value = Db::getInstance()->getValue(' - SELECT `id_feature_value` - FROM '._DB_PREFIX_.'feature_product - WHERE `id_feature` = '.(int)$id_feature.' - AND `id_product` = '.(int)$id_product); + SELECT fp.`id_feature_value` + FROM '._DB_PREFIX_.'feature_product fp + INNER JOIN '._DB_PREFIX_.'feature_value fv USING (`id_feature_value`) + WHERE fp.`id_feature` = '.(int)$id_feature.' + AND fv.`custom` = '.(int)$custom.' + AND fp.`id_product` = '.(int)$id_product); - if ($id_feature_value && !is_null($id_lang) && $id_lang) + if ($custom && $id_feature_value && !is_null($id_lang) && $id_lang) Db::getInstance()->execute(' UPDATE '._DB_PREFIX_.'feature_value_lang SET `value` = \''.pSQL($value).'\' WHERE `id_feature_value` = '.(int)$id_feature_value.' + AND `value` != \''.pSQL($value).'\' AND `id_lang` = '.(int)$id_lang); } - - if (!$id_feature_value) + + if (!$custom) $id_feature_value = Db::getInstance()->getValue(' SELECT fv.`id_feature_value` FROM '._DB_PREFIX_.'feature_value fv - LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.`id_feature_value` = fv.`id_feature_value`) + LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.`id_feature_value` = fv.`id_feature_value` AND fvl.`id_lang` = '.(int)$id_lang.') WHERE `value` = \''.pSQL($value).'\' AND fv.`id_feature` = '.(int)$id_feature.' + AND fv.`custom` = 0 GROUP BY fv.`id_feature_value`'); if ($id_feature_value) @@ -162,7 +166,7 @@ class FeatureValueCore extends ObjectModel // Feature doesn't exist, create it $feature_value = new FeatureValue(); $feature_value->id_feature = (int)$id_feature; - $feature_value->custom = 0; + $feature_value->custom = (bool)$custom; foreach (Language::getLanguages() as $language) $feature_value->value[$language['id_lang']] = $value; $feature_value->add(); diff --git a/controllers/admin/AdminImportController.php b/controllers/admin/AdminImportController.php index 8ae22ff07..e80ce48c0 100644 --- a/controllers/admin/AdminImportController.php +++ b/controllers/admin/AdminImportController.php @@ -247,7 +247,7 @@ class AdminImportControllerCore extends AdminController 'delete_existing_images' => array( 'label' => $this->l('Delete existing images (0 = No, 1 = Yes)') ), - 'features' => array('label' => $this->l('Feature(Name:Value:Position)')), + 'features' => array('label' => $this->l('Feature(Name:Value:Position:Customized)')), 'online_only' => array('label' => $this->l('Available online only (0 = No, 1 = Yes)')), 'condition' => array('label' => $this->l('Condition')), 'customizable' => array('label' => $this->l('Customizable (0 = No, 1 = Yes)')), @@ -472,9 +472,8 @@ class AdminImportControllerCore extends AdminController } - $this->separator = Tools::substr(strval(trim(Tools::getValue('separator', ','))), 0, 1); - $this->multiple_value_separator = Tools::substr(strval(trim(Tools::getValue('multiple_value_separator', ';'))), 0, 1); - + $this->separator = ($separator = Tools::substr(strval(trim(Tools::getValue('separator'))), 0, 1)) ? $separator : ';'; + $this->multiple_value_separator = ($separator = Tools::substr(strval(trim(Tools::getValue('multiple_value_separator'))), 0, 1)) ? $separator : ','; parent::__construct(); } @@ -569,8 +568,8 @@ class AdminImportControllerCore extends AdminController $this->context->cookie->entity_selected = (int)Tools::getValue('entity'); $this->context->cookie->iso_lang_selected = base64_encode(Tools::getValue('iso_lang')); - $this->context->cookie->separator_selected = base64_encode(Tools::getValue('separator')); - $this->context->cookie->multiple_value_separator_selected = base64_encode(Tools::getValue('multiple_value_separator')); + $this->context->cookie->separator_selected = base64_encode($this->separator); + $this->context->cookie->multiple_value_separator_selected = base64_encode($this->multiple_value_separator); $this->context->cookie->csv_selected = base64_encode(Tools::getValue('csv')); $this->tpl_view_vars = array( @@ -1602,13 +1601,14 @@ class AdminImportControllerCore extends AdminController $feature_name = isset($tab_feature[0]) ? trim($tab_feature[0]) : ''; $feature_value = isset($tab_feature[1]) ? trim($tab_feature[1]) : ''; $position = isset($tab_feature[2]) ? (int)$tab_feature[2] : false; + $custom = isset($tab_feature[3]) ? (int)$tab_feature[3] : false; if(!empty($feature_name) && !empty($feature_value)) { $id_feature = (int)Feature::addFeatureImport($feature_name, $position); $id_product = null; if (Tools::getValue('forceIDs') || Tools::getValue('match_ref')) $id_product = (int)$product->id; - $id_feature_value = (int)FeatureValue::addFeatureValueImport($id_feature, $feature_value, $id_product, $id_lang); + $id_feature_value = (int)FeatureValue::addFeatureValueImport($id_feature, $feature_value, $id_product, $id_lang, $custom); Product::addFeatureProductImport($product->id, $id_feature, $id_feature_value); } } @@ -1626,7 +1626,6 @@ class AdminImportControllerCore extends AdminController StockAvailable::setQuantity((int)$product->id, 0, $product->quantity, $this->context->shop->id); } - $this->closeCsvFile($handle); }