Commerce: programmatically create new product with my ID I have database of products and I want to export it to Drupal Commerce database with my Ids being saved:

$product = commerce_product_new('product');
$product-&gt;product_id = '100500';
$product-&gt;title = 'my title';
commerce_product_save($product);


But it always returns STATUS_UPDATE because in sites/all/modules/commerce/modules/product/includes/commerce_product.controller.inc in line 80 there is:

// Determine if we will be inserting a new product.
$product-&gt;is_new = empty($product-&gt;product_id);


It always clears "is_new" when "product_id" is filled.

If I change that string like:

$product-&gt;is_new = !empty($product-&gt;is_new) || empty($product-&gt;product_id);


Everything works fine.

Is it a Commerce bug or I do something wrong?
I don't see this as a bug, as we do want to prevent arbitrary IDs from being set in general. If you're doing it intentionally, though, I think your best bet would be to implement an override in a custom entity controller that extends the core functionality and changes the behavior of the is_new check like you've done.