Timing Your Discounts in Zen Cart Mods
This page describes methods to create begin and/or end dates for discounts when using the following Zen Cart mods:- Better Together for Zen Cart
- Combination Discounts for Zen Cart
- Big Spender for Zen Cart
- Big Chooser for Zen Cart
Setting start and end dates for Better Together Discounts is now built in to the Zen Cart Better Together Admin Panel as well as Zen Cart Combination Discounts Admin Panel.
Background
All four of these modules have a setup() function at the bottom of their implementation files, and the discounts are coded in these files. Since Better Together has the most familiar and concise syntax, I will use it first in of the examples below, and alternate example using other modules.Date Specification
We will use a sortable format (Y-m-d) to specify dates for clarity. In PHP, to create a variable which represents the current day, you would code$today = strtotime(date('Y-m-d'));Other dates will be constructed in a similar way. For instance, if we have a sale which ends on April 1, 2008, we will say
$end_date = strtotime(date('2008-04-01'));
Begin Dates
If we want to start a sale on April 1st, 2008, in Better Together, we can use$today = strtotime(date('Y-m-d')); $start_date = strtotime(date('2008-04-01')); if ($today >= $start_date) { // Buy any item from category 10, get a second identical one free $this->add_twoforone_cat(10); }
Big Spender would be similar, but of course the entire discount must be specified within the brackets:
$today = strtotime(date('Y-m-d')); $start_date = strtotime(date('2008-04-01')); if ($today >= $start_date) { $this->add_threshold(20, 'Spend over $20 on Acme products, get a free gift', false); $this->set_support('Free gift choices are from category 439'); $this->set_constraint(CAT, 264); $this->set_choice_discount(1, CAT,439,"%",100); }
End Dates
If we want to end a sale on March 31st, 2008, in Better Together, we can use$today = strtotime(date('Y-m-d')); $end_date = strtotime(date('2008-03-31')); if ($today <= $end_date) { // Buy any item from category 10, get a second identical one free $this->add_twoforone_cat(10); }
Big Chooser would be similar, but of course the entire discount must be specified within the brackets:
$today = strtotime(date('Y-m-d')); $end_date = strtotime(date('2008-03-31')); if ($today <= $end_date) { $this->add_condition('Buy any 2 items, get the 3rd free', true); $this->set_constraint(MINPRICE, 0.01, 2); $this->set_discount(MINPRICE, 0.01, 1, "%", 100); }
Begin and End Dates
If we want to start a sale on March 1st, 2008 and end it on March 31st, 2008, in Better Together, we can use$today = strtotime(date('Y-m-d')); $start_date = strtotime(date('2008-03-01')); $end_date = strtotime(date('2008-03-31')); if ($today >= $start_date && $today <= $end_date) { // Buy any item from category 10, get a second identical one free $this->add_twoforone_cat(10); }
Combination Discounts would be similar:
$today = strtotime(date('Y-m-d')); $start_date = strtotime(date('2008-03-01')); $end_date = strtotime(date('2008-03-31')); if ($today >= $start_date && $today <= $end_date) { // Buy 2 product 83, get one free $this->add_linkage(PROD,83,2,PROD,83,1,"%", 100); }
Days of the Week
Here's how to run a Better Together sale on Tuesdays:$today = date('D'); if ($today == 'Tues') { // Buy any item from category 10, get a second identical one free $this->add_twoforone_cat(10); }
Date and Time
If we want to start a sale on December 22, 2012 at 4:00 PM, in Better Together, we can use$now = strtotime(date('Y-m-d H:i')); $start_time = strtotime(date('2013-12-22 16:00')); if ($now >= $start_time) { // Buy any item from category 10, get a second identical one free $this->add_twoforone_cat(10); }
Day of Week and Time
Here's how to run a Better Together sale on Monday from 5-10PM:$today = date('D'); $time = date("H:i"); if ($today == 'Mon' && $time >= "17:00" && $time <= "22:00") { // Buy any item from category 10, get a second identical one free $this->add_twoforone_cat(10); }