Dev: Requirements

Before using the JavaScript API, you need to enable the Persistent Cart App Embed.

Enable the App Embed

  1. In Shopify Admin, go to Online Store → Themes
  2. Click Customise on your live theme
  3. Open the App embeds panel
  4. Enable Persistent Cart
  5. Click Save

Once enabled, the helper object becomes available globally:

window.refactor_apps.persistent_cart

If this object is undefined, the App Embed is not active.

Authentication Requirement

In customer-related methods (getCustomerCart, addToCustomerCart, etc.), you need to pass the required customerId parameter:

APIGetCustomerCart(customerId)

In guest-related methods (getGuestCart, updateGuestCart, etc.), the customer should be logged in to process the data:

APIGetGuestCart()

If these conditions are missing, you will receive status: 404. Be ready to handle it

if (window.refactor_apps.persistent_cart) {   
  const guestCartRes = await window.refactor_apps.persistent_cart.getGuestCart()

  if(guestCartRes.status === 401) {
      // user should be logged in!
      return;
  }

  // process the guestCartRes.data
  return; 
}
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us