0

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"

Error: Data selector commerce-line-item:commerce-product:field-dealer-price:amount for parameter amount is invalid.

Here are the steps I took to get to my current spot:

  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"
  2. 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
  3. Then, I get stuck with Add Actions:
  4. Select action to add: Commerce Line Item: Set item to specific amount
  5. Line Item: Data Selector: commerce_line_item (Already inserted)
  6. 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. My products show up correctly in the shopping cart, so that hasn't been an issue.

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

Thanks,

1
  1. Entity has field: Parameter: Entity: [commerce-line-item], Field: field_dealer_price

Your price field won't be on commerce-line-item. It will be on commerce-line-item:commerce-product. You need to check for it there.

  1. 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

So since the field_dealer_price is on the product instance, you'd be looking at this: commerce-line-item:commerce-product:field-dealer-price:amount

An example, without the role condition, would look like this:

{ "pricing_from_another_field_example" : {
    "LABEL" : "Role based pricing example",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "commerce_line_item", "commerce_product_reference" ],
    "ON" : { "commerce_product_calculate_sell_price" : [] },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "commerce-line-item" ], "field" : "commerce_product" } },
      { "entity_has_field" : {
          "entity" : [ "commerce-line-item:commerce-product" ],
          "field" : "field_dealer_price"
        }
      }
    ],
    "DO" : [
      { "commerce_line_item_unit_price_amount" : {
          "commerce_line_item" : [ "commerce_line_item" ],
          "amount" : [ "commerce-line-item:commerce-product:field-dealer-price:amount" ],
          "component_name" : "base_price",
          "round_mode" : "1"
        }
      }
    ]
  }
}
  • Thank you for taking a look at this. I am missing something that is probably very obvious. In the "Fields search" report, I confirmed where the standard Drupal Commerce "commerce_price" field and my new "field_dealer_price" is used. Right now, they are used only on the new Product Variations that I created: Bikes, Hubs, etc. – keb805 Oct 30 '15 at 17:58
  • Correction I changed my third condition to "Entity has field" Parameter: Entity[commerce-line-item:commerce-product,Field: field_dealer_price. I had mistakenly deleted a condition in my zeal to fix things....Now everything works :) Holy cow! Thank you very much. – keb805 Oct 30 '15 at 18:27
  • No problem! Please be sure to mark your question as answered. – nvahalik Oct 30 '15 at 20:17

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.