Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I need to change price according to the role of the user.
In drupal 7 there was a rules solution
But now rules can't support calculate sell price etc...
Can you give me the best approach for doing this.
I have create a new field in Product variation types which is "role" en entity reference of the user role.
So I can create price with role attribute, but how to display only prices according to the user role ?
Comments
Comment #2
bojanz CreditAttribution: bojanz at Centarro commentedYou need to write a PriceResolver.
Like here: http://dev.studiopresent.com/blog/back-end/drupal-commerce-2-and-sale-price
Comment #3
zoraxthank's a lot it works !
Comment #4
Bala.addweb CreditAttribution: Bala.addweb at AddWeb Solution Pvt. Ltd. commentedYou can use Commerce Pricelist for that. In further option;
- Load the product with commerce_product_load($product_id);
- Get User Role and decide Price for that.
- Change Unit price (commerce_price) of loaded product related to new decided price.
Hope this helps you.
Comment #5
bojanz CreditAttribution: bojanz at Centarro commented@nikunj.addweb
You're replying to a D8 issue with D7 advice.
Comment #6
Bala.addweb CreditAttribution: Bala.addweb at AddWeb Solution Pvt. Ltd. commentedPricelist is now available for Drupal 8.
For customization, you can get help from here
Comment #8
zoraxthanks for your answer, but I will try without pricelist (even if it sounds good ).
But I have another question, all prices displayed on the site are now function of the role user.
But When the administrator need to create order with certain price list based on the customer role how can I do that ?
I wonder if masquerade will do the job, but the administrator will have to switch between different connection it will be a nightmare...
I probably need to :
1 - alter the order form
2 - get the client role
3 - apply price of that role