I'm using Rules to create drupal commerce products. The problem is that the product_id is not assigned.

Since the Rules settings page for creating products only gives the following options, I assumed that the product_id would be generated automatically:

Entity type, SKU, Type, Title, Creator, Price, Provided variables.

If the product_id has to be added manually (within Rules) how would I obtain the correct value to use? (Or is there a setting I am missing within Rules?)



You cannot set the product ID manually, because it depends on the AUTO_INCREMENT value in your commerce_product database table. What you can do is use "Save an entity" on the product and check the "Force saving immediately" checkbox. The entity will have an ID after that, though I've had scenarios in Rules where for some reason the ID wasn't immediately added to the entity in memory. If this happens to you, you'll just have to use "Fetch an entity by property" after saving and load the product using the SKU or something and use the fetched_entity from then on.

|improve this answer|||||
  • 1
    Thanks Ryan, added a "save entity" action and it works! :) – Pog Le Pog Oct 23 '13 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.