Discussions

How to setup role-based product prices?

How to setup role-based product prices?
We don't want role-based discount, we need completely different price plans based on roles.

Posted: Aug 8, 2011

Comments

mayar on August 8, 2011

Now I try:
1. Add to product field 'price2' (of type 'price').
2. Make pricing rule:
event: Calculating the sell price of a product
condition: User has role(s)
action: ???

What action I must use for copying price from field 'field_price2'?

May be is some another way..

rfay rfay on August 9, 2011

OK, I just tried this out and it seems to be OK.

1. Add a field called adminprice to the product.
2. Create a product pricing rule:
When calculating the sell price of an order
Condition: Entity has field Parameter: Entity: [commerce-line-item], Field: commerce_product
Condition: Entity has field Parameter: Entity: [commerce-line-item:commerce-product Field: field_adminprice
Condition: : User: [site:current-user], Roles: administrator

Action: Set a data value: Parameter: Data: [commerce-line-item:commerce-unit-price:amount], Value: [commerce-line-item:commerce-product:field-adminprice:amount]
Action: Commerce Line Item: Set the unit price to a specific amount: Parameter: Line item: [commerce_line_item], Value: [commerce-line-item:commerce-product:field-adminprice:amount]

The reason you have to use the commerce_line_item-supplied action instead of just using set-data-value is that the line item actually manages and stores all components involved in the calculation of the price, and this is just one of them.

jras on August 13, 2011

Randy,

The recipe listed above worked like a charm. Problem is, when I reached the checkout screen, my "Order Total" did not comput correctly. The order total was correct in the shopping cart block, however, at checkout my order total was incorrect. Any ideas?

rfay rfay on August 15, 2011

If you can give more detail it will be easier to help you. Like... What does "incorrect" mean? Screenshots of your cart and checkout and rules would help.

mayar on August 17, 2011

I have problem with "Order total". It is still use the base price on /checkout page.

Rule export:
{ "rules_price_for_operator" : {
"LABEL" : "price_for_operator",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules", "commerce_product_reference" ],
"ON" : [ "commerce_product_calculate_sell_price" ],
"IF" : [
{ "user_has_role" : {
"account" : [ "site:current-user" ],
"roles" : { "value" : { "5" : "5" } },
"operation" : "OR"
}
},
{ "entity_has_field" : { "entity" : [ "commerce-line-item" ], "field" : "commerce_product" } },
{ "entity_has_field" : {
"entity" : [ "commerce-line-item:commerce-product" ],
"field" : "field_priceoperator"
}
}
],
"DO" : [
{ "data_set" : {
"data" : [ "commerce-line-item:commerce-unit-price:amount" ],
"value" : [ "commerce-line-item:commerce-product:field-priceoperator:amount" ]
}
}
]
}
}

thejtate on August 16, 2011

Well I tried it myself and I didn't get any errors setting up the Conditions or Actions in the Rules. But, my total is still pulling from the typical unit price and not the discounted admin price.

Took me a while to finally get how I have to declare in the Conditions what I want to pull for the Actions, just not sure what I'm doing wrong at this point.

Any thoughts? Thanks.

ponies on September 11, 2012

Is there a way to automatically apply a coupon to an order based on the user's role? I want to highlight their fantastic savings.

Ole Martin on April 12, 2012

Can not get this.
Is it the "product" I'll add a field, and how do I do this? Or is it my own content type that I made?

If the error message "Value": The data selector commerce-line item: commerce product: field-admin price: amount for the amount parameter is invalid.

newbieUser on March 5, 2013

goal:
trade - see retail and wholesale price
annoy. and auth. user see retail price.

use kickstart2.0

did not setup admin price , use std commerce_price which is a std field in product variation
use commerce_price_eur, as retail price, a std field after enabling mulitcurrency.
is this wrong?

then I make commerce_price hidden. Wrong again?

follow the receipe, except
Value: [commerce-line-item:commerce-product:field-commerce_price:amount]
Roles: shop (instead of admin, already admin/people/permissions/roles and add a new role: shop)

when shop login. commerce_price is still hidden??

zeta1600 on February 10, 2012

This worked perfectly... for one other price. I have a scenario that is a little more complex though. Sometimes a product is taken to different venues where I could have two to three different prices for the same product. Can any of you suggest how to best do that? Just add another price and another rule? Would that make sense?

Patroclas on February 11, 2012

If there is a logic to the price selection, then I guess you should be able to add that as a condition of the rule, adding prices to the product as before.

newbieUser on March 9, 2013

maybe i did not post my question at the right place, therefore did not get any feedback.
Let me try again.

Goal :
everyone see retail price (commerce_price)
user (shop) see both retail and trade price

with multicurrency enabled, I have 3 default price input field:
1. commerce_price (input trade price) , instead of creating a field as rfay suggested. Question 1 : Is it ok to use this default field?
2. commerce_price_eur (input retail price)
3. commerce_price_usd

Question 2: Do i have to "hidden" commerce_price (input trade price) in the content type, manage display?

Go to admin/people/permissions/roles and add a new role: shop

Then I did as rfay suggested
Create a product pricing rule:
When calculating the sell price of an order
Condition: Entity has field Parameter: Entity: [commerce-line-item], Field: commerce_product
Condition: Entity has field Parameter: Entity: [commerce-line-item:commerce-product Field: commerce_price
Condition: : User: [site:current-user], Roles: shop

Action: Commerce Line Item: Set the unit price to a specific amount: Parameter: Line item: [commerce_line_item], Value: [commerce-line-item:commerce-product:commerce_price:amount]

When login as shop , the commerce_price (trade price) did not show up?
Where did I do wrong?

drupalcommerce In this week's Commerce Module Tuesday video @MrJoshMiller takes a look at @jazzdrive3's Commerce Product Add-on: http://t.co/HUry3sYyxu
drupalcommerce RT @DrupalATX: Learn how to launch an online store straight from the @commerceguys! http://t.co/vYz4XeXmox #drupal #training
drupalcommerce Check out the #Drupal Commerce 2.x Roadmap to see where you can get involved: http://t.co/WAc3jmXY2a