Safari 11 issue with the AJAX cart API

lattice
New Member
3 0 1

Hi,

I'm having trouble with Safari 11 seemingly not storing cart cookie variables upon a fetch request to the following endpoints:

GET /cart.js

POST /cart/add.js

Running the below function in chrome gives me the full set of cookies required for the cart to work:

addToCart(32498730762285,1)

Chrome CookiesChrome Cookies

However in safari (only version 11) I get nothing:

Screen Shot 2020-07-14 at 8.20.20 AM.png

 

This results in shopify getting a different cart any time a user tries to 'add to cart', meaning that the user can't effectively add anything to cart.

 

My fetch requests look like this:

 

async function getCart(){
      const req = await fetch('/cart.js')
      const res = req.json()
      return res
}

async function addToCart(id,quantity){
     const req = await fetch('/cart/add.js',{ 
      method: 'POST', 
      headers: {'Content-Type': 'application/json'}, 
      body: JSON.stringify({ items: [{ quantity:quantity,id:id }] }) 
     })

     const res = req.json()
     return res
}

 

 

dddddddd
New Member
1 0 0

Did you ever solve this? We are running into the same issue.

0 Likes
stine79
New Member
2 0 0

Any chance you found the solution?

We have the same issue. This piece of code works well in edge and chrome but not in safari

<script>
          $(document).on('click','.add_tote_cart',function(){
          $.ajax({
            type: 'POST', 
            url: '/cart/add.js',
            dataType: 'json', 
            data: {id:31938994012238, quantity:1}, //the id is the variant of the free gift 
            success: function(){
                 document.documentElement.dispatchEvent(new CustomEvent('cart:refresh', {
                bubbles: true  //this code is for prestige theme, is to refresh the cart
                   }));       
                  }
               });
            })
</script>
0 Likes