osCommerce Big Chooser
A discounting module for osCommerce 2.2 and 2.3 that allows you to discount products if certain conditions are met.Background: See the osCommerce Matrix-o-discounts
Example Discounts: I have provided several examples of osCommerce Big Chooser discounts.
Relevance: osCommerce 2.2, 2.3
Current Version: 1.2.11. Occasionally, new features are documented prior to being publicly available; please check the version history to ensure the feature you want is available in your version.
Support Thread: My commercial software is not supported on the osCommerce forum. Please email me questions instead.
Cost: $60 (Note: this low price covers software only for self-installation.)
Would you like to ask me questions before buying? I'm happy to help likely purchasers make the right decision. Please use my contact form.
Installed Cost: $120.00 (Professional installation by That Software Guy.) Note that this does not include payment gateway integration - see above. Please test my free software first (Better Together or Quantity Discounts) to ensure that this will work with your payment gateway.
Installation Difficulty: Moderate (You must write some PHP to configure this mod; there is no Admin panel)
Installation Instructions: click here
Payment Gateway Integration Note that some payment modules, including PayPal, do not natively work with Order Total discounts (mine or anyone else's).
Here are some suggestions on how to fix this:
osCommerce 2.2 osCommerce 2.3 Note that doing these integrations is your responsibility. You can try doing this before purchase by testing my Better Together or Quantity Discounts modules, both of which are free.
Buy: Buy Table Discounts!
Pre-purchase questions? No problem! Just Please contact me with your question.
Promotional Page Download: The Big Chooser promotional page is a free download from my website. You must buy Big Chooser separately.
BC Promo Page for osC 2.2 BC Promo Page for osC 2.3.x.
Add-Ons: Discount Preview allows you to show the discounts from Big Chooser in your cart. It's is a free download.
FAQ: click here
Marketing Text: click here
Bugs: click here
Overview:
My Big Spender Extension allows you to discount products in various ways under various conditions provided a certain dollar threshold is exceeded. Big Chooser takes a similar approach, but rather than setting a dollar threshold, it becomes activated when a specific set of items are placed into the cart.Big Chooser is configured by creating "conditions" and then parameterizing these conditions, specifying how the decision is made as to whether the condition is met, and the discounts available once the condition is met.
Big Chooser requires you to add these conditions and parameters to the module itself - they are not configured through the admin panel. This sounds complicated, but it's not that bad, and many examples of common discounting practices are provided. Please note that Big Chooser only provides a discount; it does not automatically add items to the cart.
The calling conventions for building a condition are as follows:
{ text description, whether to apply the behavior multiple times }
So suppose the discount was stated as, "After items A and B are added to the cart, take some action." This would be
$this->add_condition("Buy items A and B, and get ...", false);
If the discount was, "For every item A and B in the cart, take some action," the code would be
$this->add_condition("For every A and B you buy, get ...", true);
Now we need to parameterize the condition. Parameter statements apply to the condition statement they immediately follow. I have provided a visual cue for this by indenting the parameter statements on this page by three spaces. The following types of parameter statements are currently supported:
- set_constraint - specifies the items that must be in the cart to meet the condition
- set_choice_constraint - specifies a set of items, some of which must be in the cart to meet the condition
- set_negative_constraint - specifies the items which are excluded from the promotion; they will not be counted towards the condition. (Note that as of osCommerce Big Chooser 1.2.11, it is considered for discounting; prior to that it was not.)
- set_discount - discount some product or category by a specific percentage or currency figure
- set_choice_discount - discount a specified number of items from some product or category by a specific percentage or currency figure
- set_cart_discount - discount the entire cart by a specific percentage or currency figure
- set_support - provide additional information on the discount
- set_deal_id - giving the discount an identifying number to allow other discounts to be filtered out if this number has been run
- set_no_double_dip - specifying which discounts which, if executed, will cause this discount to be skipped
- include_condition_items - allow items which were used in set_discount or set_choice discount to themselves be discounted
- set_extra_discount, set_extra_choice_discount - used with include_condition_items to specify additional discounts not included in the condition
One of set_discount(), set_choice_discount() or set_cart_discount() must be done for every condition for it to have any action. One of set_constraint() or set_choice_constraint() must be used for every condition to make it conditional (otherwise the discount will be applied universally).
Examples
First, some easy ones:The discount, "Buy product 1, get a free product 5" would be specified as
$this->add_condition("Buy name-of-product-1, get a free name-of-product-5", false); $this->set_constraint(PROD, 1, 1); $this->set_discount(PROD, 5, 1, "%", 100);
The discount, "Buy an item from category 3, get a free product 8" would be specified as
$this->add_condition("Buy an item from name-of-category-3, get a free name-of-product-8", false); $this->set_constraint(CAT, 3, 1); $this->set_discount(PROD, 8, 1, "%", 100);
Now let's look at things you can't do with Better Together.
The discount, "Buy 3 items from category 5, get a fourth one free" would be specified as
$this->add_condition("Buy 3 item from name-of-category-5, get a fourth free", false); $this->set_constraint(CAT, 5, 3); $this->set_discount(CAT, 5, 1, "%", 100);
The discount, "Buy 3 items from manufacturer ABC, get a fourth one free" would be specified as
$this->add_condition("Buy 3 item from manufacturer ABC, get a fourth free", false); $this->set_constraint(MANUF, 7, 3); $this->set_discount(MANUF, 7, 1, "%", 100);(assuming the manufacturer id of ABC was 7).
Pay close attention to the phrase you use to promote the discount where the condition and discount refer to the same category or product. For instance, I do not recommend using verbiage like "buy three, get one free" because it's ambiguous. Rather, use "buy three, get a fourth free" or "buy three, get the least expensive one free" to indicate whether the customer will need to pay full price for two or three items. For more suggestions on this, see verbiage.
The discount, "Buy 3 items from category 5, get the least expensive one free" would be specified as
$this->add_condition("Buy 3 items from category-5, get least expensive free", false); $this->set_constraint(CAT, 5, 2); $this->set_discount(CAT, 5, 1, "%", 100);
If you really don't like this phrasing, use the set_support command to emphasize that the discount is applied to the lowest priced item.
$this->add_condition("Pick 3 items from category-5, get one free", false); $this->set_support("Discount applied to lowest priced item"); $this->set_constraint(CAT, 5, 2); $this->set_discount(CAT, 5, 1, "%", 100);
The discount, "Mix and match 3 product 1 and product 2, get a free product 5" would be specified as
$this->add_condition("Mix and match 3 of products 1 and 2, get a free name-of-product-5", false); $this->set_choice_constraint(3, PROD, 1, PROD, 2); $this->set_discount(PROD, 5, 1, "%", 100);
The discount, "Buy 6 items from two categories (21 and 22), get the least expensive one free" would be specified as
$this->add_condition("Buy 6 items from cat-21-or-22, get the lowest price one free", false); $this->set_choice_constraint(5, CAT, 21, CAT, 22); $this->set_choice_discount(1, CAT, 21, "%", 100, CAT, 22, "%", 100);
The discount, "Buy two items from category 3, get your choice of a free product 8, 9 or 10" would be specified as
$this->add_condition("Buy two items from name-of-category-3, get a free name-of-product-8, 9 or 10", false); $this->set_constraint(CAT, 3, 2); $this->set_choice_discount(1, PROD, 8, "%", 100, PROD, 9, "%", 100, PROD, 10, "%", 100);
Conversely, the discount, "Buy any of product 8, 9 or 10, get two items from category 3 free" would be specified as
$this->add_condition("Buy any of 8, 9 or 10, get two items from name-of-category-3 free", false); $this->set_choice_constraint(1, PROD, 8, PROD, 9, PROD, 10); $this->set_discount(CAT, 3, 2, "%", 100);
What if instead of category 3, you wanted to provide a discount for spending on certain types of products which were spread across categories. We'll call this product class "open stock cookware," and assume that it is made up of product ids 1, 3, 5, 11, 13, 19, 37, and 41. We'll only allow this discount to be offered once per order.
$this->add_condition("Buy 2 items from open stock cookware, select 2 free gifts... ", false); $this->set_choice_constraint(2, PROD, 1, PROD, 3, PROD, 5, PROD, 11, PROD, 13, PROD, 19, PROD, 37, PROD, 41); $this->set_choice_discount(1, PROD, 8, "%", 100, PROD, 9, "%", 100, PROD, 10, "%", 100);
Discounting can be done in currencies as well. To offer $5 off (or 5 of whatever currency your cart uses), instead of 100% off, use
$this->add_condition("Buy 2 items from open stock cookware, select 2 free gifts... ", false); $this->set_choice_constraint(2, PROD, 1, PROD, 3, PROD, 5, PROD, 11, PROD, 13, PROD, 19, PROD, 37, PROD, 41); $this->set_choice_discount(1, PROD, 8, "$", 5, PROD, 9, "$", 5, PROD, 10, "$", 5);
(The "$" is just used to specify currency; your cart's currency settings will be respected when computing the discount.)
The discount, "Buy product 12, get 20% off one item priced at $100 or more" would be specified as
$this->add_condition("Buy name-of-product-12, get 20% off one item $100 or more", false); $this->set_constraint(PROD, 12, 1); $this->set_discount(MINPRICE, 100, 1, "%", 20);
In some discounting plans, you want to discount both items. You can do this with Big Chooser as follows:
$this->add_condition("Buy a movie and hardware item, get 10% off both", true); $this->set_constraint(CAT, 3, 1, CAT, 1, 1); $this->set_discount(CAT, 1, 1, "%", 10, CAT, 3, 1, "%", 10); $this->include_condition_items();
Sometimes you may wish to tier your discounts
$this->add_condition("Buy 5 category 1, get five free product 20", false); $this->set_constraint(CAT, 1, 5); $this->set_discount(PROD, 20, 5, "%", 100); $this->add_condition("Buy 2 category 1, get one free product 20", false); $this->set_constraint(CAT, 1, 2); $this->set_discount(PROD, 20, 1, "%", 100);
Or, you may offer two ways of getting the same discount:
$this->add_condition("Buy 5 category 1, get a free product 20", false); $this->set_constraint(CAT, 1, 5); $this->set_discount(PROD, 20, 1, "%", 100); $this->add_condition("Buy 2 category 7, get a free product 20", false); $this->set_constraint(CAT, 7, 2); $this->set_discount(PROD, 20, 1, "%", 100);
If you want these discounts to both be valid on a single order, that's fine - but if you wish to make them exclusive (only one free product 20), more steps are required. Big Chooser does not know that these are related, so this would allow someone buying 5 category 1 items and 2 category 7 to get 2 product 20 items free. To indicate that discounts are exclusive, use set_deal_id() and set_no_double_dip().
$this->add_condition("Buy 5 category 1, get a free product 20", false); $this->set_support("Limit one free product 20 per order"); $this->set_constraint(CAT, 1, 5); $this->set_deal_id(1); $this->set_discount(PROD, 20, 1, "%", 100); $this->add_condition("Buy 2 category 7, get a free product 20", false); $this->set_support("Limit one free product 20 per order"); $this->set_no_double_dip(1); $this->set_constraint(CAT, 7, 2); $this->set_discount(PROD, 20, 1, "%", 100);Note that when this is done, the highest discount should be specified first; otherwise, a lower discount will block a higher discount.
A set_no_double_dip() on the first condition and a set_deal_id() on the last are not required but may be specified; the above block is identical to this:
$this->add_condition("Buy 5 category 1, get a free product 20", false); $this->set_constraint(CAT, 1, 5); $this->set_deal_id(1); $this->set_no_double_dip(2); $this->set_discount(PROD, 20, 1, "%", 100); $this->add_condition("Buy 2 category 7, get a free product 20", false); $this->set_deal_id(2); $this->set_no_double_dip(1); $this->set_constraint(CAT, 7, 2); $this->set_discount(PROD, 20, 1, "%", 100);
If you want to offer a variant of quantity discount, such as a "buy four, get the least expensive one free" promotion, this can be done as follows:
$this->add_condition("Buy any four items, get the lowest priced one free", true); $this->set_constraint(MINPRICE, 0.01, 3); $this->set_discount(MINPRICE, 0.01, 1, "%", 100);
Another form of tiered quantity discounts involves a full initial price and then lower prices for subsequent items.
$this->add_condition("Buy 1 product 12, get additional ones for $10 off each", true); $this->set_constraint(PROD, 12, 1); $this->set_discount(PROD, 12, 1, "$", 10); $this->set_extra_discount(PROD, 12, '*', "$", 10);
Another type of quantity discount has discounts on all discounted items when certain levels are reached. If you do this and have multiple levels, be sure to put the largest one first.
$this->add_condition("Buy 12 or more product 17, get 20% off", false); $this->include_condition_items(); $this->set_constraint(PROD, 17, 12); $this->set_discount(PROD, 17, 12, "%", 20); $this->set_extra_discount(PROD, 17, '*', "%", 20); $this->add_condition("Buy 6 or more product 17, get 10% off", false); $this->include_condition_items(); $this->set_constraint(PROD, 17, 6); $this->set_discount(PROD, 17, 6, "%", 10); $this->set_extra_discount(PROD, 17, '*', "%", 10);Yes, this syntax is a bit wacky, and probably not what you expected. You can read more about doing discounts like this in the section Discounting the items that create the condition below.
You can discount the entire cart based on the purchase of specific items:
$this->add_condition("Buy 3 item from name-of-category-5, get 20% off your entire order", false); $this->set_constraint(CAT, 5, 3); $this->set_cart_discount("%", 20);
Or you can discount just the constraint:
$this->add_condition("Buy 3 item from name-of-category-5, get off 20% the set of three", false); $this->set_constraint(CAT, 5, 3); $this->set_cart_discount("%", 20, CART_DISCOUNT_CONSTRAINTS_ONLY);
Discounting the items that create the condition
In the normal model for running Big Chooser, a condition specified in add_condition (and enforced through set_constraint, set_choice_constraint, etc.) sets aside the items required to meet the condition. They are not available for discounting. The only items which are discounted are the additional items specified in set_discount and set_choice_discount. However, some shops want to use Big Chooser to create offers where once a condition is met, a discount is applied to the items meeting the condition (and optionally even more items).This can also be done with Big Chooser, but requires more statements.
For instance, the discount, "Mix and match 6 product 10 or 12, get 20% off all 6" would be specified as
$this->add_condition("Buy 6 product 10 or 12, get 20% off all 6", false); $this->include_condition_items(); $this->set_choice_constraint(6, PROD, 10, PROD, 12); $this->set_choice_discount(6, PROD, 10, "%", 20, PROD, 12, "%", 20);
When eliminating items from consideration for further discounting, normally both the items in the set_constraint/set_choice_constraint statements and the items matching the set_discount/set_choice_discount statements are selected. However, in a discount using include_condition_items, because the two groups potentially overlap, only the items matching the constraints are removed. This could potentially result in double discounting if the items in set_discount and set_choice_discount are discounted by a subsequent offer. For this reason, two new statements were added which can be used with include_condition discounts to extend the discount, yet properly remove all discounted items from further discounting. They are "set_extra_discount" and "set_extra_choice_discount".
We'll look at the discount, "Buy 6 or more product 10 or 12, get 20% off the group." At first glance, you would think it would be
// DO NOT DO THIS!! $this->add_condition("Buy 6 or more product 10 or 12, get 20% off the group", false); // WRONG!! $this->include_condition_items(); $this->set_choice_constraint(6, PROD, 10, PROD, 12); $this->set_discount(PROD, 10, '*', "%", 20); // WRONG! $this->set_discount(PROD, 12, '*', "%", 20); // WRONG!
Do this instead; match the constraint with the discount, then specify additional discounts.
$this->add_condition("Buy 6 or more product 10 or 12, get 20% off the group", false); $this->include_condition_items(); $this->set_choice_constraint(6, PROD, 10, PROD, 12); $this->set_choice_discount(6, PROD, 10, "%", 20, PROD, 12, "%", 20); $this->set_extra_discount(PROD, 10, '*', "%", 20); $this->set_extra_discount(PROD, 12, '*', "%", 20);
Sometimes, discounting the items that create the condition is basically Quantity Discounting.
Consider a discounting policy like this:
- Buy 24 or more from Category 6, get 12.5% off the items in Category 6
- Buy 48 or more from Category 6, get 22.5% off the items in Category 6
- Buy 96 or more from Category 6, get 30% off the items in Category 6
- Buy 144 or more from Category 6, get 44% off the items in Category 6
$this->add_condition("Buy 144 or more cat 6, get 44% off all", false); $this->include_condition_items(); $this->set_constraint(CAT, 6, 144); $this->set_discount(CAT, 6, 144, "%", 44); $this->set_extra_discount(CAT, 6, '*', "%", 44); $this->add_condition("Buy 96 or more cat 6, get 30% off all", false); $this->include_condition_items(); $this->set_constraint(CAT, 6, 96); $this->set_discount(CAT, 6, 96, "%", 30); $this->set_extra_discount(CAT, 6, '*', "%", 30); $this->add_condition("Buy 48 or more cat 6, get 22.5% off all", false); $this->include_condition_items(); $this->set_constraint(CAT, 6, 48); $this->set_discount(CAT, 6, 48, "%", 22.5); $this->set_extra_discount(CAT, 6, '*', "%", 22.5); $this->add_condition("Buy 24 or more cat 6, get 12.5% off all", false); $this->include_condition_items(); $this->set_constraint(CAT, 6, 24); $this->set_discount(CAT, 6, 24, "%", 12.5); $this->set_extra_discount(CAT, 6, '*', "%", 12.5);
Note that if you are only doing Quantity Discounting style discounts, please consider Table Discounts as an alternative to Big Chooser.
Discounting without conditions
You can offer a discount with no conditions, which can come in handy if you want to coordinate it with another discount (using set_no_double_dip).$this->add_condition("Get 20% off all mice for club members", true); $this->set_discount(PROD, 3, '*', "%", 20); $this->set_discount(PROD, 26, '*', "%", 20);
Displaying Big Chooser Discounts
These conditions and parameters are not only used in discount calculations; they are also used to create messages which are automatically displayed on the product_info page. Details on how to do this are provided in marketing.Big Chooser is an order total module, so it appears on the Order Confirmation Page of your checkout as a discount (unless Discount Preview is used, which allows the discount to be shown in the cart).
Order Confirmation Page displaying Big Chooser Discount
This is a "buy 3, get the least expensive free" offer.Detailed Description:
Conditions and parameters are specified in the setup() method at the bottom of the file
includes/modules/order_total/ot_big_chooser.php
There is no admin interface; you must modify the file directly.
Any number of these discounts may be offered; discount computation will be done in the following order:
- conditions are calculated in the order in which they are specified in setup()
- For each condition, the set_discount() and set_cart_discount() statements are executed first (in the order they were specified), then the set_choice_discount() statements (in the order they were specified)
- Once an item has been discounted, it is not subject to re-discounting, even if rules would permit it
- Items in the cart are discounted from least expensive to most expensive.
To make these discounts visible on your product info page, follow the directions in marketing below in the installation instructions.
This step will display the message you provided in the add_condition() command:
For every 3 items from open stock cookware, select 2 free gifts ...
The message is displayed to encourage the customer to meet the condition. It is displayed on any item which will contribute to meeting the condition *and* any item which is discounted after meeting the condition.
This step is optional; if you prefer, you can add your own marketing text.
Note that CAT has different semantics in Big Chooser when compared to Better Together. In Better Together, CAT only includes items directly below the specified category (i.e. CAT means "parent category"). In Big Chooser, CAT includes all items below the specified category, whether they are directly below or in subcategories.
Men's Clothing (category 3) | ----> Shirts (category 5) | | | -------> shirt A | shirt B | shirt C ----> Pants (category 6) | | | -------> pants A | pants B | pants C ----> Shoes (category 7) | ---> Dress Shoes (category 12) | | | -------> dress shoes A | dress shoes B | dress shoes C ---> Casual Shoes (category 18) | -------> casual shoes A casual shoes B casual shoes CSpecifying "Men's Clothing" as a category in Big Chooser will include all items in Shirts, Pants and Shoes.
Specifying "Shoes" (CAT 7) as a category will include both dress shoes and casual shoes. This cannot be done in Better Together.
How Discounts are Selected
Big Chooser sorts items by price in descending order, then looks for the constraints from the top going down. Once it has found a match, it looks for the discount from the bottom going up. So if the following items are in your cart,Product ID | Category ID | Price |
---|---|---|
1 | 12 | $4.00 |
5 | 18 | $20.00 |
7 | 12 | $5.00 |
9 | 12 | $10.00 |
Big Chooser sorts them by price like this:
Product ID | Category ID | Price |
---|---|---|
5 | 18 | $20.00 |
9 | 12 | $10.00 |
7 | 12 | $5.00 |
1 | 12 | $4.00 |
It then matches constraints from most expensive items to least (top down), and matches discounts from least expensive items to most (bottom up).
If your discount is
function setup() { $this->add_condition("Buy a category 12 item, get a second free", true); $this->set_constraint(CAT, 12, 1); $this->set_discount(CAT, 12, 1, "%", 100); }then this means that product 9 will be the constraint, and product 1 will be the item which is discounted 100%.
But if your discount is
function setup() { $this->add_condition("Buy a category 12 item, get a category 18 item free", true); $this->set_constraint(CAT, 12, 1); $this->set_discount(CAT, 18, 1, "%", 100); }then this means that product 9 will be the constraint, and product 5 will be the item which is discounted 100%. Since product 5 is more expensive than product 9, this may not be what you want.
The way to prevent this from happening is to use
condition_price_gte
.
This will ensure that the constraint's price is greater than or equal to
the discounted item's price.
function setup() { $this->add_condition("Buy a category 12 item, get a category 18 item free", true); $this->set_constraint(CAT, 12, 1); $this->condition_price_gte(); $this->set_discount(CAT, 18, 1, "%", 100); }As items are used as conditions and discounted items, they are no longer available for subsequent use as conditions or discounted items. So if your cart contents are this:
Quantity | Product ID | Price |
---|---|---|
1 | 5 | $20.00 |
2 | 8 | $10.00 |
1 | 12 | $10.00 |
function setup() { $this->add_condition("Buy one product 5,get a product 8 free", true); $this->set_constraint(PROD, 5, 1); $this->set_discount(PROD, 8, 1, "%", 100); }you will only get one of product 8 for free. The second product 8 has no matching product 5. Discounts are also done "in order" of specification, so if you have,
// DO NOT DO THIS! function setup() { $this->add_condition("Buy one product 5,get a product 8 free", true); $this->set_constraint(PROD, 5, 1); $this->set_discount(PROD, 8, 1, "%", 100); $this->add_condition("Buy two product 5, get a product 8 and product 12 free", true); $this->set_constraint(PROD, 5, 2); $this->set_discount(PROD, 8, 1, "%", 100, PROD, 12, 1, "%", 100); }the first discount will trigger and you will not have two product 5's left. The correct specification would be to put the larger discount on top.
function setup() { $this->add_condition("Buy two product 5, get a product 8 and product 12 free", true); $this->set_constraint(PROD, 5, 2); $this->set_discount(PROD, 8, 1, "%", 100, PROD, 12, 1, "%", 100); $this->add_condition("Buy one product 5,get a product 8 free", true); $this->set_constraint(PROD, 5, 1); $this->set_discount(PROD, 8, 1, "%", 100); }
Installation Instructions:
- Back up everything! Try this in a test environment prior to installing it on a live shop.
- Copy the contents of the unzipped folder to the root directory of your shop.
- Login to Admin and in Modules > Order Total.
- In osCommerce 2.2: You will see 'Big Chooser Discount' listed along with all the other modules available. Click on 'Big Chooser Discount' to highlight the module and click on 'Install'
- In osCommerce 2.3: Click on the "Install Module" button on the upper right. Select the row that says "Big Chooser Discount." Press the "Install Module" button on the right hand side of the screen.
- Ensure that the sort order that you have selected for Big Chooser is not already used by another module. If necessary, change the sort orders of other modules to ensure that Big Chooser displays where you want it, with a unique sort order. Also, if you are using Re-calculate Tax = Standard, be sure the Tax sort order is larger than the Big Chooser sort order.
- Decide on the discounts you wish to use. The easiest way to do this
is to open a shopping cart in another window, and just start adding
discounts to the setup() method of
includes/modules/order_total/ot_big_chooser.php
The discounts are shown on the second step of checkout in "Your Total" under "Big Chooser Discount." - You may wish to use a less silly name than "Big Chooser Discount."
If so, modify the file
includes/languages/english/modules/order_total/ot_big_chooser.php
- If you wish, follow the guidelines in marketing to advertise your discounts.
- Test a transaction and ensure the discount goes all the way through. For PayPal and some other payment methods, you may need to make additional changes, as outlined below in Payment Modules in osCommerce 2.2 and Payment Modules in osCommerce 2.3.
Optional Installation Instructions:
- I highly recommend Discount Preview with all my discounting modules. Without Discount Preview, your customers cannot see the price reductions they are entitled to until the second page of checkout (checkout confirmation). Obviously this is a disadvantage, particularly for new customers who need to go through the additional step of creating an account before they can see this information. Sometimes seeing is believing, so here's a video showing Discount Preview in action.
Notes on Taxes for osCommerce 2.3
If you don't use embedded taxes, and don't have a mix of taxable and tax-free products, and don't have a different rate of tax for shipping, please skip this section.
However, if you any of the above apply to you, please read my Notes on Taxes.
Payment Modules in osCommerce 2.2
Note: This only applies to osCommerce 2.2. For osCommerce 2.3, please click here.Some contributed payment modules in osCommerce 2.2 (such as PayPal) are not naturally aware of the existence of discounts (mine or any other contribution or extension). For this reason, you must ensure any payment module you use takes discounts into account. Here are some guidelines:
- If the payment module passes in a subtotal, shipping and tax, modify the subtotal (as shown below) to include the discount.
- If the payment module passes in a shipping, tax, and total, modify the total (as shown below) to include the discount.
- In the case of PayPal, turn OFF the sending of line item details, which will confuse PayPal since the total is not the sum of the line items. This can be done through the admin panel by setting Transaction Type to "Aggregate."
paypal_ipn.php
):
foreach ($order_totals as $ot) { $order_total[$ot['code']] = $ot['value']; }then the discount is available in the $order_total variable as follows:
Module | Variable Name |
---|---|
Quantity Discounts | $order_total['ot_quantity_discount'] |
Better Together | $order_total['ot_better_together'] |
Big Chooser | $order_total['ot_big_chooser'] |
Big Spender | $order_total['ot_bigspender_discount'] |
Table Discounts | $order_total['ot_table_discounts'] |
Free Gift Chooser | ot_freegift_chooser.php |
So for instance, subtracting the Quantity Discounts discount from a variable called $subtotal would be done as follows:
$subtotal = $subtotal - $order_total['ot_quantity_discounts'];This would be done in process_button() for example.
Another more sophisticated approach would be to execute the order totals and use
ot_total
, which is the final total after discounts.
// BEGIN: Change to use order_totals to get values $order_id = substr($cart_PayPal_IPN_ID, strpos($cart_PayPal_IPN_ID, '-')+1); $ord_totals = array(); $ord_totals_query = tep_db_query("select class, value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' order by sort_order"); while ($totals = tep_db_fetch_array($ord_totals_query)) { $ord_totals[$totals['class']] = $totals['value']; } // END . . . $parameters['business'] = MODULE_PAYMENT_PAYPAL_IPN_ID; // BEGIN : use order_totals['ot_total'] for order total to include all discounts. if ($ord_totals['ot_total'] > 0) { $parameters['amount'] = number_format($ord_totals['ot_total'], $currencies->get_decimal_places($currency)); } else { $parameters['amount'] = number_format($order->info['total'] - $order->info['shipping_cost'] - $order->info['tax'], $currencies->get_decimal_places($currency)); } // END
Payment Modules in osCommerce 2.3
Note: This only applies to osCommerce 2.3. For osCommerce 2.2, please click here.Some contributed payment modules in osCommerce 2.3 (2.3.1-2.3.3.x) are not naturally aware of the existence of discounts (mine or any other contribution or extension). For this reason, you must ensure any payment module you use takes discounts into account.
For some carts, PayPal Website Payments Standard has been changed to accommodate these osC discounts, but in a bizarre way. If you have
Subtotal: $30 Postage: $7.69 Discount: -$12.00 Tax (7%): $1.26 ----------------------------- Total: $26.95PayPal turns this into
Subtotal: $17.16 Tax (7%): $2.10 Shipping: $7.69 ----------------------------- Total: $26.95This is in osC 2.3.3, with no changes made to PayPal. But the final number is correct (and your actual order total figures as shown in osC admin will be correct per the checkout confirmation page).
I have seen this work on some carts and not on others depending on mods and settings; please test your own cart carefully.
PayPal Express in osCommerce 2.3 still has problems with osCommerce discounts. Here is one way to fix it:
In
./ext/modules/payment/paypal/express.php
, right above the block on
line 544-545 that sets the item and tax amounts:
$params['ITEMAMT'] = $items_total; $params['TAXAMT'] = $tax_total;insert the discount computation. Here's an example for Quantity Discounts. Pull in the module and its language file. Then compute the discount and add it in as a line item.
// Add OT require('includes/modules/order_total/ot_quantity_discount.php'); include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_quantity_discount.php'); $discount = new ot_quantity_discount(); if ($discount->check()) { $qd = $discount->calculate_deductions(); if ($qd['total'] > 0) { $amt = $qd['total'] * -1; $params['L_NAME' . $line_item_no] = 'Discount'; $params['L_AMT' . $line_item_no] = $amt; $params['L_NUMBER' . $line_item_no] = 0; $params['L_QTY' . $line_item_no] = 1; $product_tax = 0; $params['L_TAXAMT' . $line_item_no] = $paypal_express->format_raw($product_tax); $items_total += $paypal_express->format_raw($amt); $line_item_no++; } }
For other modules, here are the filenames. The object to be created is the filename without the
.php
suffix.
Module | File Name |
---|---|
Quantity Discounts | ot_quantity_discount.php |
Better Together | ot_better_together.php |
Big Chooser | ot_big_chooser.php |
Big Spender | ot_bigspender_discount.php |
Table Discounts | ot_table_discounts.php |
Free Gift Chooser | ot_freegift_chooser.php |
Verbiage in add_condition
Pay close attention to the phrase you use to promote the discount where the condition and discount refer to the same category or product. For instance, I do not recommend using verbiage like "buy three, get one free" because it's ambiguous. Rather, use "buy three, get a fourth free" or "buy three, get the least expensive one free" to indicate whether the customer will need to pay full price for two or three items.Other phrases you can use to indicate that the discounted item is in addition to the condition items (which are at full price), are
- "get another"
- "get an additional"
- "get an extra"
Marketing
What good is having cross selling and upselling specials if you don't advertise them?Big Chooser Discounts may be automatically displayed in two places: on the product info page, and on a separate promotional page. We'll talk about the product info page first.
Modify catalog/product_info.php, and add this block of code:
<?php require(DIR_FS_CATALOG. 'big_chooser_marketing.php'); ?>The placement of this code is a matter of personal preference; try placing it below the product description and adjust to your tastes. It creates a message on your page that uses the description you provided in the add_condition():
For every 3 items from open stock cookware, select 2 free gifts ...
Only one div block of text will be produced, with the div id bigChooserDiscountPolicy.
The file big_chooser_marketing.php also contains additional print statements which are commented out, but which you may uncomment if desired. These include:
- An indication of whether this product contributes towards reach the condition and/or is discounted after the condition is reached
- The display of additional "supporting" text for the discount that you have added using $this->set_support(). Such text can include links to PDFs, links to products in your cart, links to external pages, or simply descriptive text. This text will be automatically displayed on the Big Chooser Discount promotional page.
Styling this block of text (changing font, color, etc.) is simply a matter of adding to your stylesheet
#bigChooserDiscountPolicy { font-size: 200%; color: #ff0000; }This would give you
For every 3 items from open stock cookware, select 2 free gifts ...
Probably a bit more obnoxious than you would truly want, but you get the idea.
Alternately, you could modify the marketing text template (big_chooser_marketing.php) and put the text into a fieldset:
The approach to marketing text for Big Chooser is similar to the one used in Better Together. It is displayed on product info pages for products which meet the specified conditions, unless that product is constrained out of the discount. So for instance, if you have
$this->add_condition("Buy 5 items of Men's clothing (excl. shoes), get a free product 20", false); $this->set_constraint(CAT, 3, 5); $this->set_discount(PROD, 20, 1, "%", 100);then the marketing text will appear on pages for products in category 3 (and subcategories), and the page for product 20, but not on pages in category 7 (and subcategories). Note that price based constraints are not used to filter out marketing text because the final price of a product may not be known on the product info page.
The other available marketing vehicle is the Big Chooser Discount promotional page. This page is completely optional; it is not included in the Big Chooser zip file, but it is a free download from my website for people who have purchased Big Chooser. It creates a page that displays all discounts and supporting text.
Files
(new) catalog/includes/languages/english/modules/order_total/ot_big_chooser.php (new) catalog/includes/modules/order_total/ot_big_chooser.php (new) catalog/big_chooser_marketing.php
Formal Syntax of Conditions and Parameters
Conditions and Parameters, which are specified in the setup() function of ot_big_chooser.php, are the mechanism for configuring a store's discounts.Conditions
Discounts always begin by specifying a condition. All subsequent parameters (until the next condition) apply to this condition.
$this->add_condition(<description>,<repeatable>);
where:
description | Is a textual description of the discount. This description is not automatically created the way it is in Better Together. it must be added manually. The reason for this is to allow greater flexibility |
repeatable | is a boolean flag indicating whether to apply the discount only one time (false) or as many times as possible (true). |
Parameters - set_constraint
The set_constraint() command specifies the items which must be present in the cart for the condition to be passed.
$this->set_constraint(<required_purchase_quantity 1>[,<required_purchase_quantity 2>,...,<required_purchase_quantity n>]);
where:
required_purchase_quantity | is the string PROD, CAT, PRICE, MINPRICE, or MANUF, followed by an identifier (product or category id, or product price), followed by a quantity
<PROD | CAT | PRICE | MINPRICE | MANUF> <product or category identifier or price> <quantity>
|
Parameters - set_choice_constraint
The set_choice_constraint() command specifies the items which must be present in the cart for the condition to be passed.
$this->set_choice_constraint(<count>,<required_purchase 1>,<required_purchase 2>[,...,<required_purchase n>]);
where:
quantity | is the number of items from this choice the customer must buy; it must be numeric |
required_purchase | is the string PROD, CAT, PRICE, MINPRICE, or MANUF, followed by an identifier (product or category id, or product price)
<PROD | CAT | PRICE | MINPRICE | MANUF> <product or category identifier or price>
|
Note quantities are not specified per choice; the quantity is cumulative for all choices in the constraint.
Parameters - set_negative_constraint
The set_negative_constraint() command specifies the items which are excluded from the promotion; they will not be counted towards the condition.
$this->set_negative_constraint(<ignored_purchase 1>[,<ignored_purchase 2>,...,<ignored_purchase n>]);
where:
ignored_purchase | is the string PROD, CAT, PRICE, MINPRICE or MANUF, followed by an identifier (product or category id, or product price)
<PROD | CAT | PRICE | MINPRICE | MANUF> <product or category identifier or price>
|
Prior to version 1.2.11, Big Chooser's set_negative_constraint command both excluded items from counting towards the condition *and* did not discount these items. This was different from the behavior of set_negative_constraint in Big Spender, which only removes the item from threshold calculation; it does not prohibit it from being discounted.
Parameters - set_discount
The set_discount() command specifies the items or categories whose prices should be reduced if the condition has been met.
$this->set_discount(<discount 1>[,<discount 2>,...,<discount n>]);
where:
discount | is the string PROD, CAT, PRICE, MINPRICE or MANUF, followed by an identifier (product or category id, or product price), followed by a quantity, followed by a percent or dollar sign, followed by an amount
<PROD | CAT | PRICE | MINPRICE | MANUF> <product or category identifier or price> <item count> < "$" | "%" > <discount amount>
The item_count may be specified as "*", meaning "the discount may be taken an unlimited number of times." |
Parameters - set_choice_discount
The set_choice_discount() command specifies that the customer may choose between a series of discounts if the condition has been met.
$this->set_choice_discount(<quantity>,<choice 1>,<choice 2>[,...,<choice n>]);
where:
quantity | is the number of discounts the customer will receive; it must be numeric |
choice | is the string PROD, CAT, PRICE, MINPRICE or MANUF, followed by an identifier (product or category id, or product price), followed by a percent or dollar sign, followed by an amount
<PROD | CAT | PRICE | MINPRICE | MANUF> <product or category identifier or price> < "$" | "%" > <discount amount>
|
Note quantities are not specified per choice; the quantity is cumulative for all choices. For set_choice_discount, the quantity must be numeric (i.e. "*" is not allowed).
Parameters - set_cart_discount
The set_cart_discount() command specifies the reduction in the total cart price that should be done if the condition has been met.
$this->set_cart_discount(<"$"|"%">, <discount_amount>, [discount_application]);
where:
discount_amount | is a percent or dollar sign, followed by an amount |
discount_application | defaults to applying the discount to the final cart total, but can be set to CART_DISCOUNT_CONSTRAINTS_ONLY if you only want to discount the items that met the constraints. This allows you to offer a "package discount" by percentage or dollars off. See more details below. |
Advanced feature: most people want the cart discount to apply to the entire cart, but some people wanted the discount to only apply to the items that met the constraints. For these people, the optional 3rd parameter to set_cart_discount may be added, and set to CART_DISCOUNT_CONSTRAINTS_ONLY.
$this->set_cart_discount("%", 25, CART_DISCOUNT_CONSTRAINTS_ONLY);Doing so will only discount the price of the constraints, not the entire cart. This feature was added in osCommerce Big Chooser 1.2.9.
The easiest way to understand this is with a series of examples. Suppose you have the items in your cart:
product 28: $5 product 29: $10 product 30: $25 ---------------- Subtotal: $40
If you used this offer
$this->add_condition("Buy product 29 and 30, get 10% off your purchase", false); $this->set_constraint(PROD, 29, 1, PROD, 30, 1); $this->set_cart_discount("%", 10);the discount would be 10% of $40, or $4.
If you used this offer
$this->add_condition("Buy product 29 and 30, get 10% off the pair", false); $this->set_constraint(PROD, 29, 1, PROD, 30, 1); $this->set_cart_discount("%", 10, CART_DISCOUNT_CONSTRAINTS_ONLY);the discount would be 10% of $35, or $3.50.
Parameters - set_support
The set_support() command provides additional supporting text to describe your promotion. It is completely optional.
$this->set_support(<text>);
where:
text | is a text string, which can be plain text or a link |
These strings are displayed on your promotional page, and optionally, on your product info page if you follow the guidelines in marketing.
Parameters - set_deal_id
The set_deal_id() command allows you to give a condition and its associated discount an id, to allow later discounts to be filtered out if this discount has been run using set_no_double_dip. This parameter is optional and is only needed for discounts which preclude other discounts.
$this->set_deal_id(<nnnn>);
where:
nnnn | is some number which identifies this condition or group of conditions. |
Parameters - set_no_double_dip
The set_no_double_dip() command allows you to give a specify that if a certain discount has already been run, the current discount should be skipped. This parameter is optional and is only needed for discounts which preclude other discounts.
$this->set_no_double_dip(<nnnn>);
where:
nnnn | is the id which was used in a set_deal_id() command for one or more previous conditions. |
Multiple set_no_double_dip commands may be used as required.
Parameters - include_condition_items
The include_condition_items() command allows you to include items that allowed you to reach the condition in the discount calculation. Normally these items would be excluded.
$this->include_condition_items();
Parameters - set_extra_discount
Advanced usage; only required for discounts which use include_condition_items, where the conditions don't match the discounts.The set_extra_discount command extends the set_discount command when used with include_condition_items(). Normally, in discounts which use include_condition_items(), the discounts should match the conditions (because items are removed from contention for further discounting based on their presence in the condition). The set_extra_discount command allows you to add extra discounts and still have them accounted for properly and not double-discounted.
$this->set_extra_discount(<discount 1>[,<discount 2>,...,<discount n>]);
parameters are as per set_discount.
Parameters - set_extra_choice_discount
Advanced usage; only required for discounts which use include_condition_items, where the conditions don't match the discounts.The set_extra_choice_discount command extends the set_choice_discount command when used with include_condition_items(). Normally, in discounts which use include_condition_items(), the discounts should match the conditions (because items are removed from contention for further discounting based on their presence in the condition). The set_extra_choice_discount command allows you to add extra discounts and still have them accounted for properly and not double-discounted.
$this->set_extra_choice_discount(<quantity>,<choice 1>,<choice 2>[,...,<choice n>]);
parameters are as per set_choice_discount. Note quantities are not specified per choice; the quantity is cumulative for all choices. For set_extra_choice_discount, the quantity must be numeric (i.e. "*" is not allowed).
Parameters - condition_price_gte
The condition_price_gte() command allows you to ensure that the conditions have a price which is greater than or equal to the discounted item(s).
$this->condition_price_gte();
This feature was added in osCommerce Big Chooser 1.2.11.
Major Versions
- Version 1.2.11 -12/01/13 - Added condition_price_gte, added set_negative_constraint changes from Zen Cart Big Chooser 1.2.16 and 1.2.19.
- Version 1.2.10 - 09/21/13 - Update for osCommerce 2.3.3.3.
- Version 1.2.9 - 06/01/12 - Added CART_DISCOUNT_CONSTRAINTS_ONLY.
- Version 1.2.8 - 11/01/11 - Added VAT + bug fixes from Zen Cart Big Chooser 1.2.7 and 1.2.8 .
- Version 1.2.6 - 05/11/10 - Ordered set_choice_constraint by price, instead of by specified order.
- Version 1.2.5 - 05/01/10 - Some PHP5's didn't handle quantities correctly.
- Version 1.2.4 - 11/18/09 - First Release
FAQ
Q: Why is there an Big Chooser in the first place?A: To better facilitate a more powerful model for discounting based on product choices than can be created by modifying Better Together.
Q: Why is the version number of the first release so high?
A: Big Chooser for osCommerce is based on a product of the same name for the Zen Cart platform. The version of this product at the time was 1.2.4, so I started at the same number. This means you get hardened, field tested code in the first release.
Q: Why is doesn't this have the same features as the Zen Cart version?
A: Zen Cart has certain built in features which osCommerce does not, such as groups and coupons. I didn't want to rely on the contributions that provided these features in osCommerce, so I omitted them entirely.
Q: Why do you have to add PHP code to setup()? Why didn't you put this in the Admin panel?
A: Although it's a bit tedious to have to manually code the associations, it maximizes the module's flexibility. If you need help with the setup logic, I will be happy to do it for you for a small fee, but first look at the many examples in this page.
Q: Can I start and stop my Big Chooser discounts on certain dates in the future?
A: Please see Timing Discounts in osCommerce for an explanation of how to do this.
Q: How do I determine a product's id?
A: In the catalog, click on the product to open the product info page. In the address bar of your browser, you see something like
... product_info.php?products_id=24&osCsid=...The products_id = 24 tells you the product's id is 24.
Q: How do I determine a product's category id?
A: In Admin > Catalog, single click on the category you're interested in. In the address bar of your browser, you will see something like
categories.php?cPath=3&cID=11If you were to double click on it, you'd see something like
categories.php?cPath=3_11The category you want to use is "11".
In the same way, in the catalog you can hover over this category in the categories sidebox and see
catalog/index.php?cPath=3_11This re-confirms that the category is "11."
Q: How do I find out the manufacturer id so I can use MANUF?
A: Go to the Manufacturer's sidebox on your catalog home page and select a manufacturer. The resultant URL will look something like this:
catalog/index.php?manufacturers_id=8&osCsid=rhifpa0duotjnoadm4e5is70k0The "manufacturers_id=8" component of this URL indicates that the id for this manufacturer is 8.
Q: I would like my discounts to show up in the shopping cart. Why don't they?
A: The way the Order Total modules work is that they show up at checkout time. However, if you require the discounts to show up in the shopping cart, you may wish to purchase the Discount Preview module for $30.
Alternately, you may indicate that you have a Big Chooser discount policy by displaying a message on the shopping cart page informing the user that Big Chooser discounts will be calculated (and visible) at checkout time. Additionally, changing SUB_TITLE_SUB_TOTAL in the same file to something like 'Sub-Total BEFORE Discount' will emphasize the fact that a discount will be added at checkout time.
Q: How can I present my Big Chooser discounts on the product page?
A: Follow the directions in marketing in the installation instructions for details on the changes that are required.
Q: I like the message on my product page, but I'd like it to have a link in it. The condition for my discount is "two items from hardware," which corresponds to category 1.
A: You can create a link in your message.
$this->add_condition('Buy two items from <a href="index.php?main_page=index&cPath=1">hardware</a>, get two movies free', false);This will show up on your product info page as
'Buy two items from hardware, get two movies free'Be sure to construct your link WITHOUT a osCsid. Do not just copy and paste from your address bar!
Q: What is the difference between MINPRICE and PRICE?
A: PRICE means the price must be exactly equal to the specified value. MINPRICE means the price must be greater than or equal to the specified value. So using MINPRICE in a set_constraint means that only items of this price or greater count in the condition calculation. Using MINPRICE in a set_discount() or set_choice_discount() means that items at the specified price or greater will match the rule.
Q: If I specify multiple conditions with the same discounts, will Big Chooser double discount my products?
A: Each product in the customer's cart will only be discounted once by Big Chooser. Specifying "repeatable" for a condition or an item count greater than 1 for set_discount will discount multiple times only if multiple items exist; it will not cause the same item to be discounted multiple times.
Q: In what order are the discounts evaluated?
A: The conditions are evaluated in the order they are entered, with the set_discount() parameters executed first (in the order they were entered), followed by the set_choice_discounts (in the order they were entered). If repeatable is specified, a discount is run as many times as possible (as long as products are not discounted multiple times). If a condition uses no_double_dip, and other conditions with the specified ids have already been passed and discounted, that condition's discounts will not be run.
All discounts are run unless a discount is precluded because of a set_no_double_dip() command. Items are discounted in the order least expensive to most expensive.
Q: OK, I have the Big Chooser information on my product page, but my customers can't figure out that the discount isn't visible until checkout time
A: Add some explanatory text to the discountPolicy information you created above. This way it will show up every time there is Big Chooser information on a page. Alternately, you may purchase the Discount Preview module, or you may also add text to the shopping cart page to indicate that Big Chooser discounts will show up at checkout time as discussed above.
Q: I operate a multilingual shop. How can I avoid putting my descriptions in ot_big_chooser.php?
A: If you run a multilingual shop, then instead of putting the string in the add_condition() command directly, edit the file
includes/languages/english.php
and put your definitions there as PHP defined strings.
Here's an example:
<?php define('CONDITIONAL_MOVIE_DISCOUNT', "Buy movies A, B and C, get 10% off your total"); ?>Then, in ot_big_chooser.php, do
$this->add_condition(CONDITIONAL_MOVIE_DISCOUNT, false);
Q: How do I put a link in my supporting text?
A: To put an external link, use
$this->set_support('<a href="articles/Sample_PDF.pdf">Sample PDF document</a>');(single quotes around the entire string and double quotes around the href parameter or vice versa.)
For a link to a category (say category 17), use
$this->set_support('Here is our <a href="index.php?main_page=index&cPath=17">hardware</a> category');
For a link to a product (say product 9), use
$this->set_support('Here is our <a href="index.php?main_page=product_info&products_id=9">widget</a> product');
Q: How can I display images? Can I use set_support to display images?
A: Absolutely!
$this->set_support('<img src="images/my_image.jpeg" />');Q: Why is there a set_extra_discount and set_extra_choice_discount?
A: You only need to worry about these commands if you have a discount which uses include_condition_items, and you only have to worry about this if you have a "quantity discount" style offer where the products which helped the customer meet them condition are themselves discounted. If your discount is two for one, buy 2 get 1 free, etc. you don't need to worry about these commands.
Q: All these rules and parameters and combinations make my head hurt. Will you configure this for me?
A: Naturally. Contact me with your requirements for a quote.
I charge a fee of $60 for Big Chooser.
Buy Now.
The fee covers software only; installation is extra if you require help.
The fee covers software only; installation is extra if you require help.