Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Product Features via PHP in Prestashop

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?

like image 489
Harry Avatar asked Sep 19 '25 06:09

Harry


2 Answers

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 );
like image 120
Harry Avatar answered Sep 20 '25 21:09

Harry


Mh, Ive never tried to do this, but you could try this:

Product::addFeatureProductImport($productObjc->id, $id_feature, $id_feature_value); 
like image 33
elPresta Avatar answered Sep 20 '25 20:09

elPresta