when i create programmatically a product with variations i wil get the following error:

InvalidArgumentException: Field variations is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 509 of /private/var/www/gsmdrupal/web/core/lib/Drupal/Core/Entity/ContentEntityBase.php).

Comments

fidodido06 created an issue. See original summary.

drugan’s picture

Are you sure you create variations the right way in your code? Read more:

#2811529: How to create commerce products from code

mglaman’s picture

Priority: Major » Normal
Status: Active » Closed (works as designed)

Due to core limitation with views and base fields that are multiple cardinalities, you need to call

      commerce_product_add_stores_field($this->entity);
      commerce_product_add_body_field($this->entity);
      commerce_product_add_variations_field($this->entity);

on any product type made programmatically, and ensure you export config properly.