Example #1
0
    /**
     * This function is used to get product   redeem  coupon from db.
     * @param array $arr
     * 
     * 
     * @return string
     */
    function redeemCoupon($arr)
    {
        if (!empty($arr)) {
            $sql_coupon_categories = "SELECT category_id FROM coupon_category_table WHERE coupon_code='" . $arr['coupon_code'] . "'";
            $query_coupon_categories = new Bin_Query();
            if ($rows = $query_coupon_categories->executeQuery($sql_coupon_categories)) {
                foreach ($query_coupon_categories->records as $res) {
                    $category_ids[] = $res['category_id'];
                }
                $default = new Core_CAddCart();
                $cartdata = $default->getCartData();
                if (!empty($cartdata)) {
                    $cartflag = 0;
                    $sucessflag = 0;
                    foreach ($cartdata as $data) {
                        $cart_categoryid = $default->getCategoryIdByProductId($data['product_id']);
                        for ($i1 = 0; $i1 < count($category_ids); $i1++) {
                            if ($category_ids[$i1] == $cart_categoryid) {
                                if ($arr['discount_type'] == 'percent') {
                                    $redeem_price = $data['msrp'] - $data['msrp'] * ($arr['discount_amt'] / 100);
                                } else {
                                    $redeem_price = $data['msrp'] - $arr['discount_amt'];
                                }
                                $update_amt_sql = "UPDATE shopping_cart_products_table SET product_unit_price=" . $redeem_price . " WHERE cart_id=" . $data['cart_id'] . " and product_id='" . $data['product_id'] . "'";
                                $update_coupon_sql = "UPDATE coupon_user_relation_table SET no_of_uses=no_of_uses+1 WHERE coupon_code='" . $arr['coupon_code'] . "' AND user_id=" . $_SESSION['user_id'];
                                $update_amt_query = new Bin_Query();
                                if ($update_amt_query->updateQuery($update_amt_sql)) {
                                    $update_coupon_query = new Bin_Query();
                                    if ($update_coupon_query->updateQuery($update_coupon_sql)) {
                                        $output = '<div class="alert alert-success">
										<button data-dismiss="alert" class="close" type="button">×</button>
										' . Core_CLanguage::_(COUPON_REDEEMED_SUCCESSFULLY) . '
										</div>';
                                    }
                                }
                            }
                            $cartflag = 1;
                        }
                    }
                    if ($cartflag == 0) {
                        return $output = '<div class="alert alert-info">
						<button data-dismiss="alert" class="close" type="button">×</button>
						' . Core_CLanguage::_(NO_CATEGORIES_IN_YOUR_CART_MATCHES_WITH_THE_COUPON_CATEGORIES) . '
						</div>';
                    } else {
                        return $output;
                    }
                }
            } else {
                return $output = '<div class="alert alert-info">
				<button data-dismiss="alert" class="close" type="button">×</button>
				' . Core_CLanguage::_(NO_CATEGORIES_ARE_APPLICABLE_FOR_THE_COUPON) . '
				</div>';
            }
        }
    }