Solved

Don't clear the entire cart after paying a draft order invoice

SachaC
Tourist
3 1 1

We're creating an experience for a client wherein the customer pays for items from different vendors separately.

The customer adds products to their cart where they are grouped by vendor.

On the cart page, they click a checkout button for a given vendor, which fires a request to our integration that uses the API to create a draft order with that vendor's items, then redirects the customer to the invoice page.

The customer then completes the order for that vendor's items.

The problem we're facing is that when the customer completes the order, the entire cart is cleared – including the items they have not yet paid for.

Before we implement a workaround we have in mind, is there a way to prevent this functionality?

Accepted Solution (1)
SachaC
Tourist
3 1 1

This is an accepted solution.

Hi @alex_gonor 

No source, unfortunately, we just realised when testing the implementation.

I haven't seen anything noted in a changelog, either, and we're almost certain we tested it a couple of months prior to starting the work.

Luckily, the client's store is on Shopify Plus, so our workaround is basically:

  • store the entire cart in localstorage
  • when checking out, including a script in checkout.liquid when:

 

 

window.Shopify.Checkout.page === 'thank_you'​

 

 

  • use the Cart Ajax API to re-add the products from the cart, except the ones that the customer has just purchased

It's not ideal, but it works.

One thing that we noticed is that, sometimes, the ajax request would be fired too soon - that is, before Shopify had actually cleared the cart. We added a 2s delay after the "thank you" page has loaded to send the request which covers this.

Hope that helps.

Edit: I'm going to accept this message as a solution to the question, as it appears that there has been a change, but the above is a working workaround (providing it's a Plus store and you can edit the checkout.liquid file).

View solution in original post

Replies 2 (2)

alex_gonor
Shopify Partner
9 0 0

Helo @SachaC can you please give me the source where did you get the information that the shopping cart is being cleaned by Shopify. Because I also see that the cart is now being emptied, but this was not the case before, and can't find any changelogs about this update

SachaC
Tourist
3 1 1

This is an accepted solution.

Hi @alex_gonor 

No source, unfortunately, we just realised when testing the implementation.

I haven't seen anything noted in a changelog, either, and we're almost certain we tested it a couple of months prior to starting the work.

Luckily, the client's store is on Shopify Plus, so our workaround is basically:

  • store the entire cart in localstorage
  • when checking out, including a script in checkout.liquid when:

 

 

window.Shopify.Checkout.page === 'thank_you'​

 

 

  • use the Cart Ajax API to re-add the products from the cart, except the ones that the customer has just purchased

It's not ideal, but it works.

One thing that we noticed is that, sometimes, the ajax request would be fired too soon - that is, before Shopify had actually cleared the cart. We added a 2s delay after the "thank you" page has loaded to send the request which covers this.

Hope that helps.

Edit: I'm going to accept this message as a solution to the question, as it appears that there has been a change, but the above is a working workaround (providing it's a Plus store and you can edit the checkout.liquid file).