@liquidcommerce/elements-sdk 2.6.0-beta.6 → 2.6.0-beta.61
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 -2519
- package/dist/index.checkout.esm.js +16576 -0
- package/dist/index.esm.js +23632 -21083
- package/dist/ssr-stub.checkout.esm.js +18 -0
- package/dist/ssr-stub.esm.js +270 -0
- package/dist/types/auto-initialize/checkout.d.ts +2 -0
- package/dist/types/auto-initialize/shared-utils.d.ts +46 -0
- package/dist/types/{elements-base-client.d.ts → clients/base.d.ts} +15 -2
- package/dist/types/clients/builder.d.ts +3 -0
- package/dist/types/clients/checkout.d.ts +6 -0
- package/dist/types/{elements-client-helper.d.ts → clients/helpers.d.ts} +2 -1
- package/dist/types/clients/main.d.ts +3 -0
- package/dist/types/constants/core.constant.d.ts +2 -6
- package/dist/types/core/api/api-client.service.d.ts +21 -20
- package/dist/types/core/api/api-result.d.ts +19 -0
- package/dist/types/core/api/auth-client.service.d.ts +40 -13
- package/dist/types/core/api/http-client.service.d.ts +0 -1
- package/dist/types/core/base-component.service.d.ts +2 -1
- package/dist/types/core/client/actions/base-action.service.d.ts +15 -0
- package/dist/types/core/client/actions/client-address-action.service.d.ts +18 -0
- package/dist/types/core/client/actions/client-cart-action.service.d.ts +37 -0
- package/dist/types/core/client/actions/client-checkout-action.service.d.ts +56 -0
- package/dist/types/core/client/actions/client-product-action.service.d.ts +15 -0
- package/dist/types/core/client/client-action.service.d.ts +6 -70
- package/dist/types/core/client/client-config.service.d.ts +8 -2
- package/dist/types/core/command/common-command.service.d.ts +2 -1
- package/dist/types/core/google-tag-manager.service.d.ts +4 -1
- package/dist/types/core/logger/logger.service.d.ts +1 -1
- package/dist/types/core/pubsub/interfaces/cart.interface.d.ts +27 -64
- package/dist/types/core/pubsub/interfaces/checkout.interface.d.ts +45 -50
- package/dist/types/core/pubsub/interfaces/core.interface.d.ts +9 -4
- package/dist/types/core/pubsub/interfaces/product.interface.d.ts +16 -75
- package/dist/types/core/pubsub/pubsub.service.d.ts +1 -2
- package/dist/types/core/singleton-manager.service.d.ts +12 -8
- package/dist/types/core/store/interfaces/cart.interface.d.ts +16 -56
- package/dist/types/core/store/interfaces/checkout.interface.d.ts +17 -108
- package/dist/types/core/store/interfaces/core.interface.d.ts +14 -3
- package/dist/types/core/store/interfaces/metadata.interface.d.ts +11 -0
- package/dist/types/core/store/interfaces/product-list.interface.d.ts +30 -0
- package/dist/types/core/store/interfaces/product.interface.d.ts +1 -0
- package/dist/types/core/store/store.constant.d.ts +5 -0
- package/dist/types/core/store/store.service.d.ts +1 -0
- package/dist/types/core/telemetry/telemetry.service.d.ts +1 -0
- package/dist/types/enums/core.enum.d.ts +39 -1
- package/dist/types/enums/index.d.ts +0 -1
- package/dist/types/index.checkout.d.ts +8 -0
- package/dist/types/index.checkout.umd.d.ts +4 -0
- package/dist/types/index.d.ts +8 -3
- package/dist/types/interfaces/api/cart.interface.d.ts +95 -0
- package/dist/types/interfaces/api/checkout.interface.d.ts +238 -0
- package/dist/types/interfaces/api/index.d.ts +5 -0
- package/dist/types/interfaces/api/product-list.interface.d.ts +39 -0
- package/dist/types/interfaces/api/product.interface.d.ts +9 -4
- package/dist/types/interfaces/client.interface.d.ts +72 -0
- package/dist/types/interfaces/component.interface.d.ts +7 -0
- package/dist/types/interfaces/config.interface.d.ts +41 -0
- package/dist/types/interfaces/configs/address.interface.d.ts +1 -1
- package/dist/types/interfaces/configs/cart.interface.d.ts +1 -1
- package/dist/types/interfaces/configs/checkout.interface.d.ts +2 -1
- package/dist/types/interfaces/configs/global.interface.d.ts +5 -3
- package/dist/types/interfaces/configs/index.d.ts +1 -0
- package/dist/types/interfaces/configs/product-list.interface.d.ts +47 -0
- package/dist/types/interfaces/configs/product.interface.d.ts +2 -1
- package/dist/types/interfaces/injection.interface.d.ts +47 -0
- package/dist/types/modules/address/address.command.d.ts +2 -1
- package/dist/types/modules/address/styles/register-styles.d.ts +1 -0
- package/dist/types/modules/cart/cart.commands.d.ts +4 -5
- package/dist/types/modules/cart/components/cart-body.component.d.ts +2 -1
- package/dist/types/modules/cart/components/cart-footer.component.d.ts +0 -1
- package/dist/types/modules/cart/components/cart-fulfillment.component.d.ts +0 -2
- package/dist/types/modules/cart/styles/register-styles.d.ts +1 -0
- package/dist/types/modules/checkout/checkout.commands.d.ts +23 -9
- package/dist/types/modules/checkout/checkout.component.d.ts +2 -0
- package/dist/types/modules/checkout/components/checkout-billing.component.d.ts +2 -2
- package/dist/types/modules/checkout/components/checkout-completed.component.d.ts +3 -0
- package/dist/types/modules/checkout/components/checkout-header.component.d.ts +1 -0
- package/dist/types/modules/checkout/components/checkout-items.component.d.ts +4 -3
- package/dist/types/modules/checkout/components/checkout-presale-countdown.component.d.ts +14 -1
- package/dist/types/modules/checkout/components/checkout-presale-expired.component.d.ts +7 -1
- package/dist/types/modules/checkout/components/checkout-stripe-form.component.d.ts +2 -1
- package/dist/types/modules/checkout/components/checkout-tips.component.d.ts +2 -2
- package/dist/types/modules/checkout/components/promo-pc-gc.component.d.ts +0 -2
- package/dist/types/modules/checkout/constant.d.ts +3 -0
- package/dist/types/modules/checkout/styles/register-styles.d.ts +1 -0
- package/dist/types/modules/product/components/product-image-carousel.component.d.ts +3 -0
- package/dist/types/modules/product/components/product-retailers-carousel.component.d.ts +3 -0
- package/dist/types/modules/product/components/product-retailers-popup-list.component.d.ts +5 -2
- package/dist/types/modules/product/product.commands.d.ts +2 -3
- package/dist/types/modules/product/styles/register-styles.d.ts +1 -0
- package/dist/types/modules/product-list/components/card-components/index.d.ts +5 -0
- package/dist/types/modules/product-list/components/card-components/product-badge.d.ts +9 -0
- package/dist/types/modules/product-list/components/card-components/product-button.d.ts +9 -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-quantity-selector.d.ts +9 -0
- package/dist/types/modules/product-list/components/card-components/product-sizes-list.d.ts +13 -0
- package/dist/types/modules/product-list/components/filter-components/index.d.ts +7 -0
- package/dist/types/modules/product-list/components/filter-components/product-list-apply-filter-button.d.ts +1 -0
- package/dist/types/modules/product-list/components/filter-components/product-list-chip.d.ts +5 -0
- package/dist/types/modules/product-list/components/filter-components/product-list-filters-chips.d.ts +13 -0
- package/dist/types/modules/product-list/components/filter-components/product-list-fulfillment-filter.d.ts +14 -0
- package/dist/types/modules/product-list/components/{product-list-filters-subcomponents/product-list-price-filter.components.d.ts → filter-components/product-list-price-filter.d.ts} +1 -1
- package/dist/types/modules/product-list/components/filter-components/product-list-toggle-filters.d.ts +7 -0
- package/dist/types/modules/product-list/components/index.d.ts +6 -2
- package/dist/types/modules/product-list/components/product-list-card-loading.component.d.ts +2 -1
- package/dist/types/modules/product-list/components/product-list-card.component.d.ts +27 -30
- package/dist/types/modules/product-list/components/product-list-engraving.component.d.ts +12 -0
- package/dist/types/modules/product-list/components/product-list-filters.component.d.ts +55 -36
- package/dist/types/modules/product-list/components/product-list-product-engraving-lines.component.d.ts +22 -0
- package/dist/types/modules/product-list/components/product-list-product-pre-cart.component.d.ts +47 -0
- package/dist/types/modules/product-list/components/{product-list-filters-subcomponents/product-list-search.component.d.ts → product-list-search.component.d.ts} +11 -4
- package/dist/types/modules/product-list/product-list-filter.utils.d.ts +8 -0
- package/dist/types/modules/product-list/product-list.commands.d.ts +23 -8
- package/dist/types/modules/product-list/product-list.component.d.ts +10 -45
- package/dist/types/modules/product-list/product-list.constants.d.ts +38 -0
- package/dist/types/modules/product-list/product-list.interface.d.ts +20 -35
- package/dist/types/modules/product-list/styles/product-list-card.style.d.ts +1 -0
- package/dist/types/modules/product-list/styles/product-list-filters.style.d.ts +1 -0
- package/dist/types/modules/product-list/styles/register-styles.d.ts +1 -0
- package/dist/types/modules/theme-provider/constants/component-groupings.d.ts +1 -0
- package/dist/types/modules/theme-provider/constants/css-variable-mappings.d.ts +1 -1
- package/dist/types/modules/theme-provider/services/style-registry.service.d.ts +16 -0
- package/dist/types/modules/theme-provider/services/stylesheet-generator.service.d.ts +0 -1
- package/dist/types/modules/theme-provider/styles/register-styles.d.ts +1 -0
- package/dist/types/modules/theme-provider/theme-provider.service.d.ts +2 -2
- package/dist/types/modules/ui-components/drawer/drawer.component.d.ts +1 -0
- package/dist/types/modules/ui-components/engraving/engraving-form.component.d.ts +6 -1
- package/dist/types/modules/ui-components/engraving/engraving-view.component.d.ts +5 -1
- package/dist/types/modules/ui-components/input/index.d.ts +0 -1
- package/dist/types/modules/ui-components/input/input.component.d.ts +8 -1
- package/dist/types/modules/ui-components/lce-element/lce-element.component.d.ts +2 -1
- package/dist/types/modules/ui-components/promo-code-ticker/promo-code-ticker.component.d.ts +1 -1
- package/dist/types/modules/ui-components/purchase-min-alert/index.d.ts +0 -1
- package/dist/types/modules/ui-components/ui.commands.d.ts +5 -1
- package/dist/types/ssr/stub.checkout.d.ts +6 -0
- package/dist/types/ssr/stub.d.ts +10 -0
- package/dist/types/static/icon/check.icon.d.ts +2 -0
- package/dist/types/static/icon/index.d.ts +1 -0
- package/dist/types/utils/dom-compat.d.ts +2 -0
- package/dist/types/utils/format.d.ts +0 -14
- package/dist/types/utils/product-selection.d.ts +16 -0
- package/dist/types/utils/product.d.ts +10 -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 +926 -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 +69 -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 +58 -0
- package/docs/v1/reference/browser-support.md +44 -0
- package/docs/v1/reference/error-handling.md +70 -0
- package/docs/v1/reference/performance.md +54 -0
- package/docs/v1/reference/troubleshooting.md +72 -0
- package/package.json +28 -17
- package/dist/types/elements-builder-client.d.ts +0 -2
- package/dist/types/elements-client.d.ts +0 -2
- package/dist/types/enums/cloud.enum.d.ts +0 -106
- package/dist/types/interfaces/cloud/cart.interface.d.ts +0 -132
- package/dist/types/interfaces/cloud/catalog.interface.d.ts +0 -42
- package/dist/types/interfaces/cloud/checkout.interface.d.ts +0 -211
- package/dist/types/interfaces/cloud/core.interface.d.ts +0 -22
- package/dist/types/interfaces/cloud/index.d.ts +0 -5
- package/dist/types/interfaces/cloud/retailer.interface.d.ts +0 -67
- package/dist/types/interfaces/cloud/user.interface.d.ts +0 -100
- package/dist/types/interfaces/core.interface.d.ts +0 -111
- package/dist/types/modules/cart/cart.commands.helper.d.ts +0 -9
- package/dist/types/modules/checkout/components/checkout.type.d.ts +0 -4
- package/dist/types/modules/product-list/components/product-list-filters-subcomponents/index.d.ts +0 -6
- package/dist/types/modules/product-list/components/product-list-filters-subcomponents/product-list-apply-filter-button.component.d.ts +0 -1
- package/dist/types/modules/product-list/components/product-list-filters-subcomponents/product-list-delivery-options-filter.components.d.ts +0 -16
- package/dist/types/modules/product-list/components/product-list-filters-subcomponents/product-list-toggle-filters.components.d.ts +0 -18
- package/dist/types/modules/theme-provider/styles/address/index.d.ts +0 -1
- package/dist/types/modules/theme-provider/styles/cart/index.d.ts +0 -1
- package/dist/types/modules/theme-provider/styles/checkout/index.d.ts +0 -1
- package/dist/types/modules/theme-provider/styles/product/index.d.ts +0 -3
- package/dist/types/modules/theme-provider/styles/product-list/index.d.ts +0 -1
- package/dist/types/modules/theme-provider/styles/ui/index.d.ts +0 -3
- package/dist/types/modules/ui-components/input/birthdate-input.component.d.ts +0 -53
- package/dist/types/modules/ui-components/purchase-min-alert/helpers.d.ts +0 -7
- package/dist/types/utils/helper.d.ts +0 -27
- package/docs/ACTIONS.md +0 -1300
- package/docs/BROWSER_SUPPORT.md +0 -279
- package/docs/CONFIGURATION.md +0 -853
- package/docs/DOCUMENTATION_INDEX.md +0 -311
- package/docs/EVENTS.md +0 -798
- package/docs/PROXY.md +0 -228
- package/docs/THEMING.md +0 -592
- package/docs/TROUBLESHOOTING.md +0 -793
- package/umd/elements.js +0 -1
- /package/dist/types/{auto-initialize.d.ts → auto-initialize/main.d.ts} +0 -0
- /package/dist/types/modules/{theme-provider/styles/address → address/styles}/address.style.d.ts +0 -0
- /package/dist/types/modules/{theme-provider/styles/cart → cart/styles}/cart.style.d.ts +0 -0
- /package/dist/types/modules/{theme-provider/styles/checkout → checkout/styles}/checkout.style.d.ts +0 -0
- /package/dist/types/modules/{theme-provider/styles/product → product/styles}/image-carousel.style.d.ts +0 -0
- /package/dist/types/modules/{theme-provider/styles/product → product/styles}/product.style.d.ts +0 -0
- /package/dist/types/modules/{theme-provider/styles/product → product/styles}/retailers.style.d.ts +0 -0
- /package/dist/types/modules/product-list/components/{product-list-filters-subcomponents/product-list-checkbox-filter.components.d.ts → filter-components/product-list-checkbox-filter.d.ts} +0 -0
- /package/dist/types/modules/{theme-provider/styles/product-list → product-list/styles}/product-list.style.d.ts +0 -0
- /package/dist/types/modules/{theme-provider/styles/ui → ui-components/styles}/drawer.style.d.ts +0 -0
- /package/dist/types/modules/{theme-provider/styles/ui → ui-components/styles}/loading.style.d.ts +0 -0
- /package/dist/types/modules/{theme-provider/styles/ui → ui-components/styles}/promo-code-ticker.style.d.ts +0 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
# Best Practices
|
|
2
|
+
|
|
3
|
+
Recommended patterns and practices for working with the Elements SDK.
|
|
4
|
+
|
|
5
|
+
## Initialization
|
|
6
|
+
|
|
7
|
+
### Initialize Once
|
|
8
|
+
|
|
9
|
+
Create a single client instance and reuse it:
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
// Good
|
|
13
|
+
const client = await Elements('KEY', { env: 'production' });
|
|
14
|
+
await client.injectProductElement([...]);
|
|
15
|
+
await client.injectCartElement('cart');
|
|
16
|
+
|
|
17
|
+
// Bad - creates multiple instances
|
|
18
|
+
await Elements('KEY', { env: 'production' });
|
|
19
|
+
await Elements('KEY', { env: 'production' });
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Use Global Access
|
|
23
|
+
|
|
24
|
+
After initialization, use `window.LiquidCommerce.elements`:
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
// Initialize once
|
|
28
|
+
await Elements('KEY', { env: 'production' });
|
|
29
|
+
|
|
30
|
+
// Use globally throughout your app
|
|
31
|
+
window.LiquidCommerce.elements.actions.cart.openCart();
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Wait for Client Ready
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
if (window.LiquidCommerce.elements) {
|
|
38
|
+
// Client already ready
|
|
39
|
+
window.LiquidCommerce.elements.actions.cart.openCart();
|
|
40
|
+
} else {
|
|
41
|
+
// Wait for initialization
|
|
42
|
+
window.addEventListener('lce:actions.client_ready', () => {
|
|
43
|
+
window.LiquidCommerce.elements.actions.cart.openCart();
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Component Injection
|
|
49
|
+
|
|
50
|
+
### Verify Container Exists
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
// Check container before injection
|
|
54
|
+
if (document.getElementById('product')) {
|
|
55
|
+
await client.injectProductElement([
|
|
56
|
+
{ containerId: 'product', identifier: '123' }
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Provide Adequate Space
|
|
62
|
+
|
|
63
|
+
```css
|
|
64
|
+
#product-container {
|
|
65
|
+
min-height: 600px; /* Prevent layout shift */
|
|
66
|
+
max-width: 1200px;
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Handle Loading States
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
showLoader('product-container');
|
|
74
|
+
|
|
75
|
+
await client.injectProductElement([...]);
|
|
76
|
+
|
|
77
|
+
// Loader automatically replaced when product loads
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Error Handling
|
|
81
|
+
|
|
82
|
+
### Catch Errors Appropriately
|
|
83
|
+
|
|
84
|
+
```javascript
|
|
85
|
+
try {
|
|
86
|
+
await window.LiquidCommerce.elements.actions.cart.addProduct([...]);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (error.name === 'SDKError') {
|
|
89
|
+
console.error('SDK Error:', error);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Provide Fallbacks
|
|
95
|
+
|
|
96
|
+
```javascript
|
|
97
|
+
const client = await Elements('KEY', { env: 'production' });
|
|
98
|
+
|
|
99
|
+
if (!client) {
|
|
100
|
+
// Initialization failed
|
|
101
|
+
showFallbackUI();
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Performance
|
|
107
|
+
|
|
108
|
+
### Lazy Load Products
|
|
109
|
+
|
|
110
|
+
```javascript
|
|
111
|
+
const observer = new IntersectionObserver(async (entries) => {
|
|
112
|
+
for (const entry of entries) {
|
|
113
|
+
if (entry.isIntersecting) {
|
|
114
|
+
const container = entry.target;
|
|
115
|
+
await client.injectProductElement([
|
|
116
|
+
{ containerId: container.id, identifier: container.dataset.productId }
|
|
117
|
+
]);
|
|
118
|
+
observer.unobserve(container);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
document.querySelectorAll('.product-placeholder').forEach(el => {
|
|
124
|
+
observer.observe(el);
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Use Checkout-Only Build
|
|
129
|
+
|
|
130
|
+
For checkout pages:
|
|
131
|
+
|
|
132
|
+
```javascript
|
|
133
|
+
import { ElementsCheckout } from '@liquidcommerce/elements-sdk/checkout';
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Reduces bundle size by ~60%.
|
|
137
|
+
|
|
138
|
+
### Defer Non-Critical Operations
|
|
139
|
+
|
|
140
|
+
```javascript
|
|
141
|
+
// Load visible products first
|
|
142
|
+
await client.injectProductElement([
|
|
143
|
+
{ containerId: 'hero-product', identifier: '001' }
|
|
144
|
+
]);
|
|
145
|
+
|
|
146
|
+
// Load others after delay
|
|
147
|
+
setTimeout(async () => {
|
|
148
|
+
await client.injectProductElement([
|
|
149
|
+
{ containerId: 'related-1', identifier: '002' }
|
|
150
|
+
]);
|
|
151
|
+
}, 1000);
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## State Management
|
|
155
|
+
|
|
156
|
+
### Pre-fill Known Data
|
|
157
|
+
|
|
158
|
+
```javascript
|
|
159
|
+
// Set address if known
|
|
160
|
+
if (userSavedAddress) {
|
|
161
|
+
await window.LiquidCommerce.elements.actions.address.setAddressManually(
|
|
162
|
+
userSavedAddress,
|
|
163
|
+
userCoordinates
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Pre-fill checkout info
|
|
168
|
+
window.addEventListener('lce:actions.checkout_opened', () => {
|
|
169
|
+
if (userIsLoggedIn) {
|
|
170
|
+
window.LiquidCommerce.elements.actions.checkout.updateCustomerInfo({
|
|
171
|
+
firstName: user.firstName,
|
|
172
|
+
email: user.email
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Don't Clear Cart Unnecessarily
|
|
179
|
+
|
|
180
|
+
Cart persists across sessions - avoid clearing unless intentional:
|
|
181
|
+
|
|
182
|
+
```javascript
|
|
183
|
+
// Only clear when user explicitly requests
|
|
184
|
+
document.getElementById('clear-cart-btn').addEventListener('click', async () => {
|
|
185
|
+
if (confirm('Clear cart?')) {
|
|
186
|
+
await window.LiquidCommerce.elements.actions.cart.resetCart();
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Events
|
|
192
|
+
|
|
193
|
+
### Use Events for Reactive Updates
|
|
194
|
+
|
|
195
|
+
```javascript
|
|
196
|
+
// Update UI when cart changes
|
|
197
|
+
window.addEventListener('lce:actions.cart_updated', () => {
|
|
198
|
+
const cart = window.LiquidCommerce.elements.actions.cart.getDetails();
|
|
199
|
+
updateHeaderCartCount(cart.itemsCount);
|
|
200
|
+
});
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Track Important Events
|
|
204
|
+
|
|
205
|
+
```javascript
|
|
206
|
+
window.addEventListener('lce:actions.checkout_submit_completed', (event) => {
|
|
207
|
+
const { orderId, total } = event.detail.data;
|
|
208
|
+
|
|
209
|
+
// Analytics
|
|
210
|
+
gtag('event', 'purchase', {
|
|
211
|
+
transaction_id: orderId,
|
|
212
|
+
value: total / 100
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// Backend tracking
|
|
216
|
+
fetch('/api/track-order', {
|
|
217
|
+
method: 'POST',
|
|
218
|
+
body: JSON.stringify({ orderId, total })
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Security
|
|
224
|
+
|
|
225
|
+
### Use Proxy in Production
|
|
226
|
+
|
|
227
|
+
```javascript
|
|
228
|
+
const client = await Elements('YOUR_API_KEY', {
|
|
229
|
+
env: 'production',
|
|
230
|
+
proxy: {
|
|
231
|
+
baseUrl: 'https://yoursite.com/api/elements-proxy'
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Prevents ad blockers and protects API keys.
|
|
237
|
+
|
|
238
|
+
### Separate API Keys by Environment
|
|
239
|
+
|
|
240
|
+
```javascript
|
|
241
|
+
const apiKey = process.env.NODE_ENV === 'production'
|
|
242
|
+
? 'prod_key_xyz'
|
|
243
|
+
: 'dev_key_abc';
|
|
244
|
+
|
|
245
|
+
const client = await Elements(apiKey, {
|
|
246
|
+
env: process.env.NODE_ENV === 'production' ? 'production' : 'development'
|
|
247
|
+
});
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Testing
|
|
251
|
+
|
|
252
|
+
### Use Development Mode
|
|
253
|
+
|
|
254
|
+
```javascript
|
|
255
|
+
const client = await Elements('YOUR_API_KEY', {
|
|
256
|
+
env: 'development',
|
|
257
|
+
debugMode: 'console', // or 'panel'
|
|
258
|
+
development: {
|
|
259
|
+
openShadowDom: true, // Makes debugging easier
|
|
260
|
+
paymentMethodId: 'pm_test_123' // Bypass Stripe for tests
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Handle Test Scenarios
|
|
266
|
+
|
|
267
|
+
```javascript
|
|
268
|
+
// Test empty cart
|
|
269
|
+
if (isDevelopment) {
|
|
270
|
+
await window.LiquidCommerce.elements.actions.cart.resetCart();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Test with specific product
|
|
274
|
+
await window.LiquidCommerce.elements.actions.cart.addProduct([
|
|
275
|
+
{ identifier: testProductId, fulfillmentType: 'shipping', quantity: 1 }
|
|
276
|
+
]);
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## Accessibility
|
|
280
|
+
|
|
281
|
+
### Provide Labels
|
|
282
|
+
|
|
283
|
+
```html
|
|
284
|
+
<label for="cart-toggle">Shopping Cart</label>
|
|
285
|
+
<button id="cart-toggle" data-lce-cart-toggle-button>
|
|
286
|
+
Cart (<span data-lce-cart-items-count></span>)
|
|
287
|
+
</button>
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### Use Semantic HTML
|
|
291
|
+
|
|
292
|
+
```html
|
|
293
|
+
<nav aria-label="Main navigation">
|
|
294
|
+
<div id="cart-button"></div>
|
|
295
|
+
</nav>
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## Mobile Optimization
|
|
299
|
+
|
|
300
|
+
### Responsive Containers
|
|
301
|
+
|
|
302
|
+
```css
|
|
303
|
+
@media (max-width: 768px) {
|
|
304
|
+
#product-container {
|
|
305
|
+
padding: 10px;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### Mobile-Specific Cart Button
|
|
311
|
+
|
|
312
|
+
```javascript
|
|
313
|
+
if (window.innerWidth < 768) {
|
|
314
|
+
window.LiquidCommerce.elements.ui.floatingCartButton(true);
|
|
315
|
+
} else {
|
|
316
|
+
window.LiquidCommerce.elements.ui.cartButton('header-cart', true);
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## See Also
|
|
321
|
+
|
|
322
|
+
- [Performance Guide](../reference/performance.md)
|
|
323
|
+
- [Troubleshooting](../reference/troubleshooting.md)
|
|
324
|
+
- [Component Guides](../guides/)
|