shipped-suite-shopify-headless-client-sdk
v1.0.0
Published
1. Install shipped-suite-shopify-headless-client-sdk
Downloads
71
Readme
shipped-suite-shopify-headless-client-sdk
- Install shipped-suite-shopify-headless-client-sdk
npm i shipped-suite-shopify-headless-client-sdk
- Add the
div
snippet where you would like the widget to appear in the cart or checkout flow.
<div class="shipped-widget"></div>
- Import the Shipped Controller
import { Controller } from 'shipped-suite-shopify-headless-client-sdk'
- Instantiate the JS SDK
const shippedController = new Controller({
widgetSelector: '.shipped-widget',
})
- Listen and react to
onInit
andonChange
.onInit
is triggered only once when the widget is initialized. When a user opts in or opts out of Shipped Widget, or when the offer changes,onChange
callback is triggered. Your code should provide a handler for this callback, and ensure any necessary processing required by your backend server. For example:
shippedController.onChange(details => {
// Example 'details':
// {
// "isSelected": true,
// "totalFee": "2.23",
// "shippedProducts": []
// }
})
- When the cart changes, for example products are added or removed, product quantity is changed, you need to trigger update method. The widget will update its state and price offer based on the new cart total.
shippedController.update()