12 March 2018

Example for how to create product variation types programmatically.

Source code viewer
  1. // Load array with empty variables for the new product type.
  2. $product_type = commerce_product_ui_product_type_new();
  3.  
  4. // Overwrite empty defaults.
  5. $product_type = array(
  6. 'is_new' => TRUE,
  7. 'type' => 'model_' . $id,
  8. 'name' => 'Model ' . $id,
  9. 'revision' => 0,
  10. ) + $product_type;
  11.  
  12. // Write the product type to the database.
  13. commerce_product_ui_product_type_save($product_type);
  14.  
  15. // Set the multilingual value for the product type if entity translation is enabled.
  16. if (module_exists('entity_translation')) {
  17. variable_set('language_product_type_' . $product_type['type'], $product_type['multilingual']);
  18. }
  19.  
Programming Language: PHP