@liquidcommerce/elements-sdk 2.6.0-beta.41 → 2.6.0-beta.43
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 +1 -1
- package/dist/index.checkout.esm.js +6634 -6615
- package/dist/index.esm.js +11209 -11112
- package/dist/ssr-stub.checkout.esm.js +18 -0
- package/dist/ssr-stub.esm.js +269 -0
- package/dist/types/auto-initialize/shared-utils.d.ts +3 -1
- package/dist/types/clients/base.d.ts +4 -1
- package/dist/types/clients/builder.d.ts +2 -1
- package/dist/types/clients/checkout.d.ts +2 -10
- package/dist/types/clients/main.d.ts +2 -1
- package/dist/types/core/base-component.service.d.ts +2 -1
- package/dist/types/core/client/client-action.service.d.ts +1 -1
- package/dist/types/core/client/client-config.service.d.ts +1 -1
- package/dist/types/core/pubsub/pubsub.service.d.ts +0 -2
- package/dist/types/core/singleton-manager.service.d.ts +1 -1
- package/dist/types/index.checkout.d.ts +3 -2
- package/dist/types/index.checkout.umd.d.ts +1 -1
- package/dist/types/index.d.ts +4 -1
- package/dist/types/interfaces/client.interface.d.ts +62 -0
- package/dist/types/interfaces/component.interface.d.ts +7 -0
- package/dist/types/interfaces/config.interface.d.ts +45 -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 +1 -1
- package/dist/types/interfaces/configs/global.interface.d.ts +1 -1
- package/dist/types/interfaces/configs/product-list.interface.d.ts +1 -1
- package/dist/types/interfaces/configs/product.interface.d.ts +1 -1
- package/dist/types/interfaces/injection.interface.d.ts +44 -0
- package/dist/types/modules/checkout/components/checkout-stripe-form.component.d.ts +2 -1
- 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-list/components/product-list-filters.component.d.ts +3 -1
- package/dist/types/modules/product-list/product-list.commands.d.ts +1 -1
- package/dist/types/modules/product-list/product-list.component.d.ts +1 -1
- package/dist/types/modules/ui-components/lce-element/lce-element.component.d.ts +2 -1
- package/dist/types/ssr/stub.checkout.d.ts +6 -0
- package/dist/types/ssr/stub.d.ts +10 -0
- package/dist/types/utils/dom-compat.d.ts +2 -0
- package/docs/v1/README.md +2 -2
- package/docs/v1/api/actions/address-actions.md +11 -11
- package/docs/v1/api/actions/cart-actions.md +13 -13
- package/docs/v1/api/actions/checkout-actions.md +23 -23
- package/docs/v1/api/actions/product-actions.md +6 -6
- package/docs/v1/api/client.md +11 -11
- package/docs/v1/api/ui-helpers.md +11 -11
- package/docs/v1/examples/advanced-patterns.md +1 -1
- package/docs/v1/examples/checkout-flow.md +1 -1
- package/docs/v1/getting-started/concepts.md +7 -7
- package/docs/v1/getting-started/installation.md +2 -2
- package/docs/v1/getting-started/quick-start.md +3 -3
- package/docs/v1/guides/address-component.md +11 -11
- package/docs/v1/guides/best-practices.md +14 -14
- package/docs/v1/guides/cart-component.md +23 -23
- package/docs/v1/guides/checkout-component.md +24 -24
- package/docs/v1/guides/events.md +812 -77
- package/docs/v1/guides/product-component.md +5 -5
- package/docs/v1/integration/nextjs.md +11 -2
- package/docs/v1/integration/react.md +3 -3
- package/docs/v1/integration/vanilla-js.md +1 -1
- package/docs/v1/integration/vue.md +24 -0
- package/docs/v1/reference/browser-support.md +9 -0
- package/docs/v1/reference/error-handling.md +2 -2
- package/docs/v1/reference/troubleshooting.md +10 -2
- package/package.json +13 -9
- package/dist/types/interfaces/core.interface.d.ts +0 -139
- package/docs/gitbook/actions.md +0 -160
- package/docs/gitbook/address.md +0 -48
- package/docs/gitbook/cart.md +0 -65
- package/docs/gitbook/checkout.md +0 -131
- package/docs/gitbook/events.md +0 -137
- package/docs/gitbook/overview.md +0 -166
- package/docs/gitbook/product.md +0 -64
- package/docs/gitbook/quick-start-guide.md +0 -393
|
@@ -23,10 +23,10 @@ cartButton(containerId: string, showItemsCount?: boolean): void
|
|
|
23
23
|
|
|
24
24
|
```javascript
|
|
25
25
|
// Simple cart button
|
|
26
|
-
window.elements.ui.cartButton('header-cart');
|
|
26
|
+
window.LiquidCommerce.elements.ui.cartButton('header-cart');
|
|
27
27
|
|
|
28
28
|
// Cart button with item count badge
|
|
29
|
-
window.elements.ui.cartButton('header-cart', true);
|
|
29
|
+
window.LiquidCommerce.elements.ui.cartButton('header-cart', true);
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
---
|
|
@@ -51,10 +51,10 @@ floatingCartButton(showItemsCount?: boolean): void
|
|
|
51
51
|
|
|
52
52
|
```javascript
|
|
53
53
|
// Floating button without badge
|
|
54
|
-
window.elements.ui.floatingCartButton();
|
|
54
|
+
window.LiquidCommerce.elements.ui.floatingCartButton();
|
|
55
55
|
|
|
56
56
|
// Floating button with badge
|
|
57
|
-
window.elements.ui.floatingCartButton(true);
|
|
57
|
+
window.LiquidCommerce.elements.ui.floatingCartButton(true);
|
|
58
58
|
```
|
|
59
59
|
|
|
60
60
|
---
|
|
@@ -82,7 +82,7 @@ cartSubtotal(elementId: string): void
|
|
|
82
82
|
```
|
|
83
83
|
|
|
84
84
|
```javascript
|
|
85
|
-
window.elements.ui.cartSubtotal('cart-total');
|
|
85
|
+
window.LiquidCommerce.elements.ui.cartSubtotal('cart-total');
|
|
86
86
|
// Element now shows: "$49.99"
|
|
87
87
|
// Updates automatically when cart changes
|
|
88
88
|
```
|
|
@@ -114,10 +114,10 @@ cartItemsCount(elementId: string, options?: { hideZero: boolean }): void
|
|
|
114
114
|
|
|
115
115
|
```javascript
|
|
116
116
|
// Hide when cart is empty
|
|
117
|
-
window.elements.ui.cartItemsCount('items-count', { hideZero: true });
|
|
117
|
+
window.LiquidCommerce.elements.ui.cartItemsCount('items-count', { hideZero: true });
|
|
118
118
|
|
|
119
119
|
// Always show count (even "0")
|
|
120
|
-
window.elements.ui.cartItemsCount('items-count', { hideZero: false });
|
|
120
|
+
window.LiquidCommerce.elements.ui.cartItemsCount('items-count', { hideZero: false });
|
|
121
121
|
```
|
|
122
122
|
|
|
123
123
|
## Use Cases
|
|
@@ -135,7 +135,7 @@ window.elements.ui.cartItemsCount('items-count', { hideZero: false });
|
|
|
135
135
|
|
|
136
136
|
<script>
|
|
137
137
|
window.addEventListener('lce:actions.client_ready', () => {
|
|
138
|
-
window.elements.ui.cartButton('cart-btn', true);
|
|
138
|
+
window.LiquidCommerce.elements.ui.cartButton('cart-btn', true);
|
|
139
139
|
});
|
|
140
140
|
</script>
|
|
141
141
|
```
|
|
@@ -151,8 +151,8 @@ window.addEventListener('lce:actions.client_ready', () => {
|
|
|
151
151
|
|
|
152
152
|
<script>
|
|
153
153
|
window.addEventListener('lce:actions.client_ready', () => {
|
|
154
|
-
window.elements.ui.cartItemsCount('item-count');
|
|
155
|
-
window.elements.ui.cartSubtotal('cart-total');
|
|
154
|
+
window.LiquidCommerce.elements.ui.cartItemsCount('item-count');
|
|
155
|
+
window.LiquidCommerce.elements.ui.cartSubtotal('cart-total');
|
|
156
156
|
});
|
|
157
157
|
</script>
|
|
158
158
|
```
|
|
@@ -162,7 +162,7 @@ window.addEventListener('lce:actions.client_ready', () => {
|
|
|
162
162
|
```javascript
|
|
163
163
|
// Show floating button only on mobile
|
|
164
164
|
if (window.innerWidth < 768) {
|
|
165
|
-
window.elements.ui.floatingCartButton(true);
|
|
165
|
+
window.LiquidCommerce.elements.ui.floatingCartButton(true);
|
|
166
166
|
}
|
|
167
167
|
```
|
|
168
168
|
|
|
@@ -22,7 +22,7 @@ await client.injectProductElement(
|
|
|
22
22
|
## 2) Pre-Set Address (Skip Prompt)
|
|
23
23
|
|
|
24
24
|
```javascript
|
|
25
|
-
await window.elements.actions.address.setAddressManually(
|
|
25
|
+
await window.LiquidCommerce.elements.actions.address.setAddressManually(
|
|
26
26
|
{
|
|
27
27
|
one: '123 Main St',
|
|
28
28
|
two: 'Apt 4',
|
|
@@ -75,7 +75,7 @@ When users click checkout, the cart redirects to your hosted checkout page with
|
|
|
75
75
|
## Optional: Skip Cart and Go Directly to Checkout
|
|
76
76
|
|
|
77
77
|
```javascript
|
|
78
|
-
await window.elements.actions.checkout.addProduct([
|
|
78
|
+
await window.LiquidCommerce.elements.actions.checkout.addProduct([
|
|
79
79
|
{
|
|
80
80
|
identifier: '00619947000020',
|
|
81
81
|
fulfillmentType: 'shipping',
|
|
@@ -72,7 +72,7 @@ When using the CDN, the SDK auto-initializes on page load:
|
|
|
72
72
|
></script>
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
The client becomes available globally
|
|
75
|
+
The client becomes available globally under `window.LiquidCommerce.elements`.
|
|
76
76
|
|
|
77
77
|
#### Programmatic Initialization (NPM)
|
|
78
78
|
|
|
@@ -115,7 +115,7 @@ window.addEventListener('lce:actions.client_ready', (event) => {
|
|
|
115
115
|
console.log('Ready at:', event.detail.timestamp);
|
|
116
116
|
|
|
117
117
|
// Safe to use client
|
|
118
|
-
window.elements.actions.cart.openCart();
|
|
118
|
+
window.LiquidCommerce.elements.actions.cart.openCart();
|
|
119
119
|
});
|
|
120
120
|
```
|
|
121
121
|
|
|
@@ -193,7 +193,7 @@ You can use declarative initialization and programmatic control:
|
|
|
193
193
|
<script>
|
|
194
194
|
// Later, add products programmatically
|
|
195
195
|
window.addEventListener('lce:actions.client_ready', async () => {
|
|
196
|
-
await window.elements.injectProductElement([
|
|
196
|
+
await window.LiquidCommerce.elements.injectProductElement([
|
|
197
197
|
{ containerId: 'dynamic-product', identifier: selectedProductId }
|
|
198
198
|
]);
|
|
199
199
|
});
|
|
@@ -236,7 +236,7 @@ When you update the cart in one tab, all other tabs update automatically:
|
|
|
236
236
|
|
|
237
237
|
```javascript
|
|
238
238
|
// Tab 1
|
|
239
|
-
await window.elements.actions.cart.addProduct([...]);
|
|
239
|
+
await window.LiquidCommerce.elements.actions.cart.addProduct([...]);
|
|
240
240
|
|
|
241
241
|
// Tab 2 automatically receives the update
|
|
242
242
|
// No additional code needed
|
|
@@ -261,14 +261,14 @@ Components automatically rerender when data changes:
|
|
|
261
261
|
|
|
262
262
|
```javascript
|
|
263
263
|
// This triggers a rerender
|
|
264
|
-
await window.elements.actions.cart.addProduct([...]);
|
|
264
|
+
await window.LiquidCommerce.elements.actions.cart.addProduct([...]);
|
|
265
265
|
// Cart component updates automatically
|
|
266
266
|
```
|
|
267
267
|
|
|
268
268
|
Manual rerendering:
|
|
269
269
|
|
|
270
270
|
```javascript
|
|
271
|
-
const components = window.elements.getInjectedComponents();
|
|
271
|
+
const components = window.LiquidCommerce.elements.getInjectedComponents();
|
|
272
272
|
const productComponent = components.get('product-1');
|
|
273
273
|
|
|
274
274
|
// Force rerender
|
|
@@ -337,7 +337,7 @@ SDK errors are caught and logged, but don't propagate to your application:
|
|
|
337
337
|
```javascript
|
|
338
338
|
// Even if SDK throws an error, your code continues
|
|
339
339
|
try {
|
|
340
|
-
await window.elements.actions.cart.addProduct([/* invalid data */]);
|
|
340
|
+
await window.LiquidCommerce.elements.actions.cart.addProduct([/* invalid data */]);
|
|
341
341
|
} catch (error) {
|
|
342
342
|
console.log('This error is caught by SDK internally');
|
|
343
343
|
}
|
|
@@ -237,7 +237,7 @@ export default function ProductPage() {
|
|
|
237
237
|
}
|
|
238
238
|
```
|
|
239
239
|
|
|
240
|
-
> **Note:**
|
|
240
|
+
> **Note:** The SDK is SSR-safe. When imported in a Node.js / SSR environment, a lightweight stub is resolved automatically — factory functions return `null` and no browser APIs are accessed. Initialize on the client (e.g., `useEffect`, `onMounted`) to get the real client.
|
|
241
241
|
|
|
242
242
|
## Configuration Options
|
|
243
243
|
|
|
@@ -267,7 +267,7 @@ Open your browser's console and check for:
|
|
|
267
267
|
|
|
268
268
|
```javascript
|
|
269
269
|
// The client is available globally
|
|
270
|
-
console.log(window.elements);
|
|
270
|
+
console.log(window.LiquidCommerce.elements);
|
|
271
271
|
// Should output: { injectProductElement: ƒ, ui: {...}, actions: {...}, ... }
|
|
272
272
|
```
|
|
273
273
|
|
|
@@ -156,7 +156,7 @@ If you prefer JavaScript over HTML attributes:
|
|
|
156
156
|
<script defer>
|
|
157
157
|
// Wait for SDK to be ready
|
|
158
158
|
window.addEventListener('lce:actions.client_ready', async (event) => {
|
|
159
|
-
const client = window.elements;
|
|
159
|
+
const client = window.LiquidCommerce.elements;
|
|
160
160
|
|
|
161
161
|
// Inject the product
|
|
162
162
|
await client.injectProductElement([
|
|
@@ -252,7 +252,7 @@ Want to customize the look, visit the Elements Builder in our [Partner Portal](h
|
|
|
252
252
|
```html
|
|
253
253
|
<script>
|
|
254
254
|
window.addEventListener('lce:actions.client_ready', async () => {
|
|
255
|
-
const client = window.elements;
|
|
255
|
+
const client = window.LiquidCommerce.elements;
|
|
256
256
|
|
|
257
257
|
// You can customize after initialization
|
|
258
258
|
// See Theming Guide for more options
|
|
@@ -313,7 +313,7 @@ The cart should open automatically after adding a product. If it doesn't:
|
|
|
313
313
|
|
|
314
314
|
1. Check browser console for JavaScript errors
|
|
315
315
|
2. Verify no other scripts are conflicting
|
|
316
|
-
3. Try manually opening: `window.elements.actions.cart.openCart()`
|
|
316
|
+
3. Try manually opening: `window.LiquidCommerce.elements.actions.cart.openCart()`
|
|
317
317
|
|
|
318
318
|
## Next Steps
|
|
319
319
|
|
|
@@ -52,7 +52,7 @@ await client.injectAddressElement('address-container', {
|
|
|
52
52
|
The recommended method - provides accurate geocoding:
|
|
53
53
|
|
|
54
54
|
```javascript
|
|
55
|
-
await window.elements.actions.address.setAddressByPlacesId('ChIJOwg_06VPwokRYv534QaPC8g');
|
|
55
|
+
await window.LiquidCommerce.elements.actions.address.setAddressByPlacesId('ChIJOwg_06VPwokRYv534QaPC8g');
|
|
56
56
|
```
|
|
57
57
|
|
|
58
58
|
**How to get a Places ID:**
|
|
@@ -64,7 +64,7 @@ Visit [Google Place IDs](https://developers.google.com/maps/documentation/places
|
|
|
64
64
|
For custom address flows without Google Places:
|
|
65
65
|
|
|
66
66
|
```javascript
|
|
67
|
-
await window.elements.actions.address.setAddressManually(
|
|
67
|
+
await window.LiquidCommerce.elements.actions.address.setAddressManually(
|
|
68
68
|
{
|
|
69
69
|
one: '123 Main Street',
|
|
70
70
|
two: 'Apt 4', // Optional
|
|
@@ -93,7 +93,7 @@ await window.elements.actions.address.setAddressManually(
|
|
|
93
93
|
Retrieve the current address:
|
|
94
94
|
|
|
95
95
|
```javascript
|
|
96
|
-
const addressData = window.elements.actions.address.getDetails();
|
|
96
|
+
const addressData = window.LiquidCommerce.elements.actions.address.getDetails();
|
|
97
97
|
|
|
98
98
|
console.log(addressData);
|
|
99
99
|
// {
|
|
@@ -120,7 +120,7 @@ console.log(addressData);
|
|
|
120
120
|
Remove the current address:
|
|
121
121
|
|
|
122
122
|
```javascript
|
|
123
|
-
await window.elements.actions.address.clear();
|
|
123
|
+
await window.LiquidCommerce.elements.actions.address.clear();
|
|
124
124
|
```
|
|
125
125
|
|
|
126
126
|
This will:
|
|
@@ -209,7 +209,7 @@ Create a dedicated page for address selection:
|
|
|
209
209
|
|
|
210
210
|
<script>
|
|
211
211
|
window.addEventListener('lce:actions.client_ready', async () => {
|
|
212
|
-
await window.elements.injectAddressElement('address');
|
|
212
|
+
await window.LiquidCommerce.elements.injectAddressElement('address');
|
|
213
213
|
});
|
|
214
214
|
|
|
215
215
|
window.addEventListener('lce:actions.address_updated', () => {
|
|
@@ -237,7 +237,7 @@ document.getElementById('save-address-btn').addEventListener('click', async () =
|
|
|
237
237
|
const coords = await geocodeAddress(address);
|
|
238
238
|
|
|
239
239
|
try {
|
|
240
|
-
await window.elements.actions.address.setAddressManually(address, coords);
|
|
240
|
+
await window.LiquidCommerce.elements.actions.address.setAddressManually(address, coords);
|
|
241
241
|
showSuccessMessage('Address saved!');
|
|
242
242
|
} catch (error) {
|
|
243
243
|
showErrorMessage('Invalid address');
|
|
@@ -251,7 +251,7 @@ document.getElementById('save-address-btn').addEventListener('click', async () =
|
|
|
251
251
|
// After user logs in, set their saved address
|
|
252
252
|
window.addEventListener('lce:actions.client_ready', async () => {
|
|
253
253
|
if (userIsLoggedIn && !currentAddressSet) {
|
|
254
|
-
await window.elements.actions.address.setAddressManually(
|
|
254
|
+
await window.LiquidCommerce.elements.actions.address.setAddressManually(
|
|
255
255
|
user.savedAddress,
|
|
256
256
|
user.savedCoordinates
|
|
257
257
|
);
|
|
@@ -288,7 +288,7 @@ const locations = [
|
|
|
288
288
|
document.getElementById('location-select').addEventListener('change', async (e) => {
|
|
289
289
|
const selectedLocation = locations[e.target.value];
|
|
290
290
|
|
|
291
|
-
await window.elements.actions.address.setAddressByPlacesId(
|
|
291
|
+
await window.LiquidCommerce.elements.actions.address.setAddressByPlacesId(
|
|
292
292
|
selectedLocation.placesId
|
|
293
293
|
);
|
|
294
294
|
|
|
@@ -328,7 +328,7 @@ Set address as early as possible in the user flow:
|
|
|
328
328
|
```javascript
|
|
329
329
|
// On homepage or landing page
|
|
330
330
|
window.addEventListener('lce:actions.client_ready', () => {
|
|
331
|
-
const currentAddress = window.elements.actions.address.getDetails();
|
|
331
|
+
const currentAddress = window.LiquidCommerce.elements.actions.address.getDetails();
|
|
332
332
|
|
|
333
333
|
if (!currentAddress) {
|
|
334
334
|
// Show address prompt
|
|
@@ -380,7 +380,7 @@ async function setAddress(address, coords) {
|
|
|
380
380
|
}
|
|
381
381
|
|
|
382
382
|
// Set address
|
|
383
|
-
await window.elements.actions.address.setAddressManually(address, coords);
|
|
383
|
+
await window.LiquidCommerce.elements.actions.address.setAddressManually(address, coords);
|
|
384
384
|
}
|
|
385
385
|
```
|
|
386
386
|
|
|
@@ -388,7 +388,7 @@ async function setAddress(address, coords) {
|
|
|
388
388
|
|
|
389
389
|
```javascript
|
|
390
390
|
try {
|
|
391
|
-
await window.elements.actions.address.setAddressByPlacesId(placesId);
|
|
391
|
+
await window.LiquidCommerce.elements.actions.address.setAddressByPlacesId(placesId);
|
|
392
392
|
} catch (error) {
|
|
393
393
|
console.error('Failed to set address:', error);
|
|
394
394
|
|
|
@@ -21,26 +21,26 @@ await Elements('KEY', { env: 'production' });
|
|
|
21
21
|
|
|
22
22
|
### Use Global Access
|
|
23
23
|
|
|
24
|
-
After initialization, use `window.elements`:
|
|
24
|
+
After initialization, use `window.LiquidCommerce.elements`:
|
|
25
25
|
|
|
26
26
|
```javascript
|
|
27
27
|
// Initialize once
|
|
28
28
|
await Elements('KEY', { env: 'production' });
|
|
29
29
|
|
|
30
30
|
// Use globally throughout your app
|
|
31
|
-
window.elements.actions.cart.openCart();
|
|
31
|
+
window.LiquidCommerce.elements.actions.cart.openCart();
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
### Wait for Client Ready
|
|
35
35
|
|
|
36
36
|
```javascript
|
|
37
|
-
if (window.elements) {
|
|
37
|
+
if (window.LiquidCommerce.elements) {
|
|
38
38
|
// Client already ready
|
|
39
|
-
window.elements.actions.cart.openCart();
|
|
39
|
+
window.LiquidCommerce.elements.actions.cart.openCart();
|
|
40
40
|
} else {
|
|
41
41
|
// Wait for initialization
|
|
42
42
|
window.addEventListener('lce:actions.client_ready', () => {
|
|
43
|
-
window.elements.actions.cart.openCart();
|
|
43
|
+
window.LiquidCommerce.elements.actions.cart.openCart();
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
```
|
|
@@ -83,7 +83,7 @@ await client.injectProductElement([...]);
|
|
|
83
83
|
|
|
84
84
|
```javascript
|
|
85
85
|
try {
|
|
86
|
-
await window.elements.actions.cart.addProduct([...]);
|
|
86
|
+
await window.LiquidCommerce.elements.actions.cart.addProduct([...]);
|
|
87
87
|
} catch (error) {
|
|
88
88
|
if (error.name === 'SDKError') {
|
|
89
89
|
console.error('SDK Error:', error);
|
|
@@ -158,7 +158,7 @@ setTimeout(async () => {
|
|
|
158
158
|
```javascript
|
|
159
159
|
// Set address if known
|
|
160
160
|
if (userSavedAddress) {
|
|
161
|
-
await window.elements.actions.address.setAddressManually(
|
|
161
|
+
await window.LiquidCommerce.elements.actions.address.setAddressManually(
|
|
162
162
|
userSavedAddress,
|
|
163
163
|
userCoordinates
|
|
164
164
|
);
|
|
@@ -167,7 +167,7 @@ if (userSavedAddress) {
|
|
|
167
167
|
// Pre-fill checkout info
|
|
168
168
|
window.addEventListener('lce:actions.checkout_opened', () => {
|
|
169
169
|
if (userIsLoggedIn) {
|
|
170
|
-
window.elements.actions.checkout.updateCustomerInfo({
|
|
170
|
+
window.LiquidCommerce.elements.actions.checkout.updateCustomerInfo({
|
|
171
171
|
firstName: user.firstName,
|
|
172
172
|
email: user.email
|
|
173
173
|
});
|
|
@@ -183,7 +183,7 @@ Cart persists across sessions - avoid clearing unless intentional:
|
|
|
183
183
|
// Only clear when user explicitly requests
|
|
184
184
|
document.getElementById('clear-cart-btn').addEventListener('click', async () => {
|
|
185
185
|
if (confirm('Clear cart?')) {
|
|
186
|
-
await window.elements.actions.cart.resetCart();
|
|
186
|
+
await window.LiquidCommerce.elements.actions.cart.resetCart();
|
|
187
187
|
}
|
|
188
188
|
});
|
|
189
189
|
```
|
|
@@ -195,7 +195,7 @@ document.getElementById('clear-cart-btn').addEventListener('click', async () =>
|
|
|
195
195
|
```javascript
|
|
196
196
|
// Update UI when cart changes
|
|
197
197
|
window.addEventListener('lce:actions.cart_updated', () => {
|
|
198
|
-
const cart = window.elements.actions.cart.getDetails();
|
|
198
|
+
const cart = window.LiquidCommerce.elements.actions.cart.getDetails();
|
|
199
199
|
updateHeaderCartCount(cart.itemsCount);
|
|
200
200
|
});
|
|
201
201
|
```
|
|
@@ -267,11 +267,11 @@ const client = await Elements('YOUR_API_KEY', {
|
|
|
267
267
|
```javascript
|
|
268
268
|
// Test empty cart
|
|
269
269
|
if (isDevelopment) {
|
|
270
|
-
await window.elements.actions.cart.resetCart();
|
|
270
|
+
await window.LiquidCommerce.elements.actions.cart.resetCart();
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
// Test with specific product
|
|
274
|
-
await window.elements.actions.cart.addProduct([
|
|
274
|
+
await window.LiquidCommerce.elements.actions.cart.addProduct([
|
|
275
275
|
{ identifier: testProductId, fulfillmentType: 'shipping', quantity: 1 }
|
|
276
276
|
]);
|
|
277
277
|
```
|
|
@@ -311,9 +311,9 @@ await window.elements.actions.cart.addProduct([
|
|
|
311
311
|
|
|
312
312
|
```javascript
|
|
313
313
|
if (window.innerWidth < 768) {
|
|
314
|
-
window.elements.ui.floatingCartButton(true);
|
|
314
|
+
window.LiquidCommerce.elements.ui.floatingCartButton(true);
|
|
315
315
|
} else {
|
|
316
|
-
window.elements.ui.cartButton('header-cart', true);
|
|
316
|
+
window.LiquidCommerce.elements.ui.cartButton('header-cart', true);
|
|
317
317
|
}
|
|
318
318
|
```
|
|
319
319
|
|
|
@@ -113,13 +113,13 @@ Create cart buttons using JavaScript:
|
|
|
113
113
|
|
|
114
114
|
```javascript
|
|
115
115
|
// Button in a container
|
|
116
|
-
window.elements.ui.cartButton('my-container', false); // No badge
|
|
116
|
+
window.LiquidCommerce.elements.ui.cartButton('my-container', false); // No badge
|
|
117
117
|
|
|
118
118
|
// Button with item count
|
|
119
|
-
window.elements.ui.cartButton('my-container', true); // With badge
|
|
119
|
+
window.LiquidCommerce.elements.ui.cartButton('my-container', true); // With badge
|
|
120
120
|
|
|
121
121
|
// Floating button
|
|
122
|
-
window.elements.ui.floatingCartButton(true); // With badge
|
|
122
|
+
window.LiquidCommerce.elements.ui.floatingCartButton(true); // With badge
|
|
123
123
|
```
|
|
124
124
|
|
|
125
125
|
### Custom Toggle Buttons
|
|
@@ -139,19 +139,19 @@ The SDK automatically adds click handlers to elements with `data-lce-cart-toggle
|
|
|
139
139
|
### Open Cart
|
|
140
140
|
|
|
141
141
|
```javascript
|
|
142
|
-
window.elements.actions.cart.openCart();
|
|
142
|
+
window.LiquidCommerce.elements.actions.cart.openCart();
|
|
143
143
|
```
|
|
144
144
|
|
|
145
145
|
### Close Cart
|
|
146
146
|
|
|
147
147
|
```javascript
|
|
148
|
-
window.elements.actions.cart.closeCart();
|
|
148
|
+
window.LiquidCommerce.elements.actions.cart.closeCart();
|
|
149
149
|
```
|
|
150
150
|
|
|
151
151
|
### Toggle Cart
|
|
152
152
|
|
|
153
153
|
```javascript
|
|
154
|
-
window.elements.actions.cart.toggleCart();
|
|
154
|
+
window.LiquidCommerce.elements.actions.cart.toggleCart();
|
|
155
155
|
```
|
|
156
156
|
|
|
157
157
|
### Add Product to Cart
|
|
@@ -159,7 +159,7 @@ window.elements.actions.cart.toggleCart();
|
|
|
159
159
|
Add products programmatically:
|
|
160
160
|
|
|
161
161
|
```javascript
|
|
162
|
-
await window.elements.actions.cart.addProduct([
|
|
162
|
+
await window.LiquidCommerce.elements.actions.cart.addProduct([
|
|
163
163
|
{
|
|
164
164
|
identifier: '00619947000020',
|
|
165
165
|
fulfillmentType: 'shipping', // or 'onDemand'
|
|
@@ -182,7 +182,7 @@ await window.elements.actions.cart.addProduct([
|
|
|
182
182
|
### Apply Promo Code
|
|
183
183
|
|
|
184
184
|
```javascript
|
|
185
|
-
await window.elements.actions.cart.applyPromoCode('SUMMER20');
|
|
185
|
+
await window.LiquidCommerce.elements.actions.cart.applyPromoCode('SUMMER20');
|
|
186
186
|
```
|
|
187
187
|
|
|
188
188
|
The SDK automatically:
|
|
@@ -194,7 +194,7 @@ The SDK automatically:
|
|
|
194
194
|
### Remove Promo Code
|
|
195
195
|
|
|
196
196
|
```javascript
|
|
197
|
-
await window.elements.actions.cart.removePromoCode();
|
|
197
|
+
await window.LiquidCommerce.elements.actions.cart.removePromoCode();
|
|
198
198
|
```
|
|
199
199
|
|
|
200
200
|
### Reset Cart
|
|
@@ -202,7 +202,7 @@ await window.elements.actions.cart.removePromoCode();
|
|
|
202
202
|
Clear all items from the cart:
|
|
203
203
|
|
|
204
204
|
```javascript
|
|
205
|
-
await window.elements.actions.cart.resetCart();
|
|
205
|
+
await window.LiquidCommerce.elements.actions.cart.resetCart();
|
|
206
206
|
```
|
|
207
207
|
|
|
208
208
|
### Get Cart Details
|
|
@@ -210,7 +210,7 @@ await window.elements.actions.cart.resetCart();
|
|
|
210
210
|
Retrieve current cart information:
|
|
211
211
|
|
|
212
212
|
```javascript
|
|
213
|
-
const cartData = window.elements.actions.cart.getDetails();
|
|
213
|
+
const cartData = window.LiquidCommerce.elements.actions.cart.getDetails();
|
|
214
214
|
|
|
215
215
|
console.log(cartData);
|
|
216
216
|
// {
|
|
@@ -239,7 +239,7 @@ Show cart subtotal anywhere on your page:
|
|
|
239
239
|
|
|
240
240
|
<script>
|
|
241
241
|
window.addEventListener('lce:actions.client_ready', () => {
|
|
242
|
-
window.elements.ui.cartSubtotal('cart-total');
|
|
242
|
+
window.LiquidCommerce.elements.ui.cartSubtotal('cart-total');
|
|
243
243
|
});
|
|
244
244
|
</script>
|
|
245
245
|
```
|
|
@@ -257,7 +257,7 @@ Show the number of items in the cart:
|
|
|
257
257
|
|
|
258
258
|
<script>
|
|
259
259
|
window.addEventListener('lce:actions.client_ready', () => {
|
|
260
|
-
window.elements.ui.cartItemsCount('items-count', {
|
|
260
|
+
window.LiquidCommerce.elements.ui.cartItemsCount('items-count', {
|
|
261
261
|
hideZero: true // Hide when cart is empty
|
|
262
262
|
});
|
|
263
263
|
});
|
|
@@ -425,7 +425,7 @@ When you update the cart in one tab, all other open tabs automatically sync:
|
|
|
425
425
|
|
|
426
426
|
```javascript
|
|
427
427
|
// Tab 1: Add item
|
|
428
|
-
await window.elements.actions.cart.addProduct([...]);
|
|
428
|
+
await window.LiquidCommerce.elements.actions.cart.addProduct([...]);
|
|
429
429
|
|
|
430
430
|
// Tab 2: Cart automatically updates
|
|
431
431
|
// No additional code needed
|
|
@@ -459,10 +459,10 @@ If no address is set when adding to cart, the SDK:
|
|
|
459
459
|
Set address before adding to cart:
|
|
460
460
|
|
|
461
461
|
```javascript
|
|
462
|
-
await window.elements.actions.address.setAddressByPlacesId('ChIJ...');
|
|
462
|
+
await window.LiquidCommerce.elements.actions.address.setAddressByPlacesId('ChIJ...');
|
|
463
463
|
|
|
464
464
|
// Now add to cart
|
|
465
|
-
await window.elements.actions.cart.addProduct([...]);
|
|
465
|
+
await window.LiquidCommerce.elements.actions.cart.addProduct([...]);
|
|
466
466
|
```
|
|
467
467
|
|
|
468
468
|
## Promo Codes
|
|
@@ -627,8 +627,8 @@ const params = new URLSearchParams(window.location.search);
|
|
|
627
627
|
const campaign = params.get('campaign');
|
|
628
628
|
|
|
629
629
|
if (campaign === 'summer-sale') {
|
|
630
|
-
await window.elements.actions.cart.applyPromoCode('SUMMER20');
|
|
631
|
-
window.elements.actions.cart.openCart();
|
|
630
|
+
await window.LiquidCommerce.elements.actions.cart.applyPromoCode('SUMMER20');
|
|
631
|
+
window.LiquidCommerce.elements.actions.cart.openCart();
|
|
632
632
|
}
|
|
633
633
|
```
|
|
634
634
|
|
|
@@ -658,7 +658,7 @@ Pre-load cart on page load for faster access:
|
|
|
658
658
|
```javascript
|
|
659
659
|
window.addEventListener('lce:actions.client_ready', () => {
|
|
660
660
|
// Cart loads automatically, but you can pre-fetch if needed
|
|
661
|
-
window.elements.actions.cart.getDetails();
|
|
661
|
+
window.LiquidCommerce.elements.actions.cart.getDetails();
|
|
662
662
|
});
|
|
663
663
|
```
|
|
664
664
|
|
|
@@ -673,7 +673,7 @@ async function addToCart(productId) {
|
|
|
673
673
|
button.textContent = 'Adding...';
|
|
674
674
|
|
|
675
675
|
try {
|
|
676
|
-
await window.elements.actions.cart.addProduct([
|
|
676
|
+
await window.LiquidCommerce.elements.actions.cart.addProduct([
|
|
677
677
|
{ identifier: productId, fulfillmentType: 'shipping', quantity: 1 }
|
|
678
678
|
], true);
|
|
679
679
|
|
|
@@ -709,14 +709,14 @@ window.addEventListener('lce:actions.cart_updated', (event) => {
|
|
|
709
709
|
|
|
710
710
|
### Cart Not Opening
|
|
711
711
|
|
|
712
|
-
1. Check that SDK is initialized: `console.log(window.elements)`
|
|
712
|
+
1. Check that SDK is initialized: `console.log(window.LiquidCommerce.elements)`
|
|
713
713
|
2. Verify no JavaScript errors in console
|
|
714
714
|
3. Ensure cart button is properly configured
|
|
715
|
-
4. Try manually: `window.elements.actions.cart.openCart()`
|
|
715
|
+
4. Try manually: `window.LiquidCommerce.elements.actions.cart.openCart()`
|
|
716
716
|
|
|
717
717
|
### Items Not Adding
|
|
718
718
|
|
|
719
|
-
1. Check that address is set: `window.elements.actions.address.getDetails()`
|
|
719
|
+
1. Check that address is set: `window.LiquidCommerce.elements.actions.address.getDetails()`
|
|
720
720
|
2. Verify product identifier is valid
|
|
721
721
|
3. Check fulfillment type is available for the product
|
|
722
722
|
4. Look for errors in browser console
|