/** * This function is used to validate the coupon * * * * @return string */ function validateCoupon() { if ($_SESSION['user_id'] != '') { $coupon_code = $_POST['coupon_code']; $date = date('Y-m-d'); $sql_coupon_first = "SELECT a.coupon_code,a.coupan_name,a.created_date,a.discount_amt,a.discount_type,a.valid_from,valid_to ,a.min_purchase ,a.no_of_uses,b.user_id,b.no_of_uses FROM coupons_table a , coupon_user_relation_table b WHERE "; $sql_coupon = $sql_coupon_first . " a.coupon_code='" . $coupon_code . "' "; $obj_coupon = new Bin_Query(); $obj_coupon_5 = new Bin_Query(); if ($obj_coupon->executeQuery($sql_coupon)) { $sql_coupon_1 = $sql_coupon . " and a.status=1 "; if ($obj_coupon->executeQuery($sql_coupon_1)) { $sql_coupon_2 = $sql_coupon_1 . " and '" . $date . "' between a.valid_from and a.valid_to "; if ($obj_coupon->executeQuery($sql_coupon_2)) { $sql_coupon_3 = $sql_coupon_2 . " and a.coupon_code=b.coupon_code and b.user_id=" . $_SESSION['user_id'] . " "; if ($obj_coupon->executeQuery($sql_coupon_3)) { $sql_coupon_4 = $sql_coupon_3 . " and a.min_purchase<=" . $_SESSION['total'] . " "; if ($obj_coupon->executeQuery($sql_coupon_4)) { $sql_coupon_5 = $sql_coupon_4 . " and b.no_of_uses < a.no_of_uses "; if ($obj_coupon_5->executeQuery($sql_coupon_5)) { $default = new Core_CAddCart(); return $default->redeemCoupon($obj_coupon_5->records[0]); } else { return $output = '<div class="alert alert-info"> <button data-dismiss="alert" class="close" type="button">×</button> ' . Core_CLanguage::_(SORRY_YOU_HAVE_EXCEEDED_YOUR_COUPON_USING_LIMIT) . ' </div>'; } } else { return $output = '<div class="alert alert-info"> <button data-dismiss="alert" class="close" type="button">×</button> ' . Core_CLanguage::_(SORRY_PURCHASE_AMOUNT_IS_TOO_LOW_TO_USE_YOUR_COUPON) . ' </div>'; } } else { return $output = '<div class="alert alert-info"> <button data-dismiss="alert" class="close" type="button">×</button> ' . Core_CLanguage::_(COUPON_NOT_ELIGBLE_FOR_YOU) . ' </div>'; } } else { return $output = '<div class="alert alert-info"> <button data-dismiss="alert" class="close" type="button">×</button> ' . Core_CLanguage::_(COUPON_CODE_EXPIRED) . ' </div>'; } } else { return $output = '<div class="alert alert-info"> <button data-dismiss="alert" class="close" type="button">×</button> ' . Core_CLanguage::_(COUPON_CODE_IS_NOT_ACTIVE) . ' </div>'; } } else { return $output = '<div class="alert alert-error"> <button data-dismiss="alert" class="close" type="button">×</button> ' . Core_CLanguage::_(INVALID_COUPON_CODE) . ' </div>'; } } else { return $output = '<div class="alert alert-info"> <button data-dismiss="alert" class="close" type="button">×</button> ' . Core_CLanguage::_(PLEASE_LOGIN_TO_USE_YOUR_COUPON) . ' </div>'; } }