{% put scripts %}

<script>
    $('#loader_add').hide();
    function addToCartq(prodId, qty) {

        $(document).on('ajaxSetup', function (event, context) {
            var product = {};
            product.product_id = prodId;
            product.quantity = qty;

            console.log(String('Bearer {{token}}'));
            console.log(prodId);
            console.log(qty);
            console.log(JSON.stringify(product));

            $.ajax({
                async: true,
                url: 'https://nurgul.com.tm/app/api/customer/cart/add/' + String(prodId),
                type: 'POST',
                headers: { Authorization: 'Bearer {{token}}' },
                processData: false,
                contentType: false,
                data: JSON.stringify(product),
                dataType: 'json',
                success: function (data) {
                    console.log(data);

                    oc.flashMsg({
                        message: "{{'added.cart.success'|_}}",
                        type: 'success',
                        interval: 3
                    });
                },
                error: function (data) {
                    console.log(data);
                }
            });
        })
        // var fd = new FormData();
        // fd.append('phone', phone);


    }

</script>

{% endput %}
