I want to create a pricing rule based on discount entered in a field in the product display node? Is it possible? I have been trying to do it but i can't see the discount field in the dataselector. I tried entity has field but there only line-item entity appears and no node entity?
You can do this, I have done so myself. It's been a lot easier to do this than when I needed to do this.
The thing is that in rules, in order to get the fields of an entity, to use it in Rules, you need to either add a condition that the field exists or add a condition that the entity is of type X.
I've attached the base setup that does this for the commerce kickstart install profile. You might be using a different product type, but it should be easy to change.
Since you are saving the discount on the product display, you are making it more difficult for you. What you need to do, is from the line_item/product context to be able to figure out which product display the product comes from. The easiest way to do that would be to add a node reference field on the line item and then populate that with the product display node when adding the product to the cart. This should be doable with a custom submit handler added to the add to cart form with
As I said on IRC, a line item doesn't store the id of the product display in a way that Rules can understand. This is because product displays are not required for Commerce to work.
However, line items have a "commerce_display_path" field that stores the url from which the product was added, so in your case it would probably look like "node/1", or whatever the node id is.
What you need to do is: Write a custom Rules action that takes the line item, initializes the wrapper, gets the value of commerce_display_path, explodes the string, takes the nid, loads the node, returns it.
Place this in a custom rules action, and you're good to go.
You can then use your action in a component to get the product display whose fields you can then access.
protected by kiamlaluno♦ Mar 8 '12 at 19:08
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.
Would you like to answer one of these unanswered questions instead?