@liquidcommerce/elements-sdk 2.7.0 → 2.7.1
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 +83 -2750
- package/dist/index.checkout.esm.js +6877 -6825
- package/dist/index.esm.js +11384 -10940
- package/dist/types/auto-initialize/shared-utils.d.ts +5 -0
- package/dist/types/constants/core.constant.d.ts +0 -4
- package/dist/types/core/pubsub/interfaces/checkout.interface.d.ts +1 -0
- package/dist/types/enums/core.enum.d.ts +11 -0
- package/dist/types/interfaces/configs/product-list.interface.d.ts +2 -2
- package/dist/types/modules/address/address-input.component.d.ts +11 -0
- package/dist/types/modules/product-list/components/card-components/index.d.ts +3 -0
- package/dist/types/modules/product-list/components/card-components/product-badge.d.ts +8 -0
- package/dist/types/modules/product-list/components/card-components/product-fulfillments.d.ts +2 -0
- package/dist/types/modules/product-list/components/card-components/product-price-and-personalization.d.ts +13 -0
- package/dist/types/modules/product-list/components/card-components/product-title.d.ts +6 -0
- package/dist/types/modules/product-list/components/index.d.ts +1 -0
- package/dist/types/modules/product-list/components/product-list-engraving.component.d.ts +5 -1
- package/dist/types/modules/product-list/components/product-list-product-pre-cart.component.d.ts +28 -0
- package/dist/types/modules/product-list/components/product-list-retailers.component.d.ts +10 -2
- package/dist/types/modules/product-list/product-list-card.component.d.ts +0 -5
- package/dist/types/modules/product-list/product-list.commands.d.ts +11 -2
- package/dist/types/modules/product-list/product-list.interface.d.ts +1 -0
- package/dist/types/modules/ui-components/engraving/engraving-form.component.d.ts +11 -2
- 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 -1301
- package/docs/BROWSER_SUPPORT.md +0 -279
- package/docs/CONFIGURATION.md +0 -997
- package/docs/DOCUMENTATION_INDEX.md +0 -319
- package/docs/EVENTS.md +0 -798
- package/docs/PROXY.md +0 -228
- package/docs/THEMING.md +0 -681
- package/docs/TROUBLESHOOTING.md +0 -793
|
@@ -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
|
+
```
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Elements SDK
|
|
2
|
+
|
|
3
|
+
A lightweight, developer-facing guide to integrate LiquidCommerce Elements SDK into your site or app.
|
|
4
|
+
|
|
5
|
+
## What it is
|
|
6
|
+
Elements SDK is a Web Components-based e-commerce SDK that embeds product, cart, address, and checkout experiences into any website. It works with plain HTML or any framework and exposes a simple client + actions API.
|
|
7
|
+
|
|
8
|
+
## Core components
|
|
9
|
+
- Product: product detail display + add to cart
|
|
10
|
+
- Cart: slide-out cart drawer + promo codes
|
|
11
|
+
- Checkout: full checkout flow (drawer or hosted page)
|
|
12
|
+
- Address: delivery location and availability
|
|
13
|
+
|
|
14
|
+
## Quick start (CDN)
|
|
15
|
+
```html
|
|
16
|
+
<script
|
|
17
|
+
defer
|
|
18
|
+
data-liquid-commerce-elements
|
|
19
|
+
data-token="YOUR_API_KEY"
|
|
20
|
+
data-env="production"
|
|
21
|
+
data-container-1="product"
|
|
22
|
+
data-product-1="00619947000020"
|
|
23
|
+
type="text/javascript"
|
|
24
|
+
src="https://assets-elements.liquidcommerce.us/all/elements.js"
|
|
25
|
+
></script>
|
|
26
|
+
|
|
27
|
+
<div id="product"></div>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick start (NPM)
|
|
31
|
+
```bash
|
|
32
|
+
npm install @liquidcommerce/elements-sdk
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import { Elements } from '@liquidcommerce/elements-sdk';
|
|
37
|
+
|
|
38
|
+
const client = await Elements('YOUR_API_KEY', { env: 'production' });
|
|
39
|
+
await client.injectProductElement([
|
|
40
|
+
{ containerId: 'product', identifier: '00619947000020' }
|
|
41
|
+
]);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Initialization modes
|
|
45
|
+
- Declarative (CDN): data attributes on the script tag, auto-initialized
|
|
46
|
+
- Programmatic (NPM or CDN): call `Elements(...)` and inject components
|
|
47
|
+
|
|
48
|
+
The client is available globally as `window.elements` as soon as the SDK is ready.
|
|
49
|
+
|
|
50
|
+
## Quick Start Guide (auto-setup)
|
|
51
|
+
Most partners use the auto-setup approach because it is the fastest to implement. It supports rich configuration via data attributes, including product injection, cart buttons, checkout, query param handling, and more.
|
|
52
|
+
|
|
53
|
+
See [Quick Start Guide](./quick-start-guide.md) for the complete list of supported attributes and combinations.
|
|
54
|
+
|
|
55
|
+
## Configuration basics
|
|
56
|
+
```js
|
|
57
|
+
const client = await Elements('YOUR_API_KEY', {
|
|
58
|
+
env: 'production', // development | staging | production
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Client surface (exposed methods)
|
|
63
|
+
After initialization, the client exposes three main groups: injection methods, `actions`, and `ui` helpers, plus component management.
|
|
64
|
+
|
|
65
|
+
### Injection methods
|
|
66
|
+
Use these to mount SDK components into your DOM. Each method is shown with a minimal example.
|
|
67
|
+
|
|
68
|
+
#### `injectProductElement(params[])`
|
|
69
|
+
Inject one or more product components by container ID + product identifier.
|
|
70
|
+
```js
|
|
71
|
+
await client.injectProductElement([
|
|
72
|
+
{ containerId: 'product-1', identifier: '00619947000020' },
|
|
73
|
+
{ containerId: 'product-2', identifier: '08504405135' }
|
|
74
|
+
]);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### `injectAddressElement(containerId, options?)`
|
|
78
|
+
Inject a standalone address component (optional callbacks like `onAddressSet`).
|
|
79
|
+
```js
|
|
80
|
+
await client.injectAddressElement('address', {
|
|
81
|
+
onAddressSet: (address) => console.log(address)
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
#### `injectCartElement(containerId)`
|
|
86
|
+
Inject a standalone cart component (rare; cart drawer is automatic).
|
|
87
|
+
```js
|
|
88
|
+
await client.injectCartElement('cart');
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
#### `injectCheckoutElement(params)`
|
|
92
|
+
Inject a hosted checkout into a container.
|
|
93
|
+
```js
|
|
94
|
+
await client.injectCheckoutElement({
|
|
95
|
+
containerId: 'checkout',
|
|
96
|
+
checkoutId: 'checkout_abc123',
|
|
97
|
+
hideHeader: false
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
### Actions (`client.actions.*`)
|
|
103
|
+
Actions are programmatic controls for state changes and flows. The full list with details is in [Actions](./actions.md).
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
// Example: add to cart and open cart
|
|
107
|
+
await window.elements.actions.cart.addProduct([
|
|
108
|
+
{ identifier: '00619947000020', fulfillmentType: 'shipping', quantity: 1 }
|
|
109
|
+
], true);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### UI helpers (`client.ui.*`)
|
|
113
|
+
Helpers for common cart UI elements that stay in sync automatically.
|
|
114
|
+
|
|
115
|
+
#### `ui.cartButton(containerId, showItemsCount?)`
|
|
116
|
+
Renders a cart button in a container.
|
|
117
|
+
```js
|
|
118
|
+
window.elements.ui.cartButton('header-cart', true);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
#### `ui.floatingCartButton(showItemsCount?)`
|
|
122
|
+
Renders a floating cart button (bottom-right).
|
|
123
|
+
```js
|
|
124
|
+
window.elements.ui.floatingCartButton(true);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### `ui.cartSubtotal(elementId)`
|
|
128
|
+
Keeps a DOM element updated with cart subtotal.
|
|
129
|
+
```html
|
|
130
|
+
<span id="cart-total"></span>
|
|
131
|
+
```
|
|
132
|
+
```js
|
|
133
|
+
window.elements.ui.cartSubtotal('cart-total');
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
#### `ui.cartItemsCount(elementId, { hideZero })`
|
|
137
|
+
Keeps a DOM element updated with item count.
|
|
138
|
+
```html
|
|
139
|
+
<span id="items-count"></span>
|
|
140
|
+
```
|
|
141
|
+
```js
|
|
142
|
+
window.elements.ui.cartItemsCount('items-count', { hideZero: true });
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Component management
|
|
146
|
+
You can inspect and re-render injected components.
|
|
147
|
+
|
|
148
|
+
- `getInjectedComponents()`
|
|
149
|
+
Returns a map of injected components keyed by container ID.
|
|
150
|
+
|
|
151
|
+
```js
|
|
152
|
+
const components = client.getInjectedComponents();
|
|
153
|
+
const productComponent = components.get('product-1');
|
|
154
|
+
|
|
155
|
+
productComponent.getType(); // 'product'
|
|
156
|
+
productComponent.getElement(); // underlying element
|
|
157
|
+
productComponent.rerender(); // force re-render
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Recommended flow
|
|
161
|
+
1. Initialize the client
|
|
162
|
+
2. Inject product(s)
|
|
163
|
+
3. Let the cart drawer handle checkout by default
|
|
164
|
+
4. Use actions + events to track analytics and UI updates
|
|
165
|
+
|
|
166
|
+
For details, see the component pages: Product, Cart, Checkout, Address, Actions, Events.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Product
|
|
2
|
+
|
|
3
|
+
The Product component renders a complete product view with images, pricing, fulfillment options, and add-to-cart.
|
|
4
|
+
|
|
5
|
+
## What you get
|
|
6
|
+
- Image carousel
|
|
7
|
+
- Name, description, pricing
|
|
8
|
+
- Size selection (if applicable)
|
|
9
|
+
- Fulfillment type selection (shipping or on-demand)
|
|
10
|
+
- Retailer selection (when multiple retailers are available)
|
|
11
|
+
- Personalization/engraving (when supported)
|
|
12
|
+
- Quantity controls
|
|
13
|
+
- Location-based availability and pricing
|
|
14
|
+
|
|
15
|
+
## Add a product (CDN, declarative)
|
|
16
|
+
```html
|
|
17
|
+
<script
|
|
18
|
+
defer
|
|
19
|
+
data-liquid-commerce-elements
|
|
20
|
+
data-token="YOUR_API_KEY"
|
|
21
|
+
data-env="production"
|
|
22
|
+
data-container-1="product"
|
|
23
|
+
data-product-1="00619947000020"
|
|
24
|
+
type="text/javascript"
|
|
25
|
+
src="https://assets-elements.liquidcommerce.us/all/elements.js"
|
|
26
|
+
></script>
|
|
27
|
+
|
|
28
|
+
<div id="product"></div>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Add a product (programmatic)
|
|
32
|
+
```js
|
|
33
|
+
const client = await Elements('YOUR_API_KEY', { env: 'production' });
|
|
34
|
+
await client.injectProductElement([
|
|
35
|
+
{ containerId: 'product', identifier: '00619947000020' }
|
|
36
|
+
]);
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Identifiers
|
|
40
|
+
Use any of the supported identifiers:
|
|
41
|
+
- UPC
|
|
42
|
+
- Grouping ID
|
|
43
|
+
|
|
44
|
+
The SDK resolves the correct product automatically.
|
|
45
|
+
|
|
46
|
+
## Product actions
|
|
47
|
+
```js
|
|
48
|
+
const product = window.elements.actions.product.getDetails('00619947000020');
|
|
49
|
+
console.log(product.name, product.price);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Product events (examples)
|
|
53
|
+
```js
|
|
54
|
+
window.addEventListener('lce:actions.product_loaded', (event) => {
|
|
55
|
+
const { identifier, name, price } = event.detail.data;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
window.addEventListener('lce:actions.product_add_to_cart', (event) => {
|
|
59
|
+
const { identifier, quantity, fulfillmentType } = event.detail.data;
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Address requirement
|
|
64
|
+
If an address is required for availability, the SDK automatically prompts the user to set it before adding to cart.
|