Shopping Cart

Shopping cart functionality is built-in, including persistence of the cart’s items to HTML5 localstorage. Beyond this, the pio.js API includes functions built to make interacting with the cart simple:

  • PIO.getCart() function returns an object that includes the items’ information such as productId, templateName, sku, and more.
  • PIO.getNumItems() function is sugar for PIO.getCart().items.length to enable easy UI that shows the number of items in the cart.
  • PIO.clearCart() allows one to clear all items out of the cart.
  • The fns.onCartChange callback (that can be passed into either PIO.config() or PIO.open() options objects) will be called with every cart/item change. Its an easy way to trigger logic/UI updates when items change.