Example of a 'variable option' that depends on a quantity of
items with a single (aka the same) Product ID number regardless of the
options selected for the items within a customer's checkout basket / cart.
The token %%prodID-*%% is a wildcard, the modifier * means match
all products with this same product ID no matter what the options or modifier are.
If combined with the modifier style variable options then this discounting will match up with
all cart contents when these products and any combination of options are added to the cart.
You can enter default numbers in the new QTY boxes by adding the default number after the comma, see
the autographed option below for an example.
add-to-cart-opt-005 {
# enable variable option code unconditionally
# first thing below is the option file name ( for this example it is: sample_var_opt_qty_disc.html ).
# next is the agorascript identifier to run, must be a unique variable option number used by
# the product ID ( this example uses: variable-option-005 )
$item_user1 .= 'sample_var_opt_qty_with_options.html,variable-option-005;';}
-->
add-to-cart-opt-006 {
# enable variable option code unconditionally
# first thing below is the option file name ( for this example it is: sample_var_opt_qty_disc.html ).
# next is the agorascript identifier to run, must be a unique variable option number used by
# the product ID ( this example uses: variable-option-006 )
$item_user1 .= 'sample_var_opt_qty_with_options.html,variable-option-006;';}
-->
--cut here--
Quantity
Discount
20+
20%
10-19
15%
5-9
10%
3-4
5%
# this needs to be inside the cut-here tags to be run!
$suppress_qty_box = 'yes'; # we make our own boxes
return '';
-->
Available Options:
%%QtyBox-notsigned,%%
%%QtyBox-autographed,3%%
--cut here--
Below is the agorascript run that controls the discounts and option values:
variable-option-005 {
local ( $qty ) = $cart_row[$cart{'quantity'}];
local ( $price ) = $cart_row[$cart{'price'}]; # price or price_after_options
local ( $myopt ) = q{};
undef( $cart_row_options{'005'} );
if ( $var_opt_action eq 'reset' ) {
# So that cart sorting can take place, reset the name
# MUST BE exactly the same name as the hidden var above
$myopt = 'Var005';
}
else {
# For the calc function, we have the cart copy loaded, find qty
# for all products with same id, not just those of this opt #
# or those with the same options (sort of a mix n match).
$qty = 0;
local ( $xqty,$xpid,$junk );
foreach $inx ( keys( %cart_copy ) ) {
( $xqty,$xpid,$junk ) = split( /\|/,$cart_copy{$inx},3 );
if ( $xpid eq $cart_row[$cart{'product_id'}] ) { $qty = $qty + $xqty; }
}
# change the measured quantities, the discount percentage text and the decimal values for each of your discounts
if ( $qty > 19 ) {$myopt = '20% Qty Discount|' . format_price( (-0.20) * $price ) . ' each'; }
elsif ( $qty > 9 ) {$myopt = '15% Qty Discount|' . format_price( (-0.15) * $price ) . ' each'; }
elsif ( $qty > 4 ) {$myopt = '10% Qty Discount|' . format_price( (-0.10) * $price ) . ' each'; }
elsif ( $qty > 2 ) {$myopt = ' 5% Qty Discount|' . format_price( (-0.05) * $price ) . ' each'; }
}
if ( $myopt ) { $cart_row_options{'005'} = $myopt; }
} -->
variable-option-006 {
local ( $qty ) = $cart_row[$cart{'quantity'}];
local ( $price ) = $cart_row[$cart{'price_after_options'}]; # price or price_after_options
local ( $myopt ) = q{};
undef( $cart_row_options{'006'} );
if ( $var_opt_action eq 'reset' ) {
# So that cart sorting can take place, reset the name
# MUST BE exactly the same name as the hidden var above
$myopt = 'Var006';
}
else {
# For the calc function, we have the cart copy loaded, find qty
# for all products with same id, not just those of this opt #
# or those with the same options (sort of a mix n match).
$qty = 0;
local ( $xqty,$xpid,$junk );
foreach $inx ( keys( %cart_copy ) ) {
( $xqty,$xpid,$junk ) = split( /\|/,$cart_copy{$inx},3 );
if ( $xpid eq $cart_row[$cart{'product_id'}] ) { $qty = $qty + $xqty; }
}
# change the measured quantities, the discount percentage text and the decimal values for each of your discounts
if ( $qty > 19 ) {$myopt = '20% Qty Discount|' . format_price( (-0.20)*$price ) . ' each'; }
elsif ( $qty > 9 ) {$myopt = '15% Qty Discount|' . format_price( (-0.15)*$price ) . ' each'; }
elsif ( $qty > 4 ) {$myopt = '10% Qty Discount|' . format_price( (-0.10)*$price ) . ' each'; }
elsif ( $qty > 2 ) {$myopt = ' 5% Qty Discount|' . format_price( (-0.05)*$price ) . ' each'; }
}
if ( $myopt ) { $cart_row_options{'006'} = $myopt; }
} -->