Zen Cart custom software development, Zen Cart modules, Zen Cart Expert eCommerce with Zen Cart!

Timing Your Discounts in osCommerce Mods

This page describes methods to create begin and/or end dates for discounts when using the following osCommerce mods:

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);
  }