Я новенький PHP. Я создаю сайт электронной коммерции. В корзине. если я попытаюсь добавить в корзину из добавленного товара. модально ничего не отображается. второй его добавлен. модальное отображение успешно. Теперь я хочу отображать модальное окно, когда я нажимаю добавить в корзину из продукта. Общий запас: 15
URL: https://www.bellastudio.pk/new/products.php?p_slug=embroidery-shalwar-dupatta-2
Вот вставка корзины. php Заранее спасибо
PHP
$stmt = $host->prepare("SELECT * FROM productstock INNER JOIN product ON product.p_id = productstock.pid INNER JOIN productsize ON productsize.sid = productstock.size_id WHERE product.p_itemno = :itemno AND productsize.sname = :size");
$stmt->bindValue(':itemno', $itemno);
$stmt->bindValue(':size', $size);
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
if($qty <= $row['stockqty']){
if($qty == 0)
{
echo "<p>Please enter a quantity</p>";
}else
{
$product = array("name" => $name,
"price" => $price,
"item_no" => $itemno,
"qty" => $qty,
"color" => $color,
"size" => $size,
"stockitemno" => $stockitemno,
"sleeves" => $sleeves,
"neck" => $neck,
"stockqty" => $row['stockqty']);
// check if product is already in array - if it is just update quantity
if(count($_SESSION['cart']) > 0)
{
foreach($_SESSION['cart'] as $key => $cart)
{
if(in_array($stockitemno, $cart))
{
$exists = 1;
$check = $_SESSION['cart'][$key]['qty'] + $qty;
// add qty in cart with qty from post together
// then check if the total is equal to or less
// than your stockqty - if yes add qty together‚
if($check <= $_SESSION['cart'][$key]['stockqty']){
$_SESSION['cart'][$key]['qty'] += $qty;
}
break;
}
}
}
foreach($_SESSION['cart'] as $key => $cart)
{
if($_SESSION['cart'][$key]['qty'] >= $_SESSION['cart'][$key]['stockqty'])
{
echo "No More Stock";
}else
{
echo $name . ' (' . $size . ')';
echo "<br />";
echo "<p>was successfully added to your shopping cart</p>";
}
}
// if exists = 1
if($exists !== 1)
{
$_SESSION['cart'][] = $product;
}
}
}
else
{
echo "<p>The Requested quantity for this product is not available.</p>";
}
}
} catch(PDOException $e)
{
echo "Error: " . $e->getMessage();
}
$host = null;
$cart_count = count($_SESSION['cart']);
?>
Ajax
<script type="text/javascript">
$(document).ready(function()
{
function load_cart_data()
{
$.ajax({
url:"asset/includes/fetch_cart1.php",
method:"POST",
success:function(data)
{
$('.cart_details').html(data);
$('.badge1').text(data.total_item);
}
});
}
$(document).on('click','#add_to_cart',function (e) {
var cart_count = $('.navbar-tool-badge').text();
cart_count = parseInt(cart_count);
if($('input[type=radio][name=size]:checked').length == 0)
{
$('.msg').html('Please choose size.');
return false;
} else {
var product_name = $('#hidden-name').val();
var product_price = $('#hidden-price').val();
var product_itemno = $('#itemno').val();
var product_quantity = $('.quantity').val();
var product_color = $('#color').val();
var product_size = $("input[name='size']:checked").val();
var sleeves = $('#sleeves').val();
var neck = $('#neck').val();
e.preventDefault();
$.ajax
({
type: "POST",
url: "asset/includes/insertcart.php",
data:{product_name:product_name, product_price:product_price, product_itemno:product_itemno , product_quantity:product_quantity, product_color:product_color, product_size:product_size, sleeves:sleeves, neck:neck},
cache: false,
success: function(response)
{
load_cart_data();
$("#getCode").html(response);
$("#myModal").modal('show');
// remove cart count
$('.navbar-tool-badge').html(cart_count + 1);
}
});
}
});
$(document).on('click', '.delete', function(){
var item_no = $(this).attr("id");
var cart_count = $('.navbar-tool-badge').text();
cart_count = parseInt(cart_count);
$.ajax({
url:"asset/includes/delete_item.php",
method:"POST",
data:{item_no:item_no},
success:function(data)
{
if(data){
load_cart_data();
$('#cart-popover').popover('hide');
}
// remove cart count
$('.navbar-tool-badge').html(cart_count - 1);
}
})
});
});
</script>