Tags/topics: 
2
Answers
Vote up!
0
Vote down!

How to get Product image field in Rules?

Hi,

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!
0
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.

Thanks.

Answer by: maxchock
Posted: May 30, 2013
Vote up!
0
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

Comments

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