SPECIAL OFFER: Only $69 for access to everything in OSTraining for 1 year! You save $75! 

Commerce Kickstart: Rules >> Pricing & User Roles

5 years 10 months ago #118558 by keb805
After working thru the Commerce tutorial and understanding roles, I thought it would be straightforward to set up a pricing rule based on user role, but I cannot seem to build the correct "Action" in Rules.

I want to reference a "Dealer Price" field in a Product Variation is the User Role = "dealer"

1. In a custom Product Variation "Bikes", I created a new field "Dealer Price" that mirrors the "Price" field that is already part of Commerce Kickstart
  • Dealer price
  • Field Type: Price
  • Widget: Price with Currency
2, Created role "Dealer"
3. Initiated creation of pricing rule
  • Store Settings >> Pricing Rules
  • Add Pricing Rule
  • Add Event: Calculating the sell price of a product
  • Add Conditions: 1. User has role(s): Parameter: User: [site:current-user], Roles: dealer; 2. Entity has field: Parameter: Entity: [commerce-line-item], Field: commerce_product; 3. Entity has field: Parameter: Entity: [commerce-line-item], Field: field_dealer_price
4. Then, I get stuck with Add Actions:
1. Select action to add: Commerce Line Item: Set item to specific amount
2. Line Item: Data Selector: commerce_line_item (Already inserted)
3. Amount: [Click on Switch to Data Selector]: commerce-line-item:commerce-product:field-dealer-price:amount
**or**commerce-line-item:commerce-product:field_dealer_price:amount **or**commerce-line-item:commerce-product:field-dealer_price:amount

I get an error msg when trying to reference the new price field "Dealer Price". I feel like I am missing a connection within Commerce that ties the Product Variation to the Commerce_line_item, but I haven't been able to identify the missing link.

Any help in tying the concepts of "Roles", "Rules", and "Commerce Kickstart" together is appreciated.

Thanks,
keb805

This message has an attachment file.
Please log in or register to see it.

Please Log in to join the conversation.

5 years 10 months ago #118587 by steve
Hi keb805

Sadly, I can see very little about this online. Drupal Commerce documentation is not the best.

There are two useful forum comments here:
drupalcommerce.org/comment/1610#comment-1610
drupalcommerce.org/comment/9178#comment-9178

This is the only tutorial I could find: jamestombs.co.uk/2012-09-14/drupal-comme...rent-customer-groups Have you seen that guide and does it help?
The following user(s) said Thank You: keb805

Please Log in to join the conversation.

5 years 10 months ago #118611 by keb805
Steve,

Success! I had read both of the posts you mentioned multiple times, but to no avail. However, this morning, I walked through the steps again and realized that I had missed how one of the conditions was supposed to be set up. The conditions are meant to be as follows:

1. User has role(s): Parameter: User: [site:current-user], Roles: dealer;
2. Entity has field: Parameter: Entity: [commerce-line-item], Field: commerce_product;
3. Entity has field: Parameter: Entity: [commerce-line-item:commerce-product], Field: field_dealer_price

I had gone straight to `commerce-line-item:field_dealer_price`, and Drupal was trying hard to tell me that there was no path there.

That said, I don't understand something in the architecture of either Rules logic or Commerce that takes the Product Variation and crunches it to see it as a `commerce-line-item:commerce-product`.

I will repost to the Commerce Q&A to see if I get any information on that front.

So excited to have this part working! I bombed a bit yesterday while struggling to add this feature, but we are in business (figuratively) today!

Thank you for pointing me to re-read!
Katie

Please Log in to join the conversation.

5 years 10 months ago #118612 by steve
Wonderful, thanks Katie. Congrats on solving that!

To be honest, my next step would have been to ask to dive into the site and test everything myself too. Drupal Commerce can be a complex beast at times :)

Please Log in to join the conversation.