function loadCart() {
    $.ajax({
        data: {
            "load_product": 1
        },
        url: "db/Operations.php",
        type: "POST",
        success: function (data) {
            data = $.parseJSON(data);
            console.log("🚀 ~ file: ecom.js ~ line 10 ~ loadCart ~ data", data)
            cart = data['cart'];
            cart_count = data['cart_count'];
            console.log("🚀 ~ file: ecom.js ~ line 12 ~ loadCart ~ cart_count", cart_count)
            $('#cart-table tbody').html(cart);
            $('#cart_count').html(cart_count);
        },
        error: function (data) {
            console.log('Error:', data);
        }
    });
}
$(document).ready(function () {

    loadCart();

    $('.product_items').click(function (e) {
        e.preventDefault();
        var product_id = $(this).data('id');
        var that = $(this);
        $.ajax({
            data: {
                "product_id": product_id
            },
            url: "db/Operations.php",
            type: "POST",
            success: function (data) {
                data = $.parseJSON(data);

                loadCart();

                var cart = data.cart;
                $.each(cart, function (indexInArray, valueOfElement) {
                    if (product_id == indexInArray) {

                        $(that).closest('.cart-action').find('.cart_count').html(valueOfElement);
                    }
                });
            },
            error: function (data) {
                console.log('Error:', data);
            }
        });
    });

    $(document).on('click', '.remove_cart_item', function (e) {
        e.preventDefault();
        var product_id = $(this).data('id');
        if (!confirm('Are you sure to remove the product?')) {
            return false;
        }

        $.ajax({
            data: {
                "remove_cart_item": 1,
                "remove_product_id": product_id
            },
            url: "db/Operations.php",
            type: "POST",
            success: function (data) {
                loadCart();
            },
            error: function (data) {
                console.log('Error:', data);
            }
        });
    });
});