Note: By default, Shoprocket works automatically and handles most events & behaviours for you. The below functions are for advanced usage, in cases where you do not want to use our embeds or want to customise the behaviour.
This guide is designed to help you make the most of Shoprocket's software development kit (SDK) for cart management. Below, you'll find the essential functionalities you can leverage to manage Shoprocket within your application.
Table of Contents
- Adding an Item to the Cart
- Rendering an Abandoned Cart
- Updating Quantity of an Item in the Cart
- Removing an Item from the Cart
- Clearing the Cart
- Getting Cart Items
- Working with Session
- Populating the Cart Address
- Toggle the Cart (open/close)
- Set the Currency
- Set the Language
Listening for the Shoprocket Ready Event
Before using the Shoprocket SDK, it's essential to ensure that the SDK is fully loaded and ready to be used. To do this, you need to listen for the
Shoprocket.ready event. Here's an example of how to listen for the event:
Adding an Item to the Cart
To add an item to the cart, you can use the
Rendering an Abandoned Cart
To recover an abandoned cart, utilise the
Updating Quantity of an Item in the Cart
Shoprocket.cart.update method lets you update the quantity of an existing item in the cart.
Removing an Item from the Cart
To remove an item from the cart, you can call the
Clearing the Cart
If you wish to clear all items from the cart, the
Shoprocket.cart.clear method comes in handy.
Getting Cart Items
To retrieve all items in the cart, use the
Working with the Session
You can work with the Shoprocket Session (using local storage) to set & get custom values via
Populating the Cart Address
If you already know your customer's details, you can automatically populate the cart address via
Toggle the Cart (open/close)
You can toggle the cart via the Shoprocket.cart.toggle() method.
You can switch between currencies via the following method:
Note: we detect visitor locale automatically via IP location and set their currency (if currency is enabled in store)
You can switch between languages via the following method:
Note: we detect visitor locale automatically via IP location and set their language (if launguage is enabled in store)