Discount codes

A discount is a price incentive offered to customers to promote a purchase. A discount code is a calculation code whose calculation usage is "discount." It is used to calculate order item adjustments. Each row in the CALCODE table represents a CalculationCode. CalculationCodes represent ways of determining monetary amounts associated with OrderItems. They are used to calculate discounts, shipping charges, sales tax, and shipping tax. A CalculationCode attachment can be limited to specific TradingAgreements.

Two dimensions are involved in attaching a discount code to a product or a group of products. First, the discount can be attached to one or more catalog entries, and catalog groups. Attaching a calculation code to a catalog group has the same effect as attaching it to all the catalog entries directly in the catalog group.

Second, the order items are grouped for calculation in one of four ways: per trading agreement, per product, per offer, or per shipping address. This is specified by the groupBy attribute. A separate calculation is performed for each group of OrderItem objects. If no grouping is specified, then all the OrderItems attached to a particular CalculationCode object are used to perform a single calculation. The following outlines the attributes used to calculate different types of discounts:

Discounts calculated by trading agreement
The perTradingAgreement attribute means that all order items in a group must have the same trading agreement for the calculation code to be applied.
Example: Trading agreement 123 which has a discount code attached to it, giving a 10% discount if more than $100 is spent. Under the perTradingAgreement grouping, if a customer spends $175 under contract 123, then the discount is $17.50 off the price of the order, resulting in a $157.50 total, after discount.
Discounts calculated by product
The perProduct attribute means that all order items in a group must be associated with the same product for the calculation code to be applied. (The product can be either the catalog item's parent catalog entry, according to the PRODUCT_ITEM relationship type in the CATRELTYPE database table (if there is one), or just the catalog item itself.)
Example: a discount code is attached to both CatalogEntry object 1 and CatalogEntry object 2, and the discount code specifies a 15% discount when more than 10 are purchased. If the perProduct attribute is true, then buying 7 of CatalogEntry 1 and 3 of CatalogEntry 2 would not qualify for the 15% discount. Only one CatalogEntry quantity can be 10 or over to receive the discount. However, if the perProduct attribute is false, then the two amounts whose total is 10 qualify for the discount.
Discounts calculated by offer
The perOffer attribute grouping is appropriate for tax calculation codes.
Example: The statement "No tax on children's shoes priced under $30" refers to the price of a single pair of children's shoes. If several pairs of children's shoes are in the order, every pair that is under the cutoff price is tax-free. Since each offer represents a different unit price, OrderItems are grouped by the Offer object to determine tax amounts based on unit price.
Discounts calculated by shipping address
Although normally used for calculating shipping charges, the perShippingAddress groupBy attribute can also be used to group order items for discount codes according to their shipping addresses.
Example: an order level discount is defined as "10% off purchases totaling $100 or more with the same shipping address," and an order contains four items: item 1 (price $40, shipping address 10), item 2 (price $50, shipping address 10), item 3 (price $40, shipping address 20), and item 4 (price $60, shipping address 20). Since they have the same shipping address, order items 1 and 2 form a group, and order items 3 and 4 form another group. The discount calculation is performed twice, once for each group. Since the total amount for the first group is less than $100, items 1 and 2 do not qualify for a 10% discount. However, since the total amount for the second group is $100, items 3 and 4 each qualify for a 10% discount. On the other hand, if the perShippingAddress groupBy attribute value were not specified, all four items would qualify for the discount, regardless of their shipping addresses.

Products can have more than one discount associated with them. Similarly, member groups can be eligible for more than one discount. When more than one discount calculation code applies to an Order object, discount calculations are performed in ascending sequence of their CalculationCode object sequence attributes. This restricts a calculation code for use only by certain member groups as defined in the CALCODEMGP table. As with all calculation codes, multiple discount codes can be associated with each product and discount codes can be restricted for use only by certain member groups.