Last updated 19 May 2016. Created on 19 May 2016.
Edited by joshmiller. Log in to edit this page.

The sandbox module, Commerce Order Sub-total, was developed for a client's shipping calculation requirement. The idea behind the module is to provide useful sub-totaling of Orders using the Rules framework. This module exposes three different ways to retrieve a sub-total of an order:

  1. Rule Condition - You can create or modify a rule on any event and add an Order Sub-total condition. It is a sub-total because you can choose what kinds of products and line items (and even specific shipping services) to include in the total. The condition can take any number in minor units ($1.00 == 100) and compare it against the sub-total you have configured.
  2. Rule Action - You can add an action that will return the order sub-total. A sub-total is the same as the condition and can return the full order amount while excluding any kind of product or line item or shipping service. This allows you to bring in an integer that you can use in your shipping or pricing calculations.
  3. Commerce Discount Condition - Using commerce_discount, you can add a condition to any number of discounts based on the order sub-total. This means you could set or reduce the price of shipping based on an order total that doesn't include digital products. Lots of other possibilities can be opened up as well.

How to install the module

Follow the normal procedure for installing modules. Once installed, you should be able to find a new condition, action, and commerce_discount condition where you would expect them. There is no configuration or documentation page for the module. More details on how to use the module is below.

How to use the module

As described above, there are three different ways you can access an order sub-total. All three ways are found in some form of a Rules or Commerce Discount interface. Below each type of use is described in detail.

How to add an Order Sub-Total Rule Condition

Commerce Order Subtotal Condition

The animated gif above shows you how to add a condition to the rule.

  1. Locate or create the rule you want to add a condition to. For our example above, we are making our free shipping option only appear on orders that $20 or more of non-digital products.
  2. Add the condition "Order Sub-total Comparison"
  3. Choose your comparison operator (the most common one is default).
  4. Give us, in minor units, (pennies for US Dollars) what number we should compare the total to.
  5. Select which line items you want to exclude. The most common two kinds of line items are products and shipping. As demonstrated above, there can also be discount line items. There is no limit to the kinds of line items you might see on an order and the module is smart enough to skip line items that have no value.
  6. Select which kinds of products you want to exclude. This means you would need to not exclude or select the "product" line items in the above area. There is where the magic of excluding "digital" products can happen. Or, perhaps, "shoes" or "anti-matter" could be excluded.
  7. Click save.

There are other kinds of things you can remove from the order total, including certain shipping services (assuming you're allowing shipping line items at all), and SKUs. The SKUs element provides the ultimate control and lets you cherry-pick specific products you don't want included in the order total.

How to add a Order Sub-Total Rule Action

Commerce Order Subtotal Action

The above gif walks you through adding an action for the Order Subtotal. This is required to provide a variable to be used in a calculations or messages later on. For example, you could send an email with the order sub-total that was calculated, or you could use the subtotal to calculate a rate for shipping physical products. The steps are nearly identical for the condition.

How to add a Commerce Discount on Order Sub-Total

Commerce Order Subtotal Discount

When you go to add a commerce_discount, you have to choose which kind of discount you want. The one above is an order-level discount, and then you need to choose a condition. Our subtotal is a condition called "Total Amount (advanced)." This is named to make sense in context with the other order total conditional called "Total Amount." Just like the rules above, you can choose to exclude line items, product types, shipping services, and skus.

The discount we create in the above animation takes $2 off for any order that has more than $20 of non-digital products.

Looking for support? Visit the forums, or join #drupal-support in IRC.