Sell Price Calculation

Product Price Calculations happen under store configuration product pricing rules
  • Administration
  • Store
  • Configure
  • 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:

  • Add an amount to the unit price
  • Convert the unit price to a different currency
  • Divide the unit price by some amount
  • Multiply the unit price by some amount
  • Set the unit price to a specific amount
  • Set the unit price's currency code
  • Subtract an amount from the unit price

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

Pricing Rule

Create a Product pricing rule.

  • Administration
  • Store
  • Configuration
  • Product Pricing Rules
  • Add a Pricing Rule

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

  • Administration
  • Store
  • Configuration
  • Product Pricing Rules
  • Overview

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.

  • Administration
  • Store
  • Configuration
  • Product Pricing Rules
  • Add Condition

Administrator

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

  • Administration
  • Store
  • Configuration
  • Product Pricing Rules
  • Configure Condition

Add Action

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

  • Administration
  • Store
  • Configuration
  • Product Pricing Rules
  • Add Action

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.

  • Administration
  • Store
  • Configuration
  • Product Pricing Rules
  • Configure Action

Rule Overview

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

  • Administration
  • Store
  • Configuration
  • Product Pricing Rules
  • Rule Overview

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.

  • Administration
  • Store
  • Products
  • Product Types
  • Manage Display

Price Field

Set the price field to show formatted with components.

  • Administration
  • Store
  • Products
  • Product Types
  • Manage Display
  • Edit Price

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.

  • Administration
  • Store
  • Products
  • Product Types
  • Manage Display
  • Edit Price

Found errors? Think you can improve this documentation? edit this page