For the novice, or perhaps a web developer who is only occasionally asked to create an e-commerce website, it might come as a surprise that the sale or sell price goes through a fair amount of tweaking before being represented on the site. Each step that our sell price goes through is designed to make discounts, taxes, currency conversion and many other possibilities have an impact.
Product sell prices are determined via a Rules based calculation process. If you are not up on your Rules module implementation tasks, you should check out the NodeOne Rules Videos to get up to speed.
The life of a Price Calculation
See a Prezi slideshow visualizing the process.
Sell price calculations can include discounts, taxes, currency conversion, and more. Each manipulation of the price is tracked as a price component in the price fieldŐs data array, so you can see exactly what happened to result in a particular sell price at the end of the process. You can even set the Display of any price field to show all components. This is handy for showing a user that you are giving them a discount.
The actions for manipulating unit prices include:
When configuring each action, you can specify the type of price component to use. If you need additional component types for the site (more than addition/subtract, divide/multiply, etc), you currently have to write them into a module. Not sure how to create your own price component? Look into Drupalize.me's Coding for Rules videos; they are a free and well-produced series of videos!
We are going to learn the sell price calculation process by setting up a conditional discount for our administrators. We will use a condition to apply a 50% discount for any user with the role "Administrator" and show the price with components.
Our base price: $30
What the sell price should be on checkout with 50% discount if I'm an administrator: $15
Rule Overview
Calculating sale price event should be selected by default. We're going to add a condition for only affecting prices if users are administrators. We're going to reduce the price the by 50%.
Add Condition
When creating a condition, it will ask you what you want to look at. For our discount, we want to look at user's roles.
Add Action
Next, we've already clicked on Add Action and are now selecting the multiply unit price option.
Configure Action
When you are setting the actual math part of the discount, we chose to simply multiply by 0.5 for a 50% discount. You could also divide by 2. Note also that we have changed the value of the price component type. The price component type will show up when you show the price with components. Note that if you want to add your own price component type it will likely need to be done in code.
Reveal Price
We could show you a screenshot of the new product, but that would not show us that the rule is really working. To see the discount on your product, you must go to the manage display.