@liquidcommerce/elements-sdk 2.6.0-beta.40 → 2.6.0-beta.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -171
- package/dist/index.checkout.esm.js +6799 -6800
- package/dist/index.esm.js +11112 -11109
- package/dist/types/auto-initialize/shared-utils.d.ts +5 -0
- package/dist/types/core/pubsub/interfaces/checkout.interface.d.ts +1 -0
- package/docs/gitbook/actions.md +160 -0
- package/docs/gitbook/address.md +48 -0
- package/docs/gitbook/cart.md +65 -0
- package/docs/gitbook/checkout.md +131 -0
- package/docs/gitbook/events.md +137 -0
- package/docs/gitbook/overview.md +166 -0
- package/docs/gitbook/product.md +64 -0
- package/docs/gitbook/quick-start-guide.md +393 -0
- package/docs/v1/README.md +210 -0
- package/docs/v1/api/actions/address-actions.md +281 -0
- package/docs/v1/api/actions/cart-actions.md +337 -0
- package/docs/v1/api/actions/checkout-actions.md +387 -0
- package/docs/v1/api/actions/product-actions.md +115 -0
- package/docs/v1/api/client.md +482 -0
- package/docs/v1/api/configuration.md +1 -0
- package/docs/v1/api/injection-methods.md +247 -0
- package/docs/v1/api/typescript-types.md +1 -0
- package/docs/v1/api/ui-helpers.md +200 -0
- package/docs/v1/examples/advanced-patterns.md +96 -0
- package/docs/v1/examples/checkout-flow.md +91 -0
- package/docs/v1/examples/custom-theming.md +63 -0
- package/docs/v1/examples/multi-product-page.md +90 -0
- package/docs/v1/examples/simple-product-page.md +89 -0
- package/docs/v1/getting-started/concepts.md +507 -0
- package/docs/v1/getting-started/installation.md +328 -0
- package/docs/v1/getting-started/quick-start.md +405 -0
- package/docs/v1/guides/address-component.md +431 -0
- package/docs/v1/guides/best-practices.md +324 -0
- package/docs/v1/guides/cart-component.md +737 -0
- package/docs/v1/guides/checkout-component.md +672 -0
- package/docs/v1/guides/events.md +191 -0
- package/docs/v1/guides/product-component.md +686 -0
- package/docs/v1/guides/product-list-component.md +598 -0
- package/docs/v1/guides/theming.md +216 -0
- package/docs/v1/integration/angular.md +39 -0
- package/docs/v1/integration/laravel.md +41 -0
- package/docs/v1/integration/nextjs.md +60 -0
- package/docs/v1/integration/proxy-setup.md +89 -0
- package/docs/v1/integration/react.md +64 -0
- package/docs/v1/integration/vanilla-js.md +84 -0
- package/docs/v1/integration/vue.md +34 -0
- package/docs/v1/reference/browser-support.md +35 -0
- package/docs/v1/reference/error-handling.md +70 -0
- package/docs/v1/reference/performance.md +54 -0
- package/docs/v1/reference/troubleshooting.md +64 -0
- package/package.json +1 -1
- package/docs/actions.md +0 -320
- package/docs/address.md +0 -242
- package/docs/browser-support.md +0 -279
- package/docs/cart.md +0 -387
- package/docs/checkout.md +0 -420
- package/docs/configuration.md +0 -1017
- package/docs/events.md +0 -181
- package/docs/product-list.md +0 -311
- package/docs/product.md +0 -250
- package/docs/proxy.md +0 -228
- package/docs/theming.md +0 -682
- package/docs/troubleshooting.md +0 -793
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { IInjectCheckoutParams, IInjectedComponent, ILiquidCommerceElementsDevelopmentConfig } from '@/interfaces/core.interface';
|
|
2
2
|
export declare const SHARED_ATTR: {
|
|
3
3
|
readonly SCRIPT: {
|
|
4
|
+
readonly MAIN: "data-liquid-commerce-elements";
|
|
5
|
+
readonly TOKEN: "data-token";
|
|
6
|
+
readonly ENV: "data-env";
|
|
7
|
+
readonly DEBUG_MODE: "data-debug-mode";
|
|
4
8
|
readonly CHECKOUT_PARAM: "data-checkout-param";
|
|
9
|
+
readonly CHECKOUT_URL: "data-checkout-url";
|
|
5
10
|
};
|
|
6
11
|
readonly ELEMENT: {
|
|
7
12
|
readonly CHECKOUT: "data-lce-checkout";
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Actions
|
|
2
|
+
|
|
3
|
+
Actions let you control Elements programmatically after the SDK initializes. All actions live under `window.elements.actions.*`.
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
```js
|
|
7
|
+
window.addEventListener('lce:actions.client_ready', () => {
|
|
8
|
+
window.elements.actions.cart.openCart();
|
|
9
|
+
});
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Product actions
|
|
13
|
+
- `actions.product.getDetails(identifier)`
|
|
14
|
+
Returns the current loaded product data (price, size, fulfillment, retailer, quantity, images, etc.). The product must already be injected and loaded.
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
const product = window.elements.actions.product.getDetails('00619947000020');
|
|
18
|
+
console.log(product.name, product.price);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Cart actions
|
|
22
|
+
- `actions.cart.openCart()`
|
|
23
|
+
Opens the cart drawer.
|
|
24
|
+
- `actions.cart.closeCart()`
|
|
25
|
+
Closes the cart drawer.
|
|
26
|
+
- `actions.cart.toggleCart()`
|
|
27
|
+
Toggles the cart drawer open/closed.
|
|
28
|
+
- `actions.cart.addProduct(params[], openCart?)`
|
|
29
|
+
Adds one or more products to the cart. If no address is set, the SDK prompts for one and retries automatically.
|
|
30
|
+
- `actions.cart.applyPromoCode(promoCode)`
|
|
31
|
+
Applies a promo code (replaces any existing code).
|
|
32
|
+
- `actions.cart.removePromoCode()`
|
|
33
|
+
Removes the active promo code.
|
|
34
|
+
- `actions.cart.resetCart()`
|
|
35
|
+
Clears all cart items (no undo).
|
|
36
|
+
- `actions.cart.getDetails()`
|
|
37
|
+
Returns current cart data (items, totals, promo, retailers, etc.).
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
await window.elements.actions.cart.addProduct([
|
|
41
|
+
{ identifier: '00619947000020', fulfillmentType: 'shipping', quantity: 1 }
|
|
42
|
+
], true);
|
|
43
|
+
|
|
44
|
+
await window.elements.actions.cart.applyPromoCode('SUMMER20');
|
|
45
|
+
await window.elements.actions.cart.removePromoCode();
|
|
46
|
+
await window.elements.actions.cart.resetCart();
|
|
47
|
+
|
|
48
|
+
const cart = window.elements.actions.cart.getDetails();
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Checkout actions
|
|
52
|
+
- `actions.checkout.openCheckout()`
|
|
53
|
+
Opens the checkout drawer.
|
|
54
|
+
- `actions.checkout.closeCheckout()`
|
|
55
|
+
Closes the checkout drawer.
|
|
56
|
+
- `actions.checkout.toggleCheckout()`
|
|
57
|
+
Toggles the checkout drawer open/closed.
|
|
58
|
+
- `actions.checkout.exitCheckout()`
|
|
59
|
+
Navigates away from checkout (requires `exitUrl` config).
|
|
60
|
+
- `actions.checkout.addProduct(params[], openCheckout?)`
|
|
61
|
+
Adds products directly to checkout (bypasses cart).
|
|
62
|
+
- `actions.checkout.applyPromoCode(promoCode)`
|
|
63
|
+
Applies a promo code in checkout.
|
|
64
|
+
- `actions.checkout.removePromoCode()`
|
|
65
|
+
Removes the active promo code.
|
|
66
|
+
- `actions.checkout.applyGiftCard(code)`
|
|
67
|
+
Applies a gift card.
|
|
68
|
+
- `actions.checkout.removeGiftCard(code)`
|
|
69
|
+
Removes a gift card.
|
|
70
|
+
- `actions.checkout.toggleIsGift(active?)`
|
|
71
|
+
Enables/disables gift mode (or toggles when omitted).
|
|
72
|
+
- `actions.checkout.toggleBillingSameAsShipping(active?)`
|
|
73
|
+
Sets billing address to match shipping.
|
|
74
|
+
- `actions.checkout.toggleMarketingPreferences(field, active)`
|
|
75
|
+
Sets marketing opt-in (`canEmail` or `canSms`).
|
|
76
|
+
- `actions.checkout.updateCustomerInfo(fields)`
|
|
77
|
+
Prefills customer info (name, email, phone, birthdate, etc.).
|
|
78
|
+
- `actions.checkout.updateBillingInfo(fields)`
|
|
79
|
+
Prefills billing address fields.
|
|
80
|
+
- `actions.checkout.updateGiftInfo(fields)`
|
|
81
|
+
Prefills gift recipient information.
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
window.elements.actions.checkout.openCheckout();
|
|
85
|
+
window.elements.actions.checkout.closeCheckout();
|
|
86
|
+
window.elements.actions.checkout.toggleCheckout();
|
|
87
|
+
|
|
88
|
+
await window.elements.actions.checkout.addProduct([
|
|
89
|
+
{ identifier: '00619947000020', fulfillmentType: 'shipping', quantity: 1 }
|
|
90
|
+
], true);
|
|
91
|
+
|
|
92
|
+
await window.elements.actions.checkout.applyPromoCode('WELCOME10');
|
|
93
|
+
await window.elements.actions.checkout.applyGiftCard('GIFT-1234-5678');
|
|
94
|
+
|
|
95
|
+
await window.elements.actions.checkout.toggleIsGift(true);
|
|
96
|
+
await window.elements.actions.checkout.toggleBillingSameAsShipping(false);
|
|
97
|
+
await window.elements.actions.checkout.toggleMarketingPreferences('canEmail', true);
|
|
98
|
+
|
|
99
|
+
window.elements.actions.checkout.updateCustomerInfo({
|
|
100
|
+
firstName: 'John',
|
|
101
|
+
lastName: 'Doe',
|
|
102
|
+
email: 'john@example.com'
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
window.elements.actions.checkout.updateBillingInfo({
|
|
106
|
+
firstName: 'John',
|
|
107
|
+
lastName: 'Doe',
|
|
108
|
+
addressOne: '789 Elm St',
|
|
109
|
+
city: 'Chicago',
|
|
110
|
+
state: 'IL',
|
|
111
|
+
zipCode: '60601'
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
window.elements.actions.checkout.updateGiftInfo({
|
|
115
|
+
firstName: 'Jane',
|
|
116
|
+
lastName: 'Smith',
|
|
117
|
+
message: 'Happy Birthday!'
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Address actions
|
|
122
|
+
- `actions.address.setAddressByPlacesId(placesId)`
|
|
123
|
+
Sets address using a Google Places ID (recommended).
|
|
124
|
+
- `actions.address.setAddressManually(address, coordinates)`
|
|
125
|
+
Sets address with your own address + lat/long data.
|
|
126
|
+
- `actions.address.getDetails()`
|
|
127
|
+
Returns the current address (or null if not set).
|
|
128
|
+
- `actions.address.clear()`
|
|
129
|
+
Removes the stored address and resets availability.
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
await window.elements.actions.address.setAddressByPlacesId('ChIJOwg_06VPwokRYv534QaPC8g');
|
|
133
|
+
|
|
134
|
+
await window.elements.actions.address.setAddressManually(
|
|
135
|
+
{ one: '123 Main Street', city: 'New York', state: 'NY', zip: '10001' },
|
|
136
|
+
{ latitude: 40.7128, longitude: -74.0060 }
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const address = window.elements.actions.address.getDetails();
|
|
140
|
+
await window.elements.actions.address.clear();
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## UI helpers (non-actions)
|
|
144
|
+
These helpers live under `window.elements.ui.*` and are commonly used with actions.
|
|
145
|
+
|
|
146
|
+
- `ui.cartButton(containerId, showItemsCount?)`
|
|
147
|
+
Renders a cart button inside the given container.
|
|
148
|
+
- `ui.floatingCartButton(showItemsCount?)`
|
|
149
|
+
Renders a floating cart button (bottom-right).
|
|
150
|
+
- `ui.cartSubtotal(elementId)`
|
|
151
|
+
Keeps an element updated with cart subtotal.
|
|
152
|
+
- `ui.cartItemsCount(elementId, { hideZero })`
|
|
153
|
+
Keeps an element updated with cart item count.
|
|
154
|
+
|
|
155
|
+
```js
|
|
156
|
+
window.elements.ui.cartButton('header-cart', true);
|
|
157
|
+
window.elements.ui.floatingCartButton(true);
|
|
158
|
+
window.elements.ui.cartSubtotal('cart-total');
|
|
159
|
+
window.elements.ui.cartItemsCount('items-count', { hideZero: true });
|
|
160
|
+
```
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Address
|
|
2
|
+
|
|
3
|
+
The Address component sets the delivery location used for availability, pricing, and fulfillment options.
|
|
4
|
+
|
|
5
|
+
## How it works
|
|
6
|
+
- Address is embedded in the Product component by default
|
|
7
|
+
- If a user adds to cart without an address, the SDK prompts automatically
|
|
8
|
+
- The address is reused across product, cart, and checkout
|
|
9
|
+
|
|
10
|
+
## Standalone address component
|
|
11
|
+
```js
|
|
12
|
+
const client = await Elements('YOUR_API_KEY', { env: 'production' });
|
|
13
|
+
await client.injectAddressElement('address', {
|
|
14
|
+
onAddressSet: (address) => {
|
|
15
|
+
console.log('Address set:', address);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Address actions
|
|
21
|
+
```js
|
|
22
|
+
await window.elements.actions.address.setAddressByPlacesId('ChIJOwg_06VPwokRYv534QaPC8g');
|
|
23
|
+
|
|
24
|
+
await window.elements.actions.address.setAddressManually(
|
|
25
|
+
{
|
|
26
|
+
one: '123 Main Street',
|
|
27
|
+
two: 'Apt 4',
|
|
28
|
+
city: 'New York',
|
|
29
|
+
state: 'NY',
|
|
30
|
+
zip: '10001'
|
|
31
|
+
},
|
|
32
|
+
{ latitude: 40.7128, longitude: -74.0060 }
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const address = window.elements.actions.address.getDetails();
|
|
36
|
+
await window.elements.actions.address.clear();
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Address events (examples)
|
|
40
|
+
```js
|
|
41
|
+
window.addEventListener('lce:actions.address_updated', (event) => {
|
|
42
|
+
const { formattedAddress } = event.detail.data;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
window.addEventListener('lce:actions.address_failed', (event) => {
|
|
46
|
+
const { error } = event.detail.data;
|
|
47
|
+
});
|
|
48
|
+
```
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Cart
|
|
2
|
+
|
|
3
|
+
The Cart component is a slide-out drawer that manages items, quantities, promo codes, and checkout.
|
|
4
|
+
|
|
5
|
+
## What you get
|
|
6
|
+
- Drawer UI with item list and totals
|
|
7
|
+
- Grouped items by retailer
|
|
8
|
+
- Quantity updates and removals
|
|
9
|
+
- Promo code support
|
|
10
|
+
- Cart persistence across sessions and tabs
|
|
11
|
+
- Checkout entry point
|
|
12
|
+
|
|
13
|
+
## Show a cart button (CDN)
|
|
14
|
+
```html
|
|
15
|
+
<script
|
|
16
|
+
defer
|
|
17
|
+
data-liquid-commerce-elements
|
|
18
|
+
data-token="YOUR_API_KEY"
|
|
19
|
+
data-env="production"
|
|
20
|
+
data-cart-badge-button="header-cart"
|
|
21
|
+
type="text/javascript"
|
|
22
|
+
src="https://assets-elements.liquidcommerce.us/all/elements.js"
|
|
23
|
+
></script>
|
|
24
|
+
|
|
25
|
+
<div id="header-cart"></div>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Cart UI helpers (programmatic)
|
|
29
|
+
```js
|
|
30
|
+
window.elements.ui.cartButton('header-cart', true);
|
|
31
|
+
window.elements.ui.floatingCartButton(true);
|
|
32
|
+
window.elements.ui.cartSubtotal('cart-total');
|
|
33
|
+
window.elements.ui.cartItemsCount('items-count', { hideZero: true });
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Cart actions
|
|
37
|
+
```js
|
|
38
|
+
window.elements.actions.cart.openCart();
|
|
39
|
+
window.elements.actions.cart.closeCart();
|
|
40
|
+
window.elements.actions.cart.toggleCart();
|
|
41
|
+
|
|
42
|
+
await window.elements.actions.cart.addProduct([
|
|
43
|
+
{ identifier: '00619947000020', fulfillmentType: 'shipping', quantity: 1 }
|
|
44
|
+
], true);
|
|
45
|
+
|
|
46
|
+
await window.elements.actions.cart.applyPromoCode('SUMMER20');
|
|
47
|
+
await window.elements.actions.cart.removePromoCode();
|
|
48
|
+
await window.elements.actions.cart.resetCart();
|
|
49
|
+
|
|
50
|
+
const cart = window.elements.actions.cart.getDetails();
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Address behavior
|
|
54
|
+
If no address is set, add-to-cart automatically opens the address prompt, then retries the add.
|
|
55
|
+
|
|
56
|
+
## Cart events (examples)
|
|
57
|
+
```js
|
|
58
|
+
window.addEventListener('lce:actions.cart_item_added', (event) => {
|
|
59
|
+
const { identifiers, itemsAdded } = event.detail.data;
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
window.addEventListener('lce:actions.cart_updated', (event) => {
|
|
63
|
+
const { subtotal, itemsCount } = event.detail.data;
|
|
64
|
+
});
|
|
65
|
+
```
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Checkout
|
|
2
|
+
|
|
3
|
+
The Checkout component provides a complete purchase flow with customer info, payment (Stripe), and confirmation.
|
|
4
|
+
|
|
5
|
+
## What you get
|
|
6
|
+
- Customer, billing, and shipping info
|
|
7
|
+
- Gift and marketing preferences
|
|
8
|
+
- Promo codes and gift cards
|
|
9
|
+
- Order summary and totals
|
|
10
|
+
- Hosted checkout or drawer checkout
|
|
11
|
+
|
|
12
|
+
## Default: drawer checkout
|
|
13
|
+
Checkout opens automatically from the cart drawer. No setup required.
|
|
14
|
+
|
|
15
|
+
## Hosted checkout (inject)
|
|
16
|
+
```js
|
|
17
|
+
const client = await Elements('YOUR_API_KEY', { env: 'production' });
|
|
18
|
+
await client.injectCheckoutElement({
|
|
19
|
+
containerId: 'checkout',
|
|
20
|
+
checkoutId: 'optional_checkout_id',
|
|
21
|
+
hideHeader: false
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Hosted checkout (URL param)
|
|
26
|
+
Hosted checkout uses two things together:
|
|
27
|
+
1) `data-checkout-url` on the main script (so the cart can redirect to your hosted checkout page).
|
|
28
|
+
2) `data-checkout-param` on the hosted page (so it can read the checkout ID from the URL).
|
|
29
|
+
|
|
30
|
+
Hosted page example:
|
|
31
|
+
```html
|
|
32
|
+
<script
|
|
33
|
+
defer
|
|
34
|
+
data-liquid-commerce-elements
|
|
35
|
+
data-token="YOUR_API_KEY"
|
|
36
|
+
data-env="production"
|
|
37
|
+
data-checkout-param="lce_checkout"
|
|
38
|
+
type="text/javascript"
|
|
39
|
+
src="https://assets-elements.liquidcommerce.us/all/elements.js"
|
|
40
|
+
></script>
|
|
41
|
+
|
|
42
|
+
<div data-lce-checkout></div>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Main script example (cart redirects here):
|
|
46
|
+
```html
|
|
47
|
+
<script
|
|
48
|
+
defer
|
|
49
|
+
data-liquid-commerce-elements
|
|
50
|
+
data-token="YOUR_API_KEY"
|
|
51
|
+
data-env="production"
|
|
52
|
+
data-checkout-url="https://yoursite.com/checkout?lce_checkout={token}"
|
|
53
|
+
data-checkout-param="lce_checkout"
|
|
54
|
+
type="text/javascript"
|
|
55
|
+
src="https://assets-elements.liquidcommerce.us/all/elements.js"
|
|
56
|
+
></script>
|
|
57
|
+
```
|
|
58
|
+
## Hosted checkout UI controls
|
|
59
|
+
Use these attributes on the hosted checkout page to customize the UI:
|
|
60
|
+
|
|
61
|
+
- `hide-header` on the checkout container
|
|
62
|
+
Hides the SDK header so you can render your own.
|
|
63
|
+
|
|
64
|
+
```html
|
|
65
|
+
<div data-lce-checkout hide-header></div>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
- `data-lce-exit-checkout` on any element
|
|
69
|
+
Lets you build your own “Exit checkout” button or link.
|
|
70
|
+
|
|
71
|
+
```html
|
|
72
|
+
<button data-lce-exit-checkout>Exit checkout</button>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Checkout-only build
|
|
76
|
+
If a page only needs hosted checkout, use the checkout-only script. It supports the same hosted-checkout attributes but ships ~50% less JavaScript for faster load time.
|
|
77
|
+
|
|
78
|
+
```html
|
|
79
|
+
<script
|
|
80
|
+
defer
|
|
81
|
+
data-liquid-commerce-elements
|
|
82
|
+
data-token="YOUR_API_KEY"
|
|
83
|
+
data-env="production"
|
|
84
|
+
type="text/javascript"
|
|
85
|
+
src="https://assets-elements.liquidcommerce.us/checkout/elements.js"
|
|
86
|
+
></script>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Checkout actions
|
|
90
|
+
```js
|
|
91
|
+
window.elements.actions.checkout.openCheckout();
|
|
92
|
+
window.elements.actions.checkout.closeCheckout();
|
|
93
|
+
window.elements.actions.checkout.toggleCheckout();
|
|
94
|
+
window.elements.actions.checkout.exitCheckout();
|
|
95
|
+
|
|
96
|
+
await window.elements.actions.checkout.addProduct([
|
|
97
|
+
{ identifier: '00619947000020', fulfillmentType: 'shipping', quantity: 1 }
|
|
98
|
+
], true);
|
|
99
|
+
|
|
100
|
+
await window.elements.actions.checkout.applyPromoCode('WELCOME10');
|
|
101
|
+
await window.elements.actions.checkout.removePromoCode();
|
|
102
|
+
|
|
103
|
+
await window.elements.actions.checkout.applyGiftCard('GIFT-1234-5678');
|
|
104
|
+
await window.elements.actions.checkout.removeGiftCard('GIFT-1234-5678');
|
|
105
|
+
|
|
106
|
+
await window.elements.actions.checkout.toggleIsGift(true);
|
|
107
|
+
await window.elements.actions.checkout.toggleBillingSameAsShipping(false);
|
|
108
|
+
await window.elements.actions.checkout.toggleMarketingPreferences('canEmail', true);
|
|
109
|
+
|
|
110
|
+
window.elements.actions.checkout.updateCustomerInfo({
|
|
111
|
+
firstName: 'John',
|
|
112
|
+
lastName: 'Doe',
|
|
113
|
+
email: 'john@example.com'
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
window.elements.actions.checkout.updateBillingInfo({
|
|
117
|
+
firstName: 'John',
|
|
118
|
+
lastName: 'Doe',
|
|
119
|
+
addressOne: '789 Elm St',
|
|
120
|
+
city: 'Chicago',
|
|
121
|
+
state: 'IL',
|
|
122
|
+
zipCode: '60601'
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Checkout events (examples)
|
|
127
|
+
```js
|
|
128
|
+
window.addEventListener('lce:actions.checkout_submit_completed', (event) => {
|
|
129
|
+
const { orderId, total } = event.detail.data;
|
|
130
|
+
});
|
|
131
|
+
```
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Events
|
|
2
|
+
|
|
3
|
+
The SDK emits events for user actions and state changes. Listen on `window` using the `lce:actions.*` namespace.
|
|
4
|
+
|
|
5
|
+
## Event shape
|
|
6
|
+
```js
|
|
7
|
+
window.addEventListener('lce:actions.event_name', (event) => {
|
|
8
|
+
const { namespace, event: eventName, timestamp, id, data } = event.detail;
|
|
9
|
+
});
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Client lifecycle
|
|
13
|
+
- `lce:actions.client_ready`
|
|
14
|
+
Fired when the SDK is initialized and safe to use.
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
window.addEventListener('lce:actions.client_ready', (event) => {
|
|
18
|
+
const { isReady, version, timestamp } = event.detail.data;
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Product events
|
|
23
|
+
- `lce:actions.product_loaded`
|
|
24
|
+
Product data loaded into the component.
|
|
25
|
+
- `lce:actions.product_add_to_cart`
|
|
26
|
+
User clicked Add to Cart.
|
|
27
|
+
- `lce:actions.product_size_changed`
|
|
28
|
+
User changed the selected size.
|
|
29
|
+
- `lce:actions.product_fulfillment_type_changed`
|
|
30
|
+
User switched fulfillment type (shipping/onDemand).
|
|
31
|
+
- `lce:actions.product_fulfillment_changed`
|
|
32
|
+
Retailer selection changed.
|
|
33
|
+
- `lce:actions.product_quantity_increase`
|
|
34
|
+
User increased quantity.
|
|
35
|
+
- `lce:actions.product_quantity_decrease`
|
|
36
|
+
User decreased quantity.
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
window.addEventListener('lce:actions.product_loaded', (event) => {
|
|
40
|
+
const { identifier, name, price } = event.detail.data;
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Address events
|
|
45
|
+
- `lce:actions.address_updated`
|
|
46
|
+
Address successfully set or changed.
|
|
47
|
+
- `lce:actions.address_cleared`
|
|
48
|
+
Address removed.
|
|
49
|
+
- `lce:actions.address_failed`
|
|
50
|
+
Address set failed (validation, geocode, etc.).
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
window.addEventListener('lce:actions.address_updated', (event) => {
|
|
54
|
+
const { formattedAddress } = event.detail.data;
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Cart events
|
|
59
|
+
- `lce:actions.cart_loaded`
|
|
60
|
+
Cart state loaded.
|
|
61
|
+
- `lce:actions.cart_opened`
|
|
62
|
+
Cart drawer opened.
|
|
63
|
+
- `lce:actions.cart_closed`
|
|
64
|
+
Cart drawer closed.
|
|
65
|
+
- `lce:actions.cart_updated`
|
|
66
|
+
Cart totals/items changed.
|
|
67
|
+
- `lce:actions.cart_item_added`
|
|
68
|
+
Item added to cart.
|
|
69
|
+
- `lce:actions.cart_item_removed`
|
|
70
|
+
Item removed from cart.
|
|
71
|
+
- `lce:actions.cart_item_quantity_increase`
|
|
72
|
+
Cart item quantity increased.
|
|
73
|
+
- `lce:actions.cart_item_quantity_decrease`
|
|
74
|
+
Cart item quantity decreased.
|
|
75
|
+
- `lce:actions.cart_promo_code_applied`
|
|
76
|
+
Promo code applied to cart.
|
|
77
|
+
- `lce:actions.cart_promo_code_removed`
|
|
78
|
+
Promo code removed from cart.
|
|
79
|
+
- `lce:actions.cart_promo_code_failed`
|
|
80
|
+
Promo code failed validation.
|
|
81
|
+
- `lce:actions.cart_product_add_success`
|
|
82
|
+
Programmatic add-to-cart succeeded.
|
|
83
|
+
- `lce:actions.cart_product_add_failed`
|
|
84
|
+
Programmatic add-to-cart failed.
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
window.addEventListener('lce:actions.cart_updated', (event) => {
|
|
88
|
+
const { cartId, itemsCount, subtotal } = event.detail.data;
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Checkout events
|
|
93
|
+
- `lce:actions.checkout_loaded`
|
|
94
|
+
Checkout state loaded.
|
|
95
|
+
- `lce:actions.checkout_opened`
|
|
96
|
+
Checkout drawer opened.
|
|
97
|
+
- `lce:actions.checkout_closed`
|
|
98
|
+
Checkout drawer closed.
|
|
99
|
+
- `lce:actions.checkout_customer_information_updated`
|
|
100
|
+
Customer info updated.
|
|
101
|
+
- `lce:actions.checkout_billing_information_updated`
|
|
102
|
+
Billing info updated.
|
|
103
|
+
- `lce:actions.checkout_gift_information_updated`
|
|
104
|
+
Gift info updated.
|
|
105
|
+
- `lce:actions.checkout_is_gift_toggled`
|
|
106
|
+
Gift mode toggled.
|
|
107
|
+
- `lce:actions.checkout_billing_same_as_shipping_toggled`
|
|
108
|
+
Billing same as shipping toggled.
|
|
109
|
+
- `lce:actions.checkout_marketing_preferences_toggled`
|
|
110
|
+
Marketing preferences toggled.
|
|
111
|
+
- `lce:actions.checkout_submit_started`
|
|
112
|
+
Checkout submit started.
|
|
113
|
+
- `lce:actions.checkout_submit_completed`
|
|
114
|
+
Checkout completed successfully.
|
|
115
|
+
- `lce:actions.checkout_submit_failed`
|
|
116
|
+
Checkout submission failed.
|
|
117
|
+
- `lce:actions.checkout_promo_code_applied`
|
|
118
|
+
Promo code applied in checkout.
|
|
119
|
+
- `lce:actions.checkout_gift_card_applied`
|
|
120
|
+
Gift card applied in checkout.
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
window.addEventListener('lce:actions.checkout_submit_completed', (event) => {
|
|
124
|
+
const { orderId, total } = event.detail.data;
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Analytics example
|
|
129
|
+
```js
|
|
130
|
+
window.addEventListener('lce:actions.checkout_submit_completed', (event) => {
|
|
131
|
+
gtag('event', 'purchase', {
|
|
132
|
+
transaction_id: event.detail.data.orderId,
|
|
133
|
+
value: event.detail.data.total / 100,
|
|
134
|
+
currency: 'USD'
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
```
|