1

I added multiple products in the cart using this below script.

<script>
    require(['jquery'], function (jquery) {
        document.getElementById("add").addEventListener("click", function () {

            //JipeJryj6w9kBpBD13fTZWz7qm0vinmg
            if (localStorage.getItem('gT') !== null) {
                guestToken = localStorage.getItem('gT');
            }
            console.log(guestToken);
            var qty = document.getElementById('<?php echo "qty".(string)$count; ?>').value;
            if (qty == 0) {
                qty = NULL;
            }

            var settings = {
                "async": true,
                "crossDomain": true,
                "url": "<?php echo $baseUrl ?>rest/V1/carts/mine/items",
                "method": "POST",
                "headers": {
                    "content-type": "application/json",
                    "authorization": "Bearer <?php echo $block->getToken() ?>",
                    "cache-control": "no-cache",
                    "postman-token": "fdf04024-bb48-15e6-77c1-22a9ba841f4d"
                },
                "processData": false,
                "data": JSON.stringify({

                    "cartItem": {
                        "sku": <?php echo $stringSku ?>,
                        "qty": qty,
                        "quote_id": guestToken
                    }

                }),


            }

            jquery.ajax(settings).done(function (response) {
                console.log(response);
            });

        })
    });

This function works fine. But my minicart looks likes this below screenshot.

enter image description here

But when I add products using default method the cart looks fine.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.