Heys guys. How can I seperate the same product if the product size is not the same? For example I add a product, Nike KD Numbers Size 9 after that I will add a new; Nike KD Numbers Size 11. The cart content will be like this:
Nike KD Numbers
Price
Size: 11
Remove
Nike KD Numbers
Price
Size: 9
Remove
Jquery
//Add to Cart Module
function add_to_cart(product_id, action) {
var quantity = $('#quantity'+product_id).val();
var product_size = $('#product_size').val();
var button = (action === 'Delete') ? $('#add_to_cart'+product_id).html('<i class="fa fa-shopping-cart"></i> Add to cart') :
$('#add_to_cart'+product_id).html('<i class="fa fa-check-square-o"></i> Added');
button,setTimeout(function(){
$.ajax({
type: 'POST',
url: '../pages/class.php',
data: {product_id : product_id, quantity : quantity, product_size : product_size, action : action},
cache: false,
success: function(data) {
console.log(data);
}
})
$('#add_to_cart'+product_id).html('<i class="fa fa-shopping-cart"></i> Add to Cart');
show_cart_count();
show_cart_contents();
show_cart_content_in_cart_page();
show_cart_content_in_checkout_page();
show_cart_total();
},300);
}
Class.php
$product_id = $_POST['product_id'];
$product_size = $_POST['product_size'];
$quantity = $_POST['quantity'];
$action = $_POST['action'];
case 'Add':
if(isset($_SESSION['item_cart'][$product_id]['product_id']) == $product_id && isset($quantity)) {
$_SESSION['item_cart'][$product_id]['product_qty'] += $quantity;
$qty = ($quantity == 1) ? 'quantity' : 'quantities';
} else {
$count = (!isset($_SESSION['item_cart'])) ? 0 : count($_SESSION['item_cart']);
$add_quantity = (isset($quantity)) ? $quantity : 1;
$_SESSION['item_cart'][$product_id] = array(
"product_id"=>$product_id,
"product_qty"=>$add_quantity,
"product_size"=>$product_size,
"product_price"=>$row['product_price'],
"product_name"=>$row['product_name'],
"product_segment"=>$row['segment_id'],
"product_image"=>$row['product_image'],
"product_brand"=>$row['product_brand'],
"product_stocks"=>$row['product_stocks']
);
}
break;
Cart Content