在Prestashop中通过PHP更新产品功能
作者:互联网
我想在自己的课堂上更改自定义功能(产品功能)(Artikeleigenschaften)的值.
更改产品值非常简单:
$productObj = new Product($produktId);
$productObj->setFieldsToUpdate(array('ean13'));
$productObj->ean13 = "johndoo";
$productObj->save();
但是,是否有类似的方法可以更改产品功能?
解决方法:
这是我的解决方案:
要更新产品功能,您必须更新数据库中的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
);
要使用非自定义值更新功能,请使用:
$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 );
标签:prestashop,product,php 来源: https://codeday.me/bug/20191028/1952341.html