Online Store 2.0 & 1.0 events

Theme events are mainly used to communicate with the app's JavaScript at specific times in the template page.

In the official theme, it is already built-in.

For third-party theme developers, the best practice is to build themes according to the following guidelines during template development, so as to be compatible with all app.

caution

The theme event is not applicable in OS2.1. Except for the Checkout page, theme events can be used normally on the Checkout page.

Usage

An event bus will be injected into the window.Shopline object, obtained through window.Shopline.event

// Emit event from theme
window.Shopline.event.emit('eventName', 'foo')

Listen in the app

window.Shopline.event.on('eventName', function (payload) {
...
})

Example: Send the currently selected sku information when sku is switched

class Sku {
...
change(currentSku) {
window.Shopline.event.emit('Product::SkuChange', currentSku)
}
...
}

Event

Standardized events

Product::SkuChanged

trigger timing:
When switching SKU & SKU changes

window.Shopline.event.on('Product::SkuChanged', function (payload) {
const { data } = payload;
//do something
})
DataDescription
type: 'init' | 'change'Timing to trigger this event, init: initialization, change: user switches sku
quantity: numberNumber of products selected (default is 1)
spuSeq: stringSerial number
discount: numberDiscount: 10 means 10%
skuSeq: stringsku serial number
price: numberSales price (constraint: sales price cannot be less than 0)
originPrice: numberOriginal price (crossed out price) (constraint: crossed out price cannot be less than 0)
stock: numberInventory
weight: number | nullWeight
weightUnit: string | nullWeight units: G-gram, KG-kg, LB-lb, OZ-oz: gram, kilogram, pound, ounce, kilogram ->g,kg,lb,oz,zh_kg
available: booleanIs sku available
shelves: booleanIs sku on the shelf
skuAttributeIds: object[]SKU Attribute ID List
imageList: stirng[] | nullImage Link
soldOut: booleanSold out or not
allowOversold: booleanWhether overselling is allowed
imageBeanList: object[]SKU Pictures
id: stringDescription of the location using sku For example: productDetail | ${modalPrefix}${spuSeq}(popup prefix + product)
instances: objectsku selector instance
instances.productImagesProduct Main Image instance
instances.buttonGroupButton group instance
instances.skuDataPoolsku instance
instances.quantityStepperQuantity selector instance

DataReport Reported events

DataReport::ViewContent

Trigger timing:
Triggered when entering product details page or Quick View & Quick Add

window.Shopline.event.on('DataReport::ViewContent', function (payload) {
const { data } = payload;
//do something
})
DsataDescription
content_spu_id: stringspu id
content_sku_id: stringsku id
content_category: stringCurrently null
currency: stringCurrency Symbols
value: stringPrice (price displayed according to actual accuracy)
quantity: numberQuantity Default is: 1
price: stringPrice (price displayed according to actual accuracy)

DataReport::AddToCart

Trigger timing:
Click on the add to cart button

window.Shopline.event.on('DataReport::AddToCart', function (payload) {
const { data } = payload;
//do something
})
data描述
content_spu_id: string商品spu id
content_sku_id: string商品sku id
content_category: stringProduct Category
content_nameProduct Name
currency: stringCurrency Symbols
value: stringPrice (price displayed according to actual accuracy)
quantity: numberNumber of products purchased
price: stringPrice (price displayed according to actual accuracy)

DataReport::InitiateCheckout

Trigger timing
After entering the checkout page

window.Shopline.event.on('DataReport::InitiateCheckout', function (payload)  {
const { data } = payload;
//do something
})
DataDescription
contents: {}[]Product content array
currency: stringCurrency Symbols
value: stringTotal price of the product
quantity: numberTotal number of products

contents

const contents: {
content_spu_id: string;
content_sku_id: string;
content_name: string;
quantity: number;
price: string;
}[]

DataReport::CompleteOrder

Trigger timing:
Click the Complete Order button (includes smart PayPal button credit card button)

DataDescription
contents: {}[]Product content array
currency: stringCurrency Symbols
value: stringTotal price of the product
quantity: numberTotal number of products

contents

const contents: {
content_spu_id: string;
content_sku_id: string;
content_name: string;
quantity: number;
price: string;
}[]

DataReport::Purchase

Trigger timing:
Triggered when the order is completed and payment is successful

DataDescription
contents: {}[]Product content array, example
content_category: string""(Currently empty)
currency: string"TWD" Currency Symbols
value: string"10.00"Total price of the product(quantity * price)
quantity: number2Total number of products(quantity * length)

contents

const contents: {
content_spu_id: string;
content_sku_id: string;
content_name: string;
quantity: number;
price: string;
}[]

example

[
{
"content_spu_id":"16047822502925650484150374",
"content_sku_id":"18047822502926992661010374",
"content_name":"⛄⛄North-Pole-Village-Musical-Ornament-With-Light-And-Motion1",
"quantity":1,
"price":29.99
},
{
"content_spu_id":"16047822502925650484150375",
"content_sku_id":"18047822502926992661010375",
"content_name":"⛄⛄North-Pole-Village-Musical-Ornament-With-Light-And-Motion2",
"quantity":1,
"price":29.99
}
]
Was this article helpful to you?

Error loading component.

Error loading component.