Drupal Answers Asked by SPR on January 14, 2021
Building a webshop for customer with Drupal 7 + commerce. I’ve defined two price fields for commerce product entity:
1) base price (excluding tax) that is wholesale price
2) retailer price (excluding tax)
There is a rule with a condition “current user has role reseller” and action that sets retailer price as base price. This works perfectly, showing different price for logged in resellers. Also, there’s a rule for tax calculation.
Now, the problem comes when trying to show both wholesale price and reseller price on the product pages including taxes. Because prices are overwritten by rules, “original” base price is not available anymore. I’ve tried to figure out how to do this programmatically since “Commerce price savings formatter”-module does not work with this kind of price structure. (tested price savings formatter module with discount rules, we are also using and it works well)
I’m quite lost where this should be done, should I change it in product node template (or template.php with some hook)? I can find the the original price without tax by going really deep in the content array. But I would need the tax too, at least the percent so I can do the calculations.
Any help, even tiny hints are much appreciated!
EDIT:
The working rule that sets the retailer price is defined as follows:
EVENT:
* Calculating the sell price of a product
CONDITIONS:
* User has role (=retailer)
ACTIONS:
* “Product has special price”-component
* Parameter:[commerce-line-item] (named as “product line item”)
Then I have custom component “Product has special price”-component
CONDITIONS:
* Data comparison: [product-line-item:type] = Product
ACTIONS:
* Set the unit price to a specific amount
* Parameter: [product-line-item]
* Amount: [product-line-item:commerce-product:field-retailer-price:amount]
Finally found a solution. The problem was in the original price rule settings.
The action "Sets the unit price to a specific amount" had a wrong [price component type], it was "Base price" and it should have been "Discount" of course. That is why the original base price was not available any more on product pages.
Also, the price savings module works now, so no need to make any customizations there.
Answered by SPR on January 14, 2021
I have been thinking of this, but can you delay the setting of the price?
I suppose you are currently overwriting the price when the user is viewing the node? Can't you set the correct price when the product is added to the cart? That would allow you to show both prices next to eachother.
Optionally if you don't want regular users to see the wholesale price, use a module like Field Permissions to prevent certain roles from viewing certain fields.
Answered by Neograph734 on January 14, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP