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
- Retrieve an Order
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 Shoprocket.cart.add()
method.
Rendering an Abandoned Cart
To recover an abandoned cart, utilise the Shoprocket.cart.recover
method.
Updating Quantity of an Item in the Cart
The 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 Shoprocket.cart.remove
method.
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 Shoprocket.cart.get
method.
Working with the Session
You can work with the Shoprocket Session (using local storage) to set & get custom values via Shoprocket.session
.
Populating the Cart Address
If you already know your customer's details, you can automatically populate the cart address via Shoprocker.cart.address
.
Toggle the Cart (open/close)
You can toggle the cart via the Shoprocket.cart.toggle() method.
Set Currency
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)
Set Language
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)
Retrieve an Order
You can retrieve the details of an existing order using the order_id, this is ideal if you're using your own custom thank you page, and would like to display conditional content based on order items etc.