Jump to content

Update Product Features via PHP


heyho

Recommended Posts

Hello,

 

how can i update the value from the custom featurs (Product Features) in php?

 

With product-fields its simple:

$productObj = new Product($produktId);
$productObj->setFieldsToUpdate(array('ean13'));
$productObj->ean13 = "johndoo";
$productObj->save();

BUT how can i update the product features?

Does anyone have an idea?

 

 

Link to comment
Share on other sites

If you want to do this in Object Oriented way as you mentioned, the best solution (in my opition) would be creating a new class called for example FeatureProduct.php.

 

It has to extend ObjectModel class, have variables with names from ps_feature_product table and have defined array $definition.

 

Check how does it look in

/classes/Feature.php
Link to comment
Share on other sites

I solved this Problem with:

http://stackoverflow.com/q/29816449/2355808

$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
);
# Clean both tables with cleanPositions();
Feature::cleanPositions();

Do you have an idea what $custom stands for? Which value does it contain?

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...