Vote up!
Vote down!

How to get Product image field in Rules?


I am creating a Rules which trigger on the event of "After saving new content". Inside the rules, I need to get the product image field. But after i drill for few ten hours, I can't seems to find a right way to do so. I guess I need to play around with the condition "Entity is of bundle" to get further data but still no luck on trying.

Hopefully someone can give some help or even some example.

Thank you in advance!

Asked by: maxchock
on May 28, 2013

2 Answers

Vote up!
Vote down!

before I got the answer from here I kind of figure out myself.

I created a "rules component", pass the Commerce Product "node:field-product:0" into "commerce_product" inside the rules component as PARAMETER, and set "Image" as PROVIDED..

I can only get the image as File data type, but it's sufficient for my use here.


Answer by: maxchock
Posted: May 30, 2013
Vote up!
Vote down!

If the product image field is inside the product variation type, you might have to use another set of events, like in this rule:

{ "rules_get_product_image" : {
    "LABEL" : "Get Product Image",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "devel", "entity" ],
    "ON" : [ "commerce_product_insert", "commerce_product_update" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "commerce-product" ], "field" : "field_images" } }
    "DO" : [ { "devel_debug" : { "value" : [ "commerce-product:field-images" ] } } ]

To get the product images from the "After saving new content" event, it would be easier to add a custom Rules action (PHP). I'm not sure if it's possible with just Rules UI from the Node context.

What do you want to do with the image or images?

Answer by: Favio Manriquez
Posted: May 29, 2013


I'm using fb_autopost to auto post product to my facebook fanspage. fb_autopost are rely on RULES totally...

- maxchock on May 30, 2013