I would like to change the value from custom features (Product Features) (Artikeleigenschaften) in my own class.
To change product values is very simple:
$productObj = new Product($produktId);
$productObj->setFieldsToUpdate(array('ean13'));
$productObj->ean13 = "johndoo";
$productObj->save();
But is there a similar way to change the Product Features?
Here my solution: To Update Product Features you have to update 2 tables in your Database: ps_feature_value and ps_feature_value_lang
Do this with:
$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
);
To Update Features with NOT custom Values use:
$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 );
Mh, Ive never tried to do this, but you could try this:
Product::addFeatureProductImport($productObjc->id, $id_feature, $id_feature_value);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With