Skip to main content
added 574 characters in body
Source Link

Yes, this is correct way. But it will work only if product is created with the help of form. If you want to add some actions every time when product is created even it is created without the help of product form(e.g programmatically) you should use hook_entity_insert

UPD: You had to say about autogenerated products in your initial post. You may add some property to all products that are created there and check it in hook_entity_insert. Example(maybe need some modifications):

/**
 * Implements hook_entity_insert().
 */
function mymodule_entity_insert($entity, $type) {
  if ($type == 'product') {
    if (empty($entity->auto_generate)) {
      $new_product = entity_create('product');
      $new_product->auto_generated = TRUE;
      $new_product->save();
    }
  }
}

Yes, this is correct way. But it will work only if product is created with the help of form. If you want to add some actions every time when product is created even it is created without the help of product form(e.g programmatically) you should use hook_entity_insert

Yes, this is correct way. But it will work only if product is created with the help of form. If you want to add some actions every time when product is created even it is created without the help of product form(e.g programmatically) you should use hook_entity_insert

UPD: You had to say about autogenerated products in your initial post. You may add some property to all products that are created there and check it in hook_entity_insert. Example(maybe need some modifications):

/**
 * Implements hook_entity_insert().
 */
function mymodule_entity_insert($entity, $type) {
  if ($type == 'product') {
    if (empty($entity->auto_generate)) {
      $new_product = entity_create('product');
      $new_product->auto_generated = TRUE;
      $new_product->save();
    }
  }
}
Source Link

Yes, this is correct way. But it will work only if product is created with the help of form. If you want to add some actions every time when product is created even it is created without the help of product form(e.g programmatically) you should use hook_entity_insert