From 9333fd1034e0c6b282b1bbda0de023f14b6ddced Mon Sep 17 00:00:00 2001 From: vChabot Date: Mon, 26 Sep 2011 13:50:53 +0000 Subject: [PATCH] // import OK for product feature --- admin-dev/tabs/AdminImport.php | 23 ++++++++++++++--------- classes/Feature.php | 8 ++++++-- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/admin-dev/tabs/AdminImport.php b/admin-dev/tabs/AdminImport.php index a5237a28d..f311ad6b6 100644 --- a/admin-dev/tabs/AdminImport.php +++ b/admin-dev/tabs/AdminImport.php @@ -179,7 +179,7 @@ class AdminImport extends AdminTab 'label' => $this->l('Delete existing images (0 = no, 1 = yes)'), 'help' => $this->l('If you do not specify this column and you specify the column images, all images of the product will be replaced by those specified in the import file') ), - 'feature' => array('label' => $this->l('Feature(Name:Position)'), + 'features' => array('label' => $this->l('Feature(Name:Position)'), 'help' => $this->l('Position of the feature.')), 'online_only' => array('label' => $this->l('Only available online')), 'condition' => array('label' => $this->l('Condition')), @@ -894,15 +894,20 @@ class AdminImport extends AdminTab if (isset($product->id_category)) $product->updateCategories(array_map('intval', $product->id_category)); + // Features import $features = get_object_vars($product); - foreach ($features AS $feature => $value) - if (!strncmp($feature, '#F_', 3) AND Tools::strlen($product->{$feature})) - { - $feature_name = str_replace('#F_', '', $feature); - $id_feature = Feature::addFeatureImport($feature_name); - $id_feature_value = FeatureValue::addFeatureValueImport($id_feature, $product->{$feature}); - Product::addFeatureProductImport($product->id, $id_feature, $id_feature_value); - } + foreach (explode(',', $features['features']) as $single_feature) + { + $tab_feature = explode(':', $single_feature); + $feature_name = $tab_feature[0]; + $feature_value = $tab_feature[1]; + $position = isset($tab_feature[2]) ? $tab_feature[1]: false; + $id_feature = Feature::addFeatureImport($feature_name, $position); + $id_feature_value = FeatureValue::addFeatureValueImport($id_feature, $feature_value); + Product::addFeatureProductImport($product->id, $id_feature, $id_feature_value); + } + // clean feature positions to avoid conflict + Feature::cleanPositions(); } } $this->closeCsvFile($handle); diff --git a/classes/Feature.php b/classes/Feature.php index cb3ae2d38..b9922d738 100644 --- a/classes/Feature.php +++ b/classes/Feature.php @@ -33,7 +33,7 @@ class FeatureCore extends ObjectModel protected $fieldsRequiredLang = array('name'); protected $fieldsSizeLang = array('name' => 128); - protected $fieldsValidateLang = array('name' => 'isGenericName'); + protected $fieldsValidateLang = array('name' => 'isGenericName', 'position' => 'isInt'); protected $table = 'feature'; protected $identifier = 'id_feature'; @@ -183,7 +183,7 @@ class FeatureCore extends ObjectModel * @param integer $id_product Product id * @param array $value Feature Value */ - public static function addFeatureImport($name) + public static function addFeatureImport($name, $position = false) { $rq = Db::getInstance()->getRow('SELECT `id_feature` FROM '._DB_PREFIX_.'feature_lang WHERE `name` = \''.pSQL($name).'\' GROUP BY `id_feature`'); if (!empty($rq)) @@ -193,6 +193,10 @@ class FeatureCore extends ObjectModel $languages = Language::getLanguages(); foreach ($languages as $language) $feature->name[$language['id_lang']] = strval($name); + if ($position) + $feature->position = (int)$position; + else + $feature->position = self::getHigherPosition() + 1; $feature->add(); return $feature->id; }