好的,这让我很难过..
我目前有一个系统,购物车检查优惠券表以查看购物者输入的优惠券代码是否对产品有效。
这很好用,但我希望扩展系统,以便将单个代码用于多个产品之一。
这是目前的工作代码:
$coupon = mysql_real_escape_string(htmlentities(strtoupper($_POST['coupon'])));
$coup_qry = mysql_query("select tblcoupon.*, sell_product.product_code,sell_product.id from tblcoupon,sell_product WHERE tblcoupon.code='$coupon' AND sell_product.product_code = tblcoupon.products");
if($numrows = mysql_num_rows($coup_qry) > 0) // check if typed coupon exists in tblcoupon table
{
while($coup_w = mysql_fetch_array($coup_qry))
{
$start_date = $coup_w['start_date'];
$end_date = $coup_w['end_date'];
$start = strtotime($start_date);
$todays_date = date("Y-m-d");
$today = strtotime($todays_date);
$expiration_date = strtotime($end_date);
if($today >= $start && $today <= $expiration_date) // if todays date is > start date
and < end date then execute the below script
{
$coupon_productcode = $coup_w['products']; //product code in the tblcoupon table
$sell_product_productcode = $coup_w['product_code'];
//check if any of the products in the shopping cart match any of the products
foreach ($_SESSION['cart'] as $name => $value)
{
$id = substr($name, 5, (strlen($name)-5));
if($id==$coup_w['id'])
{
$_SESSION['coupon'] = "C$coupon-$id";
if(isset($_SESSION['offer'])) {
unset($_SESSION['offer']);
}
if(isset($_SESSION['error'])) {
unset($_SESSION['error']);
}
$errCoupon = "Coupon code accepted-green";
}
else {
$errCoupon = "Coupon Code is Invalid for this product.";
}
}
}
else if ($today < $start){
$errCoupon = "Coupon Code is not yet active!-red";
}
else if ($today > $expiration_date){
$errCoupon = "Coupon Code has expired!-red";
}
}
}
我需要做的是在tbl_coupon
调用中添加一个新列products2
(这将是一个不同的产品代码),并让 SQL 查询查找行sell_product.product_code = tblcoupon.products OR sell_product.product_code = tblcoupon.products2
然后,我需要检查$_SESSION['cart']
$id
产品是否为有效选项(products
或products2
),但不能同时为两者。优惠券只能用于 2 个选项之一。
任何帮助都会很棒。
如果您需要更多信息,请询问。