@liquidcommerce/elements-sdk 2.7.9 → 2.7.11
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/dist/index.checkout.esm.js +7126 -7095
- package/dist/index.esm.js +11290 -11198
- package/dist/types/clients/helpers.d.ts +1 -0
- package/dist/types/interfaces/api/cart.interface.d.ts +1 -0
- package/dist/types/interfaces/api/checkout.interface.d.ts +1 -0
- package/dist/types/interfaces/api/product.interface.d.ts +1 -0
- package/dist/types/interfaces/configs/product.interface.d.ts +2 -0
- package/dist/types/modules/product/components/product-add-to-cart-section.component.d.ts +1 -0
- package/dist/types/modules/product/components/product-description.component.d.ts +1 -0
- package/dist/types/modules/product/components/product-options.component.d.ts +2 -1
- package/dist/types/modules/ui-components/engraving/engraving-view.component.d.ts +1 -0
- package/docs/v1/api/actions/checkout-actions.md +40 -0
- package/docs/v1/api/actions/product-actions.md +44 -1
- package/docs/v1/api/client.md +13 -0
- package/docs/v1/api/configuration.md +528 -1
- package/docs/v1/api/injection-methods.md +18 -4
- package/docs/v1/api/typescript-types.md +398 -1
- package/docs/v1/examples/advanced-patterns.md +102 -0
- package/docs/v1/guides/best-practices.md +29 -0
- package/docs/v1/guides/product-list-component.md +70 -161
- package/docs/v1/reference/troubleshooting.md +64 -0
- package/package.json +7 -11
|
@@ -1 +1,398 @@
|
|
|
1
|
-
|
|
1
|
+
# TypeScript Types Reference
|
|
2
|
+
|
|
3
|
+
All public types are exported from the main package entry point. Import them using the `type` keyword for optimal tree-shaking.
|
|
4
|
+
|
|
5
|
+
## Importing Types
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { Elements } from '@liquidcommerce/elements-sdk';
|
|
9
|
+
import type {
|
|
10
|
+
ILiquidCommerceElementsClient,
|
|
11
|
+
ILiquidCommerceElementsConfig,
|
|
12
|
+
IInjectProductElement,
|
|
13
|
+
IInjectedComponent
|
|
14
|
+
} from '@liquidcommerce/elements-sdk';
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
For the checkout-only build:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { ElementsCheckout } from '@liquidcommerce/elements-sdk/checkout';
|
|
21
|
+
import type {
|
|
22
|
+
IElementsCheckoutClient,
|
|
23
|
+
IElementsCheckoutActions,
|
|
24
|
+
ILiquidCommerceElementsCheckoutClientConfig,
|
|
25
|
+
IInjectedComponent
|
|
26
|
+
} from '@liquidcommerce/elements-sdk/checkout';
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Client Types
|
|
32
|
+
|
|
33
|
+
### ILiquidCommerceElementsClient
|
|
34
|
+
|
|
35
|
+
Main SDK client interface returned by `Elements()`.
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
interface ILiquidCommerceElementsClient {
|
|
39
|
+
injectProductElement(params: IInjectProductElement[]): Promise<IInjectedComponent[]>;
|
|
40
|
+
injectAddressElement(containerId: string, options?: IAddressOptions): Promise<IInjectedComponent | null>;
|
|
41
|
+
injectCartElement(containerId: string): Promise<IInjectedComponent | null>;
|
|
42
|
+
injectCheckoutElement(params: IInjectCheckoutParams): Promise<IInjectedComponent | null>;
|
|
43
|
+
injectProductList(params: IInjectProductListParams): Promise<void>;
|
|
44
|
+
injectProductListSearch(params: IInjectProductListSearchParams): Promise<void>;
|
|
45
|
+
injectProductListFilters(params: IInjectProductListFiltersParams): Promise<void>;
|
|
46
|
+
ui: ILiquidCommerceElementsUIMethod;
|
|
47
|
+
actions: ILiquidCommerceElementsActions;
|
|
48
|
+
getInjectedComponents(): Map<string, IInjectedComponent>;
|
|
49
|
+
destroy(): void;
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### ILiquidCommerceElementsBuilderClient
|
|
54
|
+
|
|
55
|
+
Builder-pattern client interface returned by `ElementsBuilder()`.
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
interface ILiquidCommerceElementsBuilderClient {
|
|
59
|
+
updateComponentGlobalConfigs(configs: UpdateComponentGlobalConfigs): Promise<void>;
|
|
60
|
+
updateProductComponent(configs: UpdateProductComponent): Promise<void>;
|
|
61
|
+
updateAddressComponent(configs: UpdateAddressComponent): void;
|
|
62
|
+
updateCartComponent(configs: UpdateCartComponent): void;
|
|
63
|
+
updateCheckoutComponent(configs: UpdateCheckoutComponent): void;
|
|
64
|
+
updateProductListComponent(configs: UpdateProductListComponent): void;
|
|
65
|
+
injectElement(params: IBuilderInjectElementParams): Promise<IInjectedComponent | null>;
|
|
66
|
+
injectProductElement(params: IInjectProductElement[]): Promise<IInjectedComponent[]>;
|
|
67
|
+
injectAddressElement(containerId: string, options?: IAddressOptions): Promise<IInjectedComponent | null>;
|
|
68
|
+
injectCartElement(containerId: string): Promise<IInjectedComponent | null>;
|
|
69
|
+
injectCheckoutElement(params: IInjectCheckoutBuilderParams): Promise<IInjectedComponent | null>;
|
|
70
|
+
injectProductList(params: IInjectProductListParams): Promise<void>;
|
|
71
|
+
actions: ILiquidCommerceElementsActions;
|
|
72
|
+
destroy(): void;
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### IElementsCheckoutClient
|
|
77
|
+
|
|
78
|
+
Checkout-only client interface returned by `ElementsCheckout()`.
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
interface IElementsCheckoutClient {
|
|
82
|
+
injectCheckout(params: IInjectCheckoutParams): Promise<IInjectedComponent | null>;
|
|
83
|
+
actions: { checkout: IElementsCheckoutActions };
|
|
84
|
+
destroy(): void;
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Configuration Types
|
|
91
|
+
|
|
92
|
+
### ILiquidCommerceElementsConfig
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
interface ILiquidCommerceElementsConfig {
|
|
96
|
+
env?: ElementsEnv;
|
|
97
|
+
promoTicker?: IPromoTicker[];
|
|
98
|
+
customTheme?: IClientCustomThemeConfig;
|
|
99
|
+
debugMode?: DebugMode;
|
|
100
|
+
checkout?: ILiquidCommerceElementsCheckoutConfig;
|
|
101
|
+
proxy?: IElementsProxyConfig;
|
|
102
|
+
development?: ILiquidCommerceElementsDevelopmentConfig;
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### ILiquidCommerceElementsCheckoutClientConfig
|
|
107
|
+
|
|
108
|
+
Same shape as `ILiquidCommerceElementsConfig`, used for the checkout-only client.
|
|
109
|
+
|
|
110
|
+
### IClientCustomThemeConfig
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
interface IClientCustomThemeConfig {
|
|
114
|
+
global?: UpdateComponentGlobalConfigs;
|
|
115
|
+
product?: UpdateProductComponent;
|
|
116
|
+
address?: UpdateAddressComponent;
|
|
117
|
+
cart?: UpdateCartComponent;
|
|
118
|
+
checkout?: UpdateCheckoutComponent;
|
|
119
|
+
productList?: UpdateProductListComponent;
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### IElementsProxyConfig
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
interface IElementsProxyConfig {
|
|
127
|
+
baseUrl: string;
|
|
128
|
+
headers?: Record<string, string>;
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### ILiquidCommerceElementsDevelopmentConfig
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
interface ILiquidCommerceElementsDevelopmentConfig {
|
|
136
|
+
customApiUrl?: string;
|
|
137
|
+
paymentMethodId?: string;
|
|
138
|
+
openShadowDom?: boolean;
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### ILiquidCommerceElementsCheckoutConfig
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
interface ILiquidCommerceElementsCheckoutConfig {
|
|
146
|
+
pageUrl?: string;
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
See [Configuration Reference](./configuration.md) for detailed property descriptions.
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Injection Types
|
|
155
|
+
|
|
156
|
+
### IInjectProductElement
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
interface IInjectProductElement {
|
|
160
|
+
containerId: string;
|
|
161
|
+
identifier: string;
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### IInjectCheckoutParams
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
interface IInjectCheckoutParams {
|
|
169
|
+
containerId: string;
|
|
170
|
+
checkoutId?: string;
|
|
171
|
+
hideHeader?: boolean;
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### IInjectCheckoutBuilderParams
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
interface IInjectCheckoutBuilderParams extends IInjectCheckoutParams {
|
|
179
|
+
simulatePresale?: boolean;
|
|
180
|
+
presaleExpiresInMinutes?: number;
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### IInjectProductListParams
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
interface IInjectProductListParams {
|
|
188
|
+
containerId: string;
|
|
189
|
+
slug: string;
|
|
190
|
+
rows?: number;
|
|
191
|
+
columns?: number;
|
|
192
|
+
filters?: ProductListFilterType[];
|
|
193
|
+
productUrl?: string;
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### IInjectProductListSearchParams
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
interface IInjectProductListSearchParams {
|
|
201
|
+
containerId: string;
|
|
202
|
+
slug: string;
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### IInjectProductListFiltersParams
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
interface IInjectProductListFiltersParams {
|
|
210
|
+
containerId: string;
|
|
211
|
+
slug: string;
|
|
212
|
+
filters?: ProductListFilterType[];
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### IBuilderInjectElementParams
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
interface IBuilderInjectElementParams {
|
|
220
|
+
type: ComponentType;
|
|
221
|
+
containerId: string;
|
|
222
|
+
[key: string]: any;
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Component Types
|
|
229
|
+
|
|
230
|
+
### IInjectedComponent
|
|
231
|
+
|
|
232
|
+
Returned by all injection methods. Provides control over the injected component.
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
interface IInjectedComponent {
|
|
236
|
+
getType(): ComponentType;
|
|
237
|
+
getElement(): HTMLElement;
|
|
238
|
+
rerender(): void;
|
|
239
|
+
destroy(): void;
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## UI Types
|
|
246
|
+
|
|
247
|
+
### ILiquidCommerceElementsUIMethod
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
interface ILiquidCommerceElementsUIMethod {
|
|
251
|
+
cartButton(containerId: string, showItemsCount?: boolean): void;
|
|
252
|
+
floatingCartButton(showItemsCount?: boolean): void;
|
|
253
|
+
cartSubtotal(elementId: string): void;
|
|
254
|
+
cartItemsCount(elementId: string, options?: { hideZero: boolean }): void;
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## Action Types
|
|
261
|
+
|
|
262
|
+
### ILiquidCommerceElementsActions
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
interface ILiquidCommerceElementsActions {
|
|
266
|
+
product: IProductActions;
|
|
267
|
+
address: IAddressActions;
|
|
268
|
+
cart: ICartActions;
|
|
269
|
+
checkout: ICheckoutActions;
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### IElementsCheckoutActions
|
|
274
|
+
|
|
275
|
+
Checkout actions available in the checkout-only client. Omits drawer-related methods.
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
interface IElementsCheckoutActions extends Omit<ICheckoutActions, 'openCheckout' | 'closeCheckout' | 'toggleCheckout'> {}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
See [Actions API](./actions/) for detailed method signatures.
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## Enum Types
|
|
286
|
+
|
|
287
|
+
### ElementsEnv
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
type ElementsEnv = 'development' | 'staging' | 'production';
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### DebugMode
|
|
294
|
+
|
|
295
|
+
```typescript
|
|
296
|
+
type DebugMode = 'none' | 'console' | 'panel';
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### FulfillmentType
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
type FulfillmentType = 'onDemand' | 'shipping';
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### ComponentType
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
type ComponentType =
|
|
309
|
+
| 'address' | 'product' | 'cart' | 'checkout'
|
|
310
|
+
| 'product-list' | 'product-list-card' | 'product-list-filters' | 'product-list-search'
|
|
311
|
+
| 'drawer' | 'input' | 'engraving-form' | 'engraving-view'
|
|
312
|
+
| 'buttons-cart-open' | 'powered-by' | 'lce-element'
|
|
313
|
+
| 'purchase-min-alert' | 'alert' | 'promo-code-ticker'
|
|
314
|
+
// ...and additional internal component types
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### DisplayModeType
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
type DisplayModeType = 'modal' | 'drawer';
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
## Theme Configuration Types
|
|
326
|
+
|
|
327
|
+
### UpdateComponentGlobalConfigs
|
|
328
|
+
|
|
329
|
+
`DeepPartial<IComponentGlobalConfigs>` -- all properties optional.
|
|
330
|
+
|
|
331
|
+
### UpdateProductComponent
|
|
332
|
+
|
|
333
|
+
`DeepPartial<IProductComponent>` -- all properties optional.
|
|
334
|
+
|
|
335
|
+
### UpdateCartComponent
|
|
336
|
+
|
|
337
|
+
`DeepPartial<ICartComponent>` -- all properties optional.
|
|
338
|
+
|
|
339
|
+
### UpdateCheckoutComponent
|
|
340
|
+
|
|
341
|
+
`DeepPartial<ICheckoutComponent>` -- all properties optional.
|
|
342
|
+
|
|
343
|
+
### UpdateAddressComponent
|
|
344
|
+
|
|
345
|
+
`DeepPartial<IAddressComponent>` -- all properties optional.
|
|
346
|
+
|
|
347
|
+
### UpdateProductListComponent
|
|
348
|
+
|
|
349
|
+
Special structure for updating product list configuration by slug:
|
|
350
|
+
|
|
351
|
+
```typescript
|
|
352
|
+
interface UpdateProductListComponent {
|
|
353
|
+
theme?: { backgroundColor?: string };
|
|
354
|
+
layout?: {
|
|
355
|
+
lists?: Record<string, DeepPartial<IPLCList>>;
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
See [Configuration Reference](./configuration.md) for detailed theme property descriptions.
|
|
361
|
+
|
|
362
|
+
---
|
|
363
|
+
|
|
364
|
+
## Promo Ticker Type
|
|
365
|
+
|
|
366
|
+
### IPromoTicker
|
|
367
|
+
|
|
368
|
+
```typescript
|
|
369
|
+
interface IPromoTicker {
|
|
370
|
+
promoCode: string;
|
|
371
|
+
text: string[];
|
|
372
|
+
separator: string;
|
|
373
|
+
activeFrom: string; // ISO 8601 UTC
|
|
374
|
+
activeUntil: string; // ISO 8601 UTC
|
|
375
|
+
}
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
380
|
+
## Utility Types
|
|
381
|
+
|
|
382
|
+
### DeepPartial
|
|
383
|
+
|
|
384
|
+
Used internally for theme update types. Makes all properties in `T` recursively optional.
|
|
385
|
+
|
|
386
|
+
```typescript
|
|
387
|
+
type DeepPartial<T> = {
|
|
388
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
389
|
+
};
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
---
|
|
393
|
+
|
|
394
|
+
## See Also
|
|
395
|
+
|
|
396
|
+
- [Client API](./client.md) - Client initialization and usage
|
|
397
|
+
- [Configuration Reference](./configuration.md) - Detailed config options
|
|
398
|
+
- [Injection Methods](./injection-methods.md) - Component injection API
|
|
@@ -88,6 +88,108 @@ const client = await Elements('YOUR_API_KEY', {
|
|
|
88
88
|
});
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
+
## 7) Cleanup on SPA Navigation
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
let client = null;
|
|
95
|
+
|
|
96
|
+
async function mountElements() {
|
|
97
|
+
client = await Elements('YOUR_API_KEY', { env: 'production' });
|
|
98
|
+
await client.injectProductElement([
|
|
99
|
+
{ containerId: 'product', identifier: '00619947000020' }
|
|
100
|
+
]);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function unmountElements() {
|
|
104
|
+
if (client) {
|
|
105
|
+
client.destroy();
|
|
106
|
+
client = null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// React example
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
mountElements();
|
|
113
|
+
return () => unmountElements();
|
|
114
|
+
}, []);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## 8) Checkout-Only Page
|
|
118
|
+
|
|
119
|
+
For a dedicated checkout page, use the tree-shaken checkout build:
|
|
120
|
+
|
|
121
|
+
```javascript
|
|
122
|
+
import { ElementsCheckout } from '@liquidcommerce/elements-sdk/checkout';
|
|
123
|
+
|
|
124
|
+
const client = await ElementsCheckout('YOUR_API_KEY', {
|
|
125
|
+
env: 'production'
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
await client.injectCheckout({
|
|
129
|
+
containerId: 'checkout',
|
|
130
|
+
checkoutId: new URLSearchParams(window.location.search).get('lce_checkout'),
|
|
131
|
+
hideHeader: false
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## 9) Promo Ticker with Time Windows
|
|
136
|
+
|
|
137
|
+
```javascript
|
|
138
|
+
const client = await Elements('YOUR_API_KEY', {
|
|
139
|
+
env: 'production',
|
|
140
|
+
promoTicker: [
|
|
141
|
+
{
|
|
142
|
+
promoCode: 'SUMMER20',
|
|
143
|
+
text: ['20% Off Summer Sale', 'Free Shipping on $50+'],
|
|
144
|
+
separator: '|',
|
|
145
|
+
activeFrom: '2026-06-01T00:00:00Z',
|
|
146
|
+
activeUntil: '2026-08-31T23:59:59Z'
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
promoCode: 'FALL10',
|
|
150
|
+
text: ['10% Off Fall Collection'],
|
|
151
|
+
separator: '|',
|
|
152
|
+
activeFrom: '2026-09-01T00:00:00Z',
|
|
153
|
+
activeUntil: '2026-11-30T23:59:59Z'
|
|
154
|
+
}
|
|
155
|
+
]
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## 10) Product List with Filters and Search
|
|
160
|
+
|
|
161
|
+
```javascript
|
|
162
|
+
const client = await Elements('YOUR_API_KEY', { env: 'production' });
|
|
163
|
+
|
|
164
|
+
await client.injectProductListSearch({
|
|
165
|
+
containerId: 'search-box',
|
|
166
|
+
slug: 'whiskey-collection'
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
await client.injectProductListFilters({
|
|
170
|
+
containerId: 'sidebar-filters',
|
|
171
|
+
slug: 'whiskey-collection',
|
|
172
|
+
filters: ['price', 'brands', 'sizes', 'fulfillment']
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
await client.injectProductList({
|
|
176
|
+
containerId: 'product-grid',
|
|
177
|
+
slug: 'whiskey-collection',
|
|
178
|
+
rows: 4,
|
|
179
|
+
columns: 3,
|
|
180
|
+
productUrl: '/products/{identifier}'
|
|
181
|
+
});
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## 11) Check Product Availability by State
|
|
185
|
+
|
|
186
|
+
```javascript
|
|
187
|
+
const availability = await window.LiquidCommerce.elements.actions.product
|
|
188
|
+
.getProductAvailabilityByState(['00619947000020', '08504405135'], 'CA');
|
|
189
|
+
|
|
190
|
+
console.log('Availability in CA:', availability);
|
|
191
|
+
```
|
|
192
|
+
|
|
91
193
|
## Related Docs
|
|
92
194
|
|
|
93
195
|
- [Events Guide](../guides/events.md)
|
|
@@ -188,6 +188,35 @@ document.getElementById('clear-cart-btn').addEventListener('click', async () =>
|
|
|
188
188
|
});
|
|
189
189
|
```
|
|
190
190
|
|
|
191
|
+
## Cleanup
|
|
192
|
+
|
|
193
|
+
### Destroy Components When Done
|
|
194
|
+
|
|
195
|
+
In single-page applications, clean up when navigating away:
|
|
196
|
+
|
|
197
|
+
```javascript
|
|
198
|
+
// Destroy individual component
|
|
199
|
+
const component = client.getInjectedComponents().get('product-1');
|
|
200
|
+
component?.destroy();
|
|
201
|
+
|
|
202
|
+
// Destroy entire client (on route change)
|
|
203
|
+
client.destroy();
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Avoid Leaking References
|
|
207
|
+
|
|
208
|
+
```javascript
|
|
209
|
+
// Good - clean up on unmount
|
|
210
|
+
useEffect(() => {
|
|
211
|
+
const init = async () => {
|
|
212
|
+
const c = await Elements('KEY', { env: 'production' });
|
|
213
|
+
clientRef.current = c;
|
|
214
|
+
};
|
|
215
|
+
init();
|
|
216
|
+
return () => clientRef.current?.destroy();
|
|
217
|
+
}, []);
|
|
218
|
+
```
|
|
219
|
+
|
|
191
220
|
## Events
|
|
192
221
|
|
|
193
222
|
### Use Events for Reactive Updates
|