// import OK for product feature
This commit is contained in:
1 parent
a2fe45d687
commit
9333fd1034
2 files changed
+20
-11
No files matched your search
@@ -179,7 +179,7 @@ class AdminImport extends AdminTab
|
|||||||
'label' => $this->l('Delete existing images (0 = no, 1 = yes)'),
|
'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')
|
'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.')),
|
'help' => $this->l('Position of the feature.')),
|
||||||
'online_only' => array('label' => $this->l('Only available online')),
|
'online_only' => array('label' => $this->l('Only available online')),
|
||||||
'condition' => array('label' => $this->l('Condition')),
|
'condition' => array('label' => $this->l('Condition')),
|
||||||
@@ -894,15 +894,20 @@ class AdminImport extends AdminTab
|
|||||||
if (isset($product->id_category))
|
if (isset($product->id_category))
|
||||||
$product->updateCategories(array_map('intval', $product->id_category));
|
$product->updateCategories(array_map('intval', $product->id_category));
|
||||||
|
|
||||||
|
// Features import
|
||||||
$features = get_object_vars($product);
|
$features = get_object_vars($product);
|
||||||
foreach ($features AS $feature => $value)
|
foreach (explode(',', $features['features']) as $single_feature)
|
||||||
if (!strncmp($feature, '#F_', 3) AND Tools::strlen($product->{$feature}))
|
{
|
||||||
{
|
$tab_feature = explode(':', $single_feature);
|
||||||
$feature_name = str_replace('#F_', '', $feature);
|
$feature_name = $tab_feature[0];
|
||||||
$id_feature = Feature::addFeatureImport($feature_name);
|
$feature_value = $tab_feature[1];
|
||||||
$id_feature_value = FeatureValue::addFeatureValueImport($id_feature, $product->{$feature});
|
$position = isset($tab_feature[2]) ? $tab_feature[1]: false;
|
||||||
Product::addFeatureProductImport($product->id, $id_feature, $id_feature_value);
|
$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);
|
$this->closeCsvFile($handle);
|
||||||
|
|||||||
+6
-2
@@ -33,7 +33,7 @@ class FeatureCore extends ObjectModel
|
|||||||
|
|
||||||
protected $fieldsRequiredLang = array('name');
|
protected $fieldsRequiredLang = array('name');
|
||||||
protected $fieldsSizeLang = array('name' => 128);
|
protected $fieldsSizeLang = array('name' => 128);
|
||||||
protected $fieldsValidateLang = array('name' => 'isGenericName');
|
protected $fieldsValidateLang = array('name' => 'isGenericName', 'position' => 'isInt');
|
||||||
|
|
||||||
protected $table = 'feature';
|
protected $table = 'feature';
|
||||||
protected $identifier = 'id_feature';
|
protected $identifier = 'id_feature';
|
||||||
@@ -183,7 +183,7 @@ class FeatureCore extends ObjectModel
|
|||||||
* @param integer $id_product Product id
|
* @param integer $id_product Product id
|
||||||
* @param array $value Feature Value
|
* @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`');
|
$rq = Db::getInstance()->getRow('SELECT `id_feature` FROM '._DB_PREFIX_.'feature_lang WHERE `name` = \''.pSQL($name).'\' GROUP BY `id_feature`');
|
||||||
if (!empty($rq))
|
if (!empty($rq))
|
||||||
@@ -193,6 +193,10 @@ class FeatureCore extends ObjectModel
|
|||||||
$languages = Language::getLanguages();
|
$languages = Language::getLanguages();
|
||||||
foreach ($languages as $language)
|
foreach ($languages as $language)
|
||||||
$feature->name[$language['id_lang']] = strval($name);
|
$feature->name[$language['id_lang']] = strval($name);
|
||||||
|
if ($position)
|
||||||
|
$feature->position = (int)$position;
|
||||||
|
else
|
||||||
|
$feature->position = self::getHigherPosition() + 1;
|
||||||
$feature->add();
|
$feature->add();
|
||||||
return $feature->id;
|
return $feature->id;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user