Size Sample Discounts on Item Regardless of any Selected Options

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. 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_disc.html,variable-option-005;';} -->

### --cut here--

Quantity | Discount
--- | ---
100+ | 20%
50-99 | 15%
25-49 | 10%
10-24 | 5%

### --cut here--

Below is the agorascript run that controls the option values:
variable-option-005 { local ( $qty ) = $cart_row[$cart{'quantity'}]; local ( $price ) = $cart_row[$cart{'price'}]; 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; } } if ( $qty > 99 ) {$myopt = '20% Qty Discount|' . format_price( (-0.20) * $price ) . ' each'; } elsif ( $qty > 49 ) {$myopt = '15% Qty Discount|' . format_price( (-0.15) * $price ) . ' each'; } elsif ( $qty > 24 ) {$myopt = '10% Qty Discount|' . format_price( (-0.10) * $price ) . ' each'; } elsif ( $qty > 9 ) {$myopt = ' 5% Qty Discount|' . format_price( (-0.05) * $price ) . ' each'; } } if ( $myopt ) { $cart_row_options{'005'} = $myopt; } } -->