Sell Price Calculation Overview

Product Price Calculations happen under store configuration product pricing rules

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

  1. A new line item is created representing the product as if it were in the user's current shopping cart order.
  2. The unit price of the line item is initialized to the productŐs base price (commerce_price) value.
  3. The line item is then passed through Rules via the Calculating the sell price of a product event where its unit price may be manipulated as necessary.
  4. The final unit price of the line item becomes the sell price of the product displayed on product pages and Views.

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!

Administrator's Special

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

Create a product pricing rule

Pricing Rule

Create a Product pricing rule.


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%.

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%.


Select the user has roles condition.

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.


Select the administrator role.

Administrator

Selecting the appropriate role is all you have to do for this screen.


Next, we've already clicked on Add Action and are now selecting the multiply unit price option.

Add Action

Next, we've already clicked on Add Action and are now selecting the multiply unit price option.


Set .5 for 50% off, and select Discount for the price component type.

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.


Final Rule Screen Overview

Rule Overview

The final screen for the rule that will set all prices to be 50% for administrators.


Lets reveal the price components

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.


Set the price field to show formatted with components.

Price Field

Set the price field to show formatted with components.


Administrators see the discount

Final Discount

Simply changing the price to show with components, it displays all that is necessary for the discount to be obvious. Also in the screenshot is the same site, not logged in. This is an important step to make sure that your condition is actually working.