Commerce Discount - Adds the commerce module the ability to handle discounts.
The Discount UI (available under Admin → Commerce → Store → Discounts) allows creating and editing discounts. Each discount consists of two related entities: Commerce Discount and Commerce Discount Offer. The Discount allows you to choose what type of entity this discount this will apply to i.e. "Order Discount" or "Product Discount" (line item). The Commerce Discount Offer denotes the result the discount produces. The module provides 4 discount offers out of the box.
Types of Discounts (Offers) Available
- $ off
- Apply a flat discount amount. Applies to orders and product discounts.
- % off
- Apply a percentage discount amount. Applies to orders and product discounts.
- Free products
- Adds a free product to the order. Applies to orders only.
- Free shipping
- Gives the order free shipping. Applies to orders only.
Once you select the type of discounts you want to create (product or order), you can then set selectively apply the discount based on conditions that are available in the UI by choosing one or more conditions.
- Total amount
- For orders, applies if total amount of the order matches is lower than, equal to, or greater than an arbitrary amount.
- For orders, applies if the user selected owns the cart.
- For orders, applies if the specified product is in the cart. For products, applies if the product matches the specified product.
- Products & Quantity
- For orders, applies if the specified product and quantity are in the cart.
- Product attributes
- For products, applies if the product is associated with the specified term.
Commerce Discount & Rules
The Commerce Discount UI is really a front-end for rules. When creating a discount, a rule is generated for doing the actual price reduction. For order discounts, the rule is attached to the
commerce_order_presave event. For product discounts, the event is
commerce_product_calculate_sell_price, which is fired every time a product's price is displayed.
How discounts are applied to products and orders
The action fired by these events is either
commerce_discount_percentage, depending on the offer type. When
commerce_discount_fixed_amount is called for an order discount, and the discount hasn't been applied to the order yet, it creates a new line item representing the discount and adds it to the order. When it's called for a product discount, and the discount wasn't applied to it yet, it adds a component to the product price, on the line-item, representing the discount.
commerce_discount_percentage is adding price components (either to all of the order's line items, or for a line item of a specific product) with the discount converted to an absolute number.
Commerce Discount ships with two included modules that provide extra functionality surrounding discounts.
Commerce Discount Date
Adds the ability to make a discount applicable only between certain dates. It works by adding a condition to the generated discount rule, verifying that the current date is in between the dates defined on the discount.
Commerce Discount Usage
Adds the ability to make a certain discount applicable only a certain amount of times. Works by adding a field to the discount, tracking how many times it was used and by adding a condition checking the current discount usage against the defined maximal usage.
The usage count is incremented when an order is created and when a discounted product is added to cart, and is decremented when an order gets deleted and when a product is removed from the cart.
Related Contrib Modules
- Commerce Discount Product Category
- Adds a condition field that allows you to reference the taxonomies/categories attached to the product display instead of the product itself. In other words, you can use the categories that you assign to your product displays to determine whether or not you want to apply a discount instead of having to directly assign those taxonomies to your products individually.
- Commerce Coupon
- Allows you to add coupon functionality to Drupal Commerce.
- Commerce Discount Extra
- Adds a number of additional conditions and offer types. Examples include % per quantity discount, Fixed amount per-quantity discount, Order-owner role condition, Total items in order, and more.
- Commerce Taxonomy Discount
- Adds conditions for discounts based on the taxonomy of a product.