Before you dive in
Check ifwindow.tolstoyWidget is already initialized or wait for the tolstoyWidgetReady event before doing anything. This will make sure Tolstoy’s widget is set for action:
Product card click
The “product card” is a component shown on a Swipeable Tolstoy’s mobile layout
It’s possible to subscribe to the components’
onClick event like so:
Subscribe to event tolstoy_product_card_click will appear in your logs.
Callback
Once the event is fired,myCallback will be triggered with the following payload:
Options
By default, subscribing to thetolstoy_product_card_click event prevents the product modal from opening:
If you’d still like the product modal to open, you can pass the following option to
window.tolstoyWidget.subscribe:
Add to cart
The “Add to cart” button is shown in the product modal:
It’s possible to subscribe to button’s
onClick event like so:
Subscribe to event tolstoy_add_to_cart will appear in your logs.
Callback
Once the event is fired,myCallback will be triggered with the following payload:
Report Add to cart Success or Failure
- Success Scenario (product added successfully to the cart)
- Failure/Error Scenario
payload to be sent back within the message, so make sure to spread payload in your message.
🛈 Note 2: The description field is optional. Use it to specify an error like itemSoldOut. If you skip it, you’ll get a general “Error adding to cart” message.
Unsubscribing from an event
If you’d like to stop listening to an event, you can do it like so:myCallback should be the original callback passed to window.tolstoyWidget.subscribe