我想在我自己的班级中更改自定义功能(产品功能)(Artikeleigenschaften)的值。
更改产品价值非常简单:
$productObj = new Product($produktId);
$productObj->setFieldsToUpdate(array('ean13'));
$productObj->ean13 = "johndoo";
$productObj->save();
但有没有类似的方法来更改产品功能?
答案 0 :(得分:2)
这是我的解决方案: 要更新产品功能,您必须更新数据库中的2个表: ps_feature_value 和 ps_feature_value_lang
这样做:
$id_feature_value = (int)FeatureValue::addFeatureValueImport
(
(int)$feature['id_feature'],
$newFeatureValue,
(int)$produktId,
$this->context->language->id,
1 // $custom
);
Product::addFeatureProductImport(
$produktId, (int)$feature['id_feature'], $id_feature_value
);
使用NOT自定义值更新功能使用:
$arr = FeatureValue::getFeatureValueLang($id_dropdown);
foreach ( $arr AS $item)
if ($item['id_lang'] == $this->context->language->id)
{
$feature_val_name = $item['value'] ;
}
$id_feature_value = (int)FeatureValue::addFeatureValueImport
(
(int)$feature['id_feature'],
$feature_val_name,
$product->id,
$this->context->language->id,
false
);
$product->addFeatureProductImport( $product->id , (int)$feature['id_feature'], $id_feature_value );
答案 1 :(得分:1)
Product::addFeatureProductImport($productObjc->id, $id_feature, $id_feature_value);
答案 2 :(得分:1)
我基于ImportControlloer创建了此功能。将此功能添加到Product.php覆盖并使用
/**
* Adds a feature value to a Product. If You want to have feature selected from dropdown leave $custom to false.
* @param int|$id_product
* @param int|$id_feature_group
* @param string|$feature_value
* @param bool|true $custom
* @param int|$id_lang
* @return bool
*/
public static function setFeatureValueToProduct($id_product, $id_feature_group, $feature_value, $custom = false, $id_lang)
{
$group_feature_obj = Feature::getFeature($id_lang, $id_feature_group);
if ($group_feature_obj){
$feature_name = $group_feature_obj['name'];
$feature_value = $feature_value ? trim($feature_value) : '';
$position = false;
if (!empty($feature_name) && !empty($feature_value)) {
$id_feature = (int)FeatureCore::addFeatureImport($feature_name, $position);
$id_feature_value = (int)FeatureValue::addFeatureValueImport($id_feature, $feature_value, $id_product, $id_lang, $custom);
if (Product::addFeatureProductImport($id_product, $id_feature, $id_feature_value)){
Feature::cleanPositions();
return true;
} else {
return;
}
}
} else {
return;
}
}
使用示例:
Product::setFeatureValue(1597, 15, 'Dracarys', false, 1);
它将下拉列表值“ Dracarys”上载到ID为1597的产品中,并将组特征上载为ID 15的产品。如果要使其为自定义值(未预定义),只需将第4个参数设置为true。
答案 3 :(得分:0)
Product::addFeatureProductImport($productObjc->id, $id_feature, $id_feature_value);
这会将功能及其值分配给产品。但是我们需要特征和值的ID。以下代码对我有用。
$feature = new Feature();
$feature->name = [
$lang_id => "string"
];
$feature->position = Feature::getHigherPosition() + 1;
$feature->add();
$featurevalue = new FeatureValue;
$featurevalue->id_feature = $feature->id;
$featurevalue->value = [
$lang_id => "string"
];
$featurevalue->add();
$product->addFeatureProductImport($product->id, $feature->id, $featurevalue->id);