Set or clear product price discounts.
- [discount code] Discount rules [/discount]
||The product's SKU code or one of either "ALL_ITEMS" or "ENTIRE_ORDER".
||Select the discount namespace to use.
||Alias for discount_space.
||Parse Interchange tags, included in the body text, before this container tag executes.
code => $sku,
body => $body,
or similarly with positional parameters:
$Tag->discount($sku, $attribute_hash_reference, $body);
Product discounts can be set upon display of any page.
The discounts apply only to the customer receiving them
and may be of one of three types:
- A discount for one particular item code (code/key is the item's SKU code)
- A discount applying to all item codes (code/key is ALL_ITEMS)
- A discount applied after all items are totalled (code/key is ENTIRE_ORDER)
The discounts are specified using a formula.
The formula is scanned for the variables "$q" and "$s",
which are substituted for with the item quantity and subtotal,
In the case of the item and ALL_ITEMS discount,
the formula must evaluate to a new subtotal for all items of that SKU
code that are ordered.
The discount for the ENTIRE_ORDER is applied to the entire
order, and would normally be a monetary amount to subtract or a
flat percentage discount.
Discounts are applied to the effective price of the product,
including any quantity discounts.
To apply a straight 20% discount to all items:
[discount ALL_ITEMS] $s * .8 [/discount]
or with a named, rather than a positional, parameter:
[discount code=ALL_ITEMS] $s * .8 [/discount]
To take 25% off of only item 00-342:
[discount 00-342] $s * .75 [/discount]
To subtract $5.00 from the customer's order:
[discount ENTIRE_ORDER] $s - 5 [/discount]
To reset a discount, just set it to an empty string, like this:
Perl code can be used to apply the discounts.
Here is an example of a discount for item code "00-343",
which prices the second one ordered at 1 cent:
return $s if $q == 1;
my $p = $s/$q;
my $t = ($q - 1) * $p;
$t .= 0.01;
If you want to display the discounted subtotal in a
way that doesn't correspond to a standard Interchange tag then
you can use the [calc] tag.
(well, [item-calc] in this example):
Discounted subtotal for [item-code]: [item-filter currency][item-calc]
[item-discount noformat=1] * [item-quantity]
Here is a slightly more complicated example that gives a 10% discount
if a product is ordered with a quantity of two or more,
with a further 5% discount for each additional item,
up to a maximum discount of 30% per SKU code.
return $s if $q == 1;
return $s * .70 if $q > 6;
return $s * (1 - (0.05 * $q));
The product SKU code or one of either ALL_ITEMS or
Select the discount namespace to use when
DiscountSpacesOn mode is in operation.
The default discount namespace is "main".
Also see the [discount-space] tag
and the DiscountSpaceVar local
This parameter was introduced in version 5.4.0,
and is therefore not available for use with any earlier Interchange version.