Example #1
0
function ajax_add_cart()
{
    $productID = 0;
    $price = 0;
    $discount = 0;
    $cart_item = get_cart_item_array();
    if (isset($_POST['productID'])) {
        $productID = $_POST['productID'];
        //$soluong=get_post_meta($productID, 'so_luong', true);
        $number = 1;
        //$time		= get_post_meta($productID, 'thoi_gian_khuyen_mai', true);
        $now = date('F j, Y');
        $price = get_field('product_price', $productID);
    }
    $cart_item['productID'] = $productID;
    $callcheckbox = get_field('call_checkbox', $productID);
    if (!empty($callcheckbox)) {
        $cart_item['price'] = 'Call';
    } else {
        $cart_item['price'] = $price;
    }
    $cart_item['quanlity'] = $number;
    $cart_item['discount'] = $discount;
    $cart_item['subtotal'] = get_subtotal($cart_item);
    if (product_exists($productID)) {
        echo 'Sản phẩm này đã có trong giỏ hàng';
    } else {
        if (!add_cart_to_session($cart_item)) {
            echo 'Không thể bỏ vào giỏ hàng! Vui lòng liên hệ quản trị website: ' . get_option('admin_email');
        } else {
            echo get_count_product();
        }
    }
    die;
}
Example #2
0
function addtocart($pid, $q)
{
    //echo "dsfsdfsfs";
    //session_start();
    if ($pid < 1 or $q < 1) {
        return;
    }
    if (is_array(@$_SESSION['cart'])) {
        if (product_exists($pid)) {
            $index = getcartindex($pid);
            $q = $_SESSION['cart'][$index]['qty'];
            $qupt = $q + 1;
            $_SESSION['cart'][$index]['qty'] = $qupt;
        } else {
            $max = count($_SESSION['cart']);
            $_SESSION['cart'][$max]['productid'] = $pid;
            $_SESSION['cart'][$max]['qty'] = $q;
        }
    } else {
        $_SESSION['cart'] = array();
        $_SESSION['cart'][0]['productid'] = $pid;
        $_SESSION['cart'][0]['qty'] = $q;
    }
    //echo "vffdgxdgfxdg";
    //$ch = 1;
    //if($ch>2)
    //print_r ($_SESSION['cart']);
}
	function addtocart($prodid,$q){
		if($prodid<1 or $q<1) return;
		
		if(is_array($_SESSION['cart'])){
			if(product_exists($prodid)) return;
			$max=count($_SESSION['cart']);
			$_SESSION['cart'][$max]['Prodid']=$prodid;
			$_SESSION['cart'][$max]['Quantity']=$q;
		}
		else{
			$_SESSION['cart']=array();
			$_SESSION['cart'][0]['Prodid']=$prodid;
			$_SESSION['cart'][0]['Quantity']=$q; 
		}
	}
Example #4
0
function addtocart($isbn, $q)
{
    if ($isbn < 1 or $q < 1) {
        return;
    }
    if (is_array($_SESSION['cart'])) {
        if (product_exists($isbn)) {
            return;
        }
        $max = count($_SESSION['cart']);
        $_SESSION['cart'][$max]['productid'] = $isbn;
        $_SESSION['cart'][$max]['qty'] = $q;
    } else {
        $_SESSION['cart'] = array();
        $_SESSION['cart'][0]['productid'] = $isbn;
        $_SESSION['cart'][0]['qty'] = $q;
    }
}
function addtocart($product_id, $quantity)
{
    if ($product_id < 1 or $quantity < 1) {
        return;
    }
    if (is_array($_SESSION['cart'])) {
        if (product_exists($product_id)) {
            return;
        }
        $max = count($_SESSION['cart']);
        $_SESSION['cart'][$max]['product_id'] = $product_id;
        $_SESSION['cart'][$max]['quantity'] = $quantity;
    } else {
        $_SESSION['cart'] = array();
        $_SESSION['cart'][0]['product_id'] = $product_id;
        $_SESSION['cart'][0]['quantity'] = $quantity;
    }
}
function addtocart($pid, $q, $p_note)
{
    if ($pid < 1 or $q < 1) {
        return;
    }
    if (is_array($_SESSION['cart'])) {
        if (product_exists($pid)) {
            return;
        }
        $max = count($_SESSION['cart']);
        $_SESSION['cart'][$max]['productid'] = $pid;
        $_SESSION['cart'][$max]['productnote'] = $p_note;
        $_SESSION['cart'][$max]['qty'] = $q;
    } else {
        $_SESSION['cart'] = array();
        $_SESSION['cart'][0]['productid'] = $pid;
        $_SESSION['cart'][0]['productnote'] = $p_note;
        $_SESSION['cart'][0]['qty'] = $q;
    }
}