0

I need to programmatically update a product with drupal commerce.

Which hook can I use?

And how can I get the value of the variation? If for example I have a field in the product variation which is field_newvar?

(In drupal 7 I used

 hook_node_presave($node) { 

and then got the commerce product entity with entity_metadata_wrapper but now in drupal8 we don't need nodes to show products.)

General Grievance
  • 4,555
  • 31
  • 31
  • 45
user1619177
  • 145
  • 9
  • try [hook_ENTITY_TYPE_presave](https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21entity.api.php/function/hook_ENTITY_TYPE_presave/9.0.x).. – 2pha Aug 10 '20 at 01:21
  • thank you it worked but I can't save the value I tried function hook_commerce_product_presave(Drupal\Core\Entity\EntityInterface $entity) { $result = $entity->get('title')->value; $entity->set('field_essai', $result); $entity->save(); } – user1619177 Aug 10 '20 at 13:41

0 Answers0