I would like to have an option to allow a coupon for _ALL_ users or just _ONE_ Customer.
However I would like to track if the coupon was used or not.
Also, I would like to use `enabled` to enable/disable a specific coupon in the database.
Here's my table and code:
Code: Select all
CREATE TABLE `coupons` (
`id` int(9) NOT NULL auto_increment,
`name` varchar(50) NOT NULL default '',
`code` varbinary(50) NOT NULL default '',
`type` char(1) NOT NULL default '',
`amount` int(4) NOT NULL default '0',
`exp_date` date NOT NULL,
`enabled` tinyint(4) NOT NULL,
PRIMARY KEY (`id`),
KEY `exp_date` (`exp_date`),
KEY `code` (`code`),
KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=131 ;
Code: Select all
// 0 = Enabled - 1 = Disabled
if ($enabled == "1") {
$name = "Invalid";
$code = "Invalid Coupon";
$type = "d";
$amount = 0.00;
} // I have a lot of chaos going on here...
$todays_date = date("Y-m-d");
$today = strtotime($todays_date);
$expiration_date = strtotime($exp_date);
if ($expiration_date > $today) {
//$valid = "yes"; // The coupon is valid and all is GREAT!
// Apply the coupon code and use it towards the order
} else {
//$valid = "no"; // The coupon has expired
$name = "Invalid";
$code = "Invalid Coupon";
$amount = 0.00;
}
if ($code) {
$query = "SELECT * FROM coupons WHERE code='$code'";
$result = mysql_query($query) or die("There was an error getting the coupon code!" . mysql_error());
$num_rows = mysql_num_rows($result);
}
if ($num_rows > 0) {
$name = mysql_result($result,0,"name");
$code = mysql_result($result,0,"code");
$type = mysql_result($result,0,"type");
$amount = mysql_result($result,0,"amount");
$exp_date = mysql_result($result,0,"exp_date");
} else {
$name = "Invalid";
$code = "Invalid Coupon";
$type = "d";
$amount = 0.00;
$exp_date = "0000-00-00";
}
header("Content-Type: application/xml; charset=UTF-8");
// Start the XML Output
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
echo "<content>\n";
echo "\t<name>$name</name>\n";
echo "\t<code>$code</code>\n";
echo "\t<type>$type</type>\n";
echo "\t<amount>$amount</amount>\n";
echo "\t<exp_date>$exp_date</exp_date>\n";
echo "</content>\n";
?>