1

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]

4
  • Now, the problem comes when trying to show both wholesale price and reseller price on the product pages including taxes. What problem? Do you mean a reseller sees the same price twice because the base price is overwritten by the reseller price? Jun 15, 2016 at 10:54
  • yes, sorry being unclear. I mean exactly that. Because prices are overwritten by rules, "original" price is not available anymore.
    – SPR
    Jun 21, 2016 at 11:56
  • Please edit and improve the question to include those details :) Jun 21, 2016 at 11:58
  • No problem :) But it is important to keep details in the question content (so people who want to answer don't have to read through all comments). Jun 21, 2016 at 12:03

2 Answers 2

0

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.

5
  • Thanks so much for giving a thought on this. I really like the idea of trying to solve the original problem totally different.. Spent few hours with this but with no luck :( Question now shows idea of original price calculation rule. When changed the event from "Calculating the sell price" as: 1) "Before adding a product to the cart" >> Fails, because commerce-line-item is not available as parameter anymore 2) "After adding a product to the cart" >> Does not give any errors and log shows that rule fires but it does not change the price in the shopping cart
    – SPR
    Jun 22, 2016 at 10:01
  • Perhaps you can use your original Rule and add a condition to see if the line-item:commerce-order:state == [cart OR checkout]. So it only rewrites the price if the product is already in the cart (or further in the checkout process)? But I do not have the time to verify it right now. Jun 22, 2016 at 10:09
  • thanks, tried that too but it did not help. Put the order state to debug log to see value and for some reason value is cart, even if shopping cart is empty...
    – SPR
    Jun 22, 2016 at 10:36
  • Then I am out of ideas, sorry. Perhaps someone else might have a bright idea. Jun 22, 2016 at 10:42
  • 1
    I appreciate your time, got some new point of views to the problem anyway :)
    – SPR
    Jun 22, 2016 at 10:54
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.