@liquidcommerce/elements-sdk 2.6.0-beta.11 → 2.6.0-beta.111
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 +99 -2518
- package/dist/index.checkout.esm.js +18212 -0
- package/dist/index.esm.js +26222 -20637
- package/dist/ssr-stub.checkout.esm.js +17 -0
- package/dist/ssr-stub.esm.js +269 -0
- package/dist/types/auto-initialize/checkout.d.ts +2 -0
- package/dist/types/auto-initialize/shared-utils.d.ts +50 -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 +13 -18
- package/dist/types/core/a11y/announcer.service.d.ts +16 -0
- package/dist/types/core/a11y/focus-manager.service.d.ts +21 -0
- package/dist/types/core/a11y/focusable.d.ts +5 -0
- package/dist/types/core/a11y/glyph-button.d.ts +8 -0
- package/dist/types/core/a11y/index.d.ts +6 -0
- package/dist/types/core/a11y/required.d.ts +1 -0
- package/dist/types/core/a11y/single-select.d.ts +20 -0
- package/dist/types/core/api/api-client.service.d.ts +19 -18
- package/dist/types/core/api/api-result.d.ts +19 -0
- package/dist/types/core/api/auth-client.service.d.ts +37 -13
- package/dist/types/core/api/http-client.service.d.ts +0 -8
- package/dist/types/core/base-component.service.d.ts +4 -1
- package/dist/types/core/client/actions/base-action.service.d.ts +22 -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 +38 -0
- package/dist/types/core/client/actions/client-checkout-action.service.d.ts +69 -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 -74
- package/dist/types/core/client/client-config.service.d.ts +8 -5
- package/dist/types/core/debug-panel/debug-panel.styles.d.ts +1 -1
- package/dist/types/core/google-tag-manager.service.d.ts +3 -1
- package/dist/types/core/logger/logger.service.d.ts +1 -1
- package/dist/types/core/pubsub/interfaces/address.interface.d.ts +3 -0
- package/dist/types/core/pubsub/interfaces/cart.interface.d.ts +1 -1
- package/dist/types/core/pubsub/interfaces/checkout.interface.d.ts +36 -51
- package/dist/types/core/pubsub/interfaces/core.interface.d.ts +11 -6
- 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 +2 -3
- package/dist/types/core/store/interfaces/checkout.interface.d.ts +19 -108
- package/dist/types/core/store/interfaces/core.interface.d.ts +12 -2
- 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 -2
- 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 +12 -7
- package/dist/types/interfaces/api/checkout.interface.d.ts +239 -0
- package/dist/types/interfaces/api/index.d.ts +5 -0
- package/dist/types/interfaces/api/product-list.interface.d.ts +15 -6
- package/dist/types/interfaces/api/product.interface.d.ts +10 -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 +40 -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 +9 -3
- package/dist/types/interfaces/configs/index.d.ts +1 -0
- package/dist/types/interfaces/configs/product-list.interface.d.ts +49 -0
- package/dist/types/interfaces/configs/product.interface.d.ts +5 -1
- package/dist/types/interfaces/injection.interface.d.ts +50 -0
- package/dist/types/modules/address/address-display.component.d.ts +3 -1
- package/dist/types/modules/address/address-input.component.d.ts +10 -1
- 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 -4
- package/dist/types/modules/cart/components/cart-body.component.d.ts +1 -0
- package/dist/types/modules/cart/components/cart-item-quantity-price.component.d.ts +5 -0
- package/dist/types/modules/cart/components/cart-item.component.d.ts +6 -0
- package/dist/types/modules/cart/styles/register-styles.d.ts +1 -0
- package/dist/types/modules/checkout/checkout.commands.d.ts +34 -11
- package/dist/types/modules/checkout/checkout.component.d.ts +6 -1
- package/dist/types/modules/checkout/components/checkout-billing.component.d.ts +5 -2
- package/dist/types/modules/checkout/components/checkout-completed.component.d.ts +5 -0
- package/dist/types/modules/checkout/components/checkout-header.component.d.ts +1 -0
- package/dist/types/modules/checkout/components/checkout-item-quantity.component.d.ts +4 -0
- package/dist/types/modules/checkout/components/checkout-items.component.d.ts +4 -3
- package/dist/types/modules/checkout/components/checkout-order-summary.component.d.ts +2 -0
- package/dist/types/modules/checkout/components/checkout-payment.component.d.ts +2 -1
- package/dist/types/modules/checkout/components/checkout-place-order-button.component.d.ts +2 -0
- package/dist/types/modules/checkout/components/checkout-presale-countdown.component.d.ts +15 -1
- package/dist/types/modules/checkout/components/checkout-presale-expired.component.d.ts +7 -1
- package/dist/types/modules/checkout/components/checkout-send-as-gift.component.d.ts +3 -0
- package/dist/types/modules/checkout/components/checkout-stripe-form.component.d.ts +4 -2
- package/dist/types/modules/checkout/components/checkout-tips.component.d.ts +4 -2
- package/dist/types/modules/checkout/components/promo-pc-gc.component.d.ts +0 -2
- package/dist/types/modules/checkout/components/required-fields-legend.d.ts +1 -0
- package/dist/types/modules/checkout/constant.d.ts +3 -0
- package/dist/types/modules/checkout/payment-session-error.d.ts +4 -0
- package/dist/types/modules/checkout/styles/register-styles.d.ts +1 -0
- package/dist/types/modules/product/components/components.d.ts +26 -2
- package/dist/types/modules/product/components/product-add-to-cart-section.component.d.ts +7 -1
- package/dist/types/modules/product/components/product-description.component.d.ts +1 -0
- package/dist/types/modules/product/components/product-drawer.component.d.ts +6 -0
- package/dist/types/modules/product/components/product-image-carousel.component.d.ts +5 -0
- package/dist/types/modules/product/components/product-options.component.d.ts +2 -1
- package/dist/types/modules/product/components/product-retailers-carousel.component.d.ts +6 -0
- package/dist/types/modules/product/components/product-retailers-popup-list.component.d.ts +12 -2
- package/dist/types/modules/product/product.commands.d.ts +5 -5
- 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 +11 -0
- package/dist/types/modules/product-list/components/card-components/product-price-and-personalization.d.ts +14 -0
- package/dist/types/modules/product-list/components/card-components/product-quantity-selector.d.ts +11 -0
- package/dist/types/modules/product-list/components/card-components/product-sizes-list.d.ts +14 -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/{product-list-filters-subcomponents/product-list-checkbox-filter.components.d.ts → filter-components/product-list-checkbox-filter.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 +15 -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} +2 -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 +3 -1
- package/dist/types/modules/product-list/components/product-list-card.component.d.ts +37 -31
- 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 +58 -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 +53 -0
- package/dist/types/modules/product-list/components/product-list-search.component.d.ts +25 -0
- package/dist/types/modules/product-list/product-list-filter.registry.d.ts +42 -0
- package/dist/types/modules/product-list/product-list-filter.utils.d.ts +7 -0
- package/dist/types/modules/product-list/product-list-order.utils.d.ts +3 -0
- package/dist/types/modules/product-list/product-list-query-params.utils.d.ts +3 -0
- package/dist/types/modules/product-list/product-list.commands.d.ts +22 -7
- package/dist/types/modules/product-list/product-list.component.d.ts +23 -47
- package/dist/types/modules/product-list/product-list.constants.d.ts +38 -0
- package/dist/types/modules/product-list/product-list.interface.d.ts +17 -28
- 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/alert/alert.component.d.ts +1 -1
- package/dist/types/modules/ui-components/buttons/buttons-open-cart.component.d.ts +5 -0
- package/dist/types/modules/ui-components/drawer/drawer.component.d.ts +15 -0
- package/dist/types/modules/ui-components/engraving/engraving-form.component.d.ts +8 -1
- package/dist/types/modules/ui-components/engraving/engraving-view.component.d.ts +7 -1
- package/dist/types/modules/ui-components/input/index.d.ts +0 -1
- package/dist/types/modules/ui-components/input/input.component.d.ts +14 -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/ui.commands.d.ts +7 -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/arrow-right.icon.d.ts +1 -1
- package/dist/types/static/icon/bag.icon.d.ts +1 -1
- package/dist/types/static/icon/check.icon.d.ts +2 -0
- package/dist/types/static/icon/checkbox.icon.d.ts +1 -1
- package/dist/types/static/icon/chevron-down.icon.d.ts +1 -1
- package/dist/types/static/icon/chevron-left.icon.d.ts +1 -1
- package/dist/types/static/icon/chevron-up.icon.d.ts +1 -1
- package/dist/types/static/icon/close.icon.d.ts +1 -1
- package/dist/types/static/icon/error-info.icon.d.ts +1 -1
- package/dist/types/static/icon/filter.icon.d.ts +1 -1
- package/dist/types/static/icon/icon.a11y.d.ts +1 -0
- package/dist/types/static/icon/icon.types.d.ts +1 -0
- package/dist/types/static/icon/index.d.ts +2 -0
- package/dist/types/static/icon/info.icon.d.ts +1 -1
- package/dist/types/static/icon/loading-spinner.icon.d.ts +1 -1
- package/dist/types/static/icon/search.icon.d.ts +1 -1
- package/dist/types/static/icon/success.icon.d.ts +1 -1
- package/dist/types/static/icon/trash.icon.d.ts +1 -1
- package/dist/types/static/icon/warning.icon.d.ts +1 -1
- package/dist/types/utils/dom-compat.d.ts +2 -0
- package/dist/types/utils/format.d.ts +5 -14
- package/dist/types/utils/image-bg-removal.d.ts +3 -0
- package/dist/types/utils/product-selection.d.ts +16 -0
- package/dist/types/utils/product.d.ts +18 -0
- package/dist/types/utils/timezone.d.ts +6 -0
- package/docs/v1/README.md +213 -0
- package/docs/v1/api/actions/address-actions.md +286 -0
- package/docs/v1/api/actions/cart-actions.md +364 -0
- package/docs/v1/api/actions/checkout-actions.md +527 -0
- package/docs/v1/api/actions/product-actions.md +204 -0
- package/docs/v1/api/client.md +596 -0
- package/docs/v1/api/configuration.md +557 -0
- package/docs/v1/api/injection-methods.md +331 -0
- package/docs/v1/api/typescript-types.md +424 -0
- package/docs/v1/api/ui-helpers.md +200 -0
- package/docs/v1/examples/advanced-patterns.md +199 -0
- package/docs/v1/examples/checkout-flow.md +90 -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 +521 -0
- package/docs/v1/getting-started/installation.md +349 -0
- package/docs/v1/getting-started/quick-start.md +410 -0
- package/docs/v1/guides/accessibility.md +219 -0
- package/docs/v1/guides/address-component.md +435 -0
- package/docs/v1/guides/best-practices.md +365 -0
- package/docs/v1/guides/cart-component.md +757 -0
- package/docs/v1/guides/checkout-component.md +670 -0
- package/docs/v1/guides/events.md +939 -0
- package/docs/v1/guides/product-component.md +736 -0
- package/docs/v1/guides/product-list-component.md +730 -0
- package/docs/v1/guides/theming.md +229 -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 +106 -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/analytics.md +107 -0
- package/docs/v1/reference/browser-support.md +47 -0
- package/docs/v1/reference/error-handling.md +83 -0
- package/docs/v1/reference/performance.md +52 -0
- package/docs/v1/reference/telemetry.md +85 -0
- package/docs/v1/reference/troubleshooting.md +135 -0
- package/package.json +75 -45
- 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 -97
- package/dist/types/interfaces/cloud/checkout.interface.d.ts +0 -218
- package/dist/types/interfaces/cloud/core.interface.d.ts +0 -22
- package/dist/types/interfaces/cloud/index.d.ts +0 -3
- 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/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-search.component.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/utils/helper.d.ts +0 -28
- 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/{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,757 @@
|
|
|
1
|
+
# Cart Component
|
|
2
|
+
|
|
3
|
+
The Cart component provides a slide-out drawer for managing shopping cart items, applying promo codes, and proceeding to checkout.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Cart component automatically:
|
|
8
|
+
- Displays cart items with images and details
|
|
9
|
+
- Removes white / near-white backgrounds from item images so products blend into the drawer (automatic, not host-configurable)
|
|
10
|
+
- Groups items by retailer
|
|
11
|
+
- Shows real-time pricing and totals
|
|
12
|
+
- Supports quantity updates
|
|
13
|
+
- Handles promo code application
|
|
14
|
+
- Persists cart across sessions and tabs
|
|
15
|
+
- Provides checkout navigation
|
|
16
|
+
|
|
17
|
+
## Basic Usage
|
|
18
|
+
|
|
19
|
+
The cart is automatically available when using the SDK - no explicit injection needed for the drawer. However, you need a way for users to open it.
|
|
20
|
+
|
|
21
|
+
### Cart Buttons
|
|
22
|
+
|
|
23
|
+
#### Declarative Cart Button
|
|
24
|
+
|
|
25
|
+
Add a cart button using data attributes on the SDK script:
|
|
26
|
+
|
|
27
|
+
```html
|
|
28
|
+
<script
|
|
29
|
+
defer
|
|
30
|
+
data-liquid-commerce-elements
|
|
31
|
+
data-token="YOUR_API_KEY"
|
|
32
|
+
data-env="production"
|
|
33
|
+
data-cart-button="header-cart"
|
|
34
|
+
type="text/javascript"
|
|
35
|
+
src="https://elements.reservebar-worker.workers.dev/all/elements.js"
|
|
36
|
+
></script>
|
|
37
|
+
|
|
38
|
+
<div id="header-cart"></div>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
#### Cart Button with Item Count Badge
|
|
42
|
+
|
|
43
|
+
Show the number of items in the cart:
|
|
44
|
+
|
|
45
|
+
```html
|
|
46
|
+
<script
|
|
47
|
+
defer
|
|
48
|
+
data-liquid-commerce-elements
|
|
49
|
+
data-token="YOUR_API_KEY"
|
|
50
|
+
data-env="production"
|
|
51
|
+
data-cart-badge-button="header-cart"
|
|
52
|
+
type="text/javascript"
|
|
53
|
+
src="https://elements.reservebar-worker.workers.dev/all/elements.js"
|
|
54
|
+
></script>
|
|
55
|
+
|
|
56
|
+
<div id="header-cart"></div>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
#### Floating Cart Button
|
|
60
|
+
|
|
61
|
+
Create a floating button (top-right corner):
|
|
62
|
+
|
|
63
|
+
```html
|
|
64
|
+
<script
|
|
65
|
+
defer
|
|
66
|
+
data-liquid-commerce-elements
|
|
67
|
+
data-token="YOUR_API_KEY"
|
|
68
|
+
data-env="production"
|
|
69
|
+
data-cart-button
|
|
70
|
+
type="text/javascript"
|
|
71
|
+
src="https://elements.reservebar-worker.workers.dev/all/elements.js"
|
|
72
|
+
></script>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Leaving `data-cart-button` empty creates a floating button automatically.
|
|
76
|
+
|
|
77
|
+
#### Positional Cart Button
|
|
78
|
+
|
|
79
|
+
Control where the cart button appears:
|
|
80
|
+
|
|
81
|
+
```html
|
|
82
|
+
<!-- Inside an element -->
|
|
83
|
+
<script data-cart-button="inside:#header"></script>
|
|
84
|
+
|
|
85
|
+
<!-- Above an element -->
|
|
86
|
+
<script data-cart-button="above:.navigation"></script>
|
|
87
|
+
|
|
88
|
+
<!-- Below an element -->
|
|
89
|
+
<script data-cart-button="below:#logo"></script>
|
|
90
|
+
|
|
91
|
+
<!-- Replace an element -->
|
|
92
|
+
<script data-cart-button="replace:#cart-placeholder"></script>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### Hide Cart Button
|
|
96
|
+
|
|
97
|
+
If you want to control cart opening manually:
|
|
98
|
+
|
|
99
|
+
```html
|
|
100
|
+
<script
|
|
101
|
+
defer
|
|
102
|
+
data-liquid-commerce-elements
|
|
103
|
+
data-token="YOUR_API_KEY"
|
|
104
|
+
data-env="production"
|
|
105
|
+
data-cart-button-hidden
|
|
106
|
+
type="text/javascript"
|
|
107
|
+
src="https://elements.reservebar-worker.workers.dev/all/elements.js"
|
|
108
|
+
></script>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### Programmatic Cart Button
|
|
112
|
+
|
|
113
|
+
Create cart buttons using JavaScript:
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
// Button in a container
|
|
117
|
+
window.LiquidCommerce.elements.ui.cartButton('my-container', false); // No badge
|
|
118
|
+
|
|
119
|
+
// Button with item count
|
|
120
|
+
window.LiquidCommerce.elements.ui.cartButton('my-container', true); // With badge
|
|
121
|
+
|
|
122
|
+
// Floating button
|
|
123
|
+
window.LiquidCommerce.elements.ui.floatingCartButton(true); // With badge
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Custom Toggle Buttons
|
|
127
|
+
|
|
128
|
+
Use your own button to toggle the cart:
|
|
129
|
+
|
|
130
|
+
```html
|
|
131
|
+
<button data-lce-cart-toggle-button>
|
|
132
|
+
View Cart
|
|
133
|
+
</button>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The SDK automatically adds click handlers to elements with `data-lce-cart-toggle-button`.
|
|
137
|
+
|
|
138
|
+
## Cart Actions
|
|
139
|
+
|
|
140
|
+
### Open Cart
|
|
141
|
+
|
|
142
|
+
```javascript
|
|
143
|
+
window.LiquidCommerce.elements.actions.cart.openCart();
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Close Cart
|
|
147
|
+
|
|
148
|
+
```javascript
|
|
149
|
+
window.LiquidCommerce.elements.actions.cart.closeCart();
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Toggle Cart
|
|
153
|
+
|
|
154
|
+
```javascript
|
|
155
|
+
window.LiquidCommerce.elements.actions.cart.toggleCart();
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Add Product to Cart
|
|
159
|
+
|
|
160
|
+
Add products programmatically:
|
|
161
|
+
|
|
162
|
+
```javascript
|
|
163
|
+
await window.LiquidCommerce.elements.actions.cart.addProduct([
|
|
164
|
+
{
|
|
165
|
+
identifier: '00619947000020',
|
|
166
|
+
fulfillmentType: 'shipping', // or 'onDemand'
|
|
167
|
+
quantity: 2
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
identifier: '08504405135',
|
|
171
|
+
fulfillmentType: 'onDemand',
|
|
172
|
+
quantity: 1
|
|
173
|
+
}
|
|
174
|
+
], true); // true = open cart after adding
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Parameters:**
|
|
178
|
+
- `identifier` (string): Product UPC, size ID, or salsifyGrouping ID
|
|
179
|
+
- `fulfillmentType` (string): `'shipping'` or `'onDemand'`
|
|
180
|
+
- `quantity` (number): Number of items (default: 1)
|
|
181
|
+
- `engravingLines` (string[], optional): Engraving text lines for the product (applied when the product/variant supports engraving; ignored otherwise)
|
|
182
|
+
- Second parameter (boolean): Open cart after adding (default: false)
|
|
183
|
+
|
|
184
|
+
### Apply Promo Code
|
|
185
|
+
|
|
186
|
+
```javascript
|
|
187
|
+
await window.LiquidCommerce.elements.actions.cart.applyPromoCode('SUMMER20');
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
The SDK automatically:
|
|
191
|
+
- Validates the promo code
|
|
192
|
+
- Calculates discount
|
|
193
|
+
- Updates cart totals
|
|
194
|
+
- Shows success/error message
|
|
195
|
+
|
|
196
|
+
### Remove Promo Code
|
|
197
|
+
|
|
198
|
+
```javascript
|
|
199
|
+
await window.LiquidCommerce.elements.actions.cart.removePromoCode();
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Reset Cart
|
|
203
|
+
|
|
204
|
+
Clear all items from the cart:
|
|
205
|
+
|
|
206
|
+
```javascript
|
|
207
|
+
await window.LiquidCommerce.elements.actions.cart.resetCart();
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Get Cart Details
|
|
211
|
+
|
|
212
|
+
Retrieve current cart information:
|
|
213
|
+
|
|
214
|
+
```javascript
|
|
215
|
+
const cartData = window.LiquidCommerce.elements.actions.cart.getDetails();
|
|
216
|
+
|
|
217
|
+
console.log(cartData);
|
|
218
|
+
// {
|
|
219
|
+
// cartId: 'cart_abc123',
|
|
220
|
+
// promoCodeDiscount: 1000, // number | null
|
|
221
|
+
// subtotal: 9998, // in cents
|
|
222
|
+
// itemCount: 5,
|
|
223
|
+
// items: {...}, // Record<itemId, ICartItem>
|
|
224
|
+
// retailers: {...}, // Record<retailerId, ICartRetailer>
|
|
225
|
+
// location: {...}, // or null
|
|
226
|
+
// ...
|
|
227
|
+
// }
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Cart UI Helpers
|
|
231
|
+
|
|
232
|
+
### Display Cart Subtotal
|
|
233
|
+
|
|
234
|
+
Show cart subtotal anywhere on your page:
|
|
235
|
+
|
|
236
|
+
```html
|
|
237
|
+
<div>
|
|
238
|
+
Cart Total: <span id="cart-total"></span>
|
|
239
|
+
</div>
|
|
240
|
+
|
|
241
|
+
<script>
|
|
242
|
+
window.addEventListener('lce:actions.client_ready', () => {
|
|
243
|
+
window.LiquidCommerce.elements.ui.cartSubtotal('cart-total');
|
|
244
|
+
}, { once: true });
|
|
245
|
+
</script>
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
The element automatically updates when the cart changes.
|
|
249
|
+
|
|
250
|
+
### Display Items Count
|
|
251
|
+
|
|
252
|
+
Show the number of items in the cart:
|
|
253
|
+
|
|
254
|
+
```html
|
|
255
|
+
<div>
|
|
256
|
+
Items: <span id="items-count"></span>
|
|
257
|
+
</div>
|
|
258
|
+
|
|
259
|
+
<script>
|
|
260
|
+
window.addEventListener('lce:actions.client_ready', () => {
|
|
261
|
+
window.LiquidCommerce.elements.ui.cartItemsCount('items-count', {
|
|
262
|
+
hideZero: true // Hide when cart is empty
|
|
263
|
+
});
|
|
264
|
+
}, { once: true });
|
|
265
|
+
</script>
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Or using data attributes:
|
|
269
|
+
|
|
270
|
+
```html
|
|
271
|
+
<!-- Always show count, even when 0 -->
|
|
272
|
+
<span data-lce-cart-items-count="keep-zero"></span>
|
|
273
|
+
|
|
274
|
+
<!-- Hide when 0 (default behavior) -->
|
|
275
|
+
<span data-lce-cart-items-count></span>
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Events
|
|
279
|
+
|
|
280
|
+
### Cart Loaded
|
|
281
|
+
|
|
282
|
+
Fired when cart data is loaded:
|
|
283
|
+
|
|
284
|
+
```javascript
|
|
285
|
+
window.addEventListener('lce:actions.cart_loaded', (event) => {
|
|
286
|
+
const { cartId, itemCount, subtotal } = event.detail.data;
|
|
287
|
+
console.log(`Cart loaded: ${itemCount} items, total: $${subtotal / 100}`);
|
|
288
|
+
});
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Cart Opened/Closed
|
|
292
|
+
|
|
293
|
+
```javascript
|
|
294
|
+
window.addEventListener('lce:actions.cart_opened', (event) => {
|
|
295
|
+
console.log('Cart drawer opened');
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
window.addEventListener('lce:actions.cart_closed', (event) => {
|
|
299
|
+
console.log('Cart drawer closed');
|
|
300
|
+
});
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### Cart Updated
|
|
304
|
+
|
|
305
|
+
Fired whenever cart contents change:
|
|
306
|
+
|
|
307
|
+
```javascript
|
|
308
|
+
window.addEventListener('lce:actions.cart_updated', (event) => {
|
|
309
|
+
const { cartId, itemCount, subtotal } = event.detail.data.current;
|
|
310
|
+
console.log('Cart updated:', itemCount, 'items');
|
|
311
|
+
});
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Item Added
|
|
315
|
+
|
|
316
|
+
```javascript
|
|
317
|
+
window.addEventListener('lce:actions.cart_item_added', (event) => {
|
|
318
|
+
const { cartId, itemId, quantity } = event.detail.data;
|
|
319
|
+
console.log(`Item ${itemId} added (quantity: ${quantity})`);
|
|
320
|
+
});
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### Item Removed
|
|
324
|
+
|
|
325
|
+
```javascript
|
|
326
|
+
window.addEventListener('lce:actions.cart_item_removed', (event) => {
|
|
327
|
+
const { cartId, itemId } = event.detail.data;
|
|
328
|
+
console.log(`Item ${itemId} removed`);
|
|
329
|
+
});
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### Quantity Changed
|
|
333
|
+
|
|
334
|
+
```javascript
|
|
335
|
+
window.addEventListener('lce:actions.cart_item_quantity_increase', (event) => {
|
|
336
|
+
const { cartId, itemId, quantity } = event.detail.data;
|
|
337
|
+
console.log(`Item ${itemId} quantity increased to ${quantity}`);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
window.addEventListener('lce:actions.cart_item_quantity_decrease', (event) => {
|
|
341
|
+
const { cartId, itemId, quantity } = event.detail.data;
|
|
342
|
+
console.log(`Item ${itemId} quantity decreased to ${quantity}`);
|
|
343
|
+
});
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### Engraving Updated
|
|
347
|
+
|
|
348
|
+
Fired when a cart line item's engraving is added or edited from the drawer (see [Engraving](#engraving)):
|
|
349
|
+
|
|
350
|
+
```javascript
|
|
351
|
+
window.addEventListener('lce:actions.cart_item_engraving_updated', (event) => {
|
|
352
|
+
const { cartId, itemId, engravingLines, previousEngravingLines } = event.detail.data;
|
|
353
|
+
console.log(`Engraving updated for ${itemId}:`, engravingLines);
|
|
354
|
+
});
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### Promo Code Events
|
|
358
|
+
|
|
359
|
+
```javascript
|
|
360
|
+
window.addEventListener('lce:actions.cart_promo_code_applied', (event) => {
|
|
361
|
+
const { cartId, discount, newSubtotal } = event.detail.data;
|
|
362
|
+
console.log(`Promo code applied: $${discount / 100} off`);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
window.addEventListener('lce:actions.cart_promo_code_removed', (event) => {
|
|
366
|
+
const { cartId, newSubtotal } = event.detail.data;
|
|
367
|
+
console.log('Promo code removed');
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
window.addEventListener('lce:actions.cart_promo_code_failed', (event) => {
|
|
371
|
+
const { cartId, error } = event.detail.data;
|
|
372
|
+
console.error('Promo code failed:', error);
|
|
373
|
+
});
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### Product Add Success/Failure
|
|
377
|
+
|
|
378
|
+
```javascript
|
|
379
|
+
window.addEventListener('lce:actions.cart_product_add_success', (event) => {
|
|
380
|
+
const { cartId, itemsAdded, identifiers } = event.detail.data;
|
|
381
|
+
console.log(`Successfully added ${itemsAdded} products`);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
window.addEventListener('lce:actions.cart_product_add_failed', (event) => {
|
|
385
|
+
const { cartId, identifiers, error } = event.detail.data;
|
|
386
|
+
console.error('Failed to add products:', error);
|
|
387
|
+
});
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
### Cart Reset
|
|
391
|
+
|
|
392
|
+
```javascript
|
|
393
|
+
window.addEventListener('lce:actions.cart_reset', (event) => {
|
|
394
|
+
console.log('Cart has been reset');
|
|
395
|
+
});
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
## Customization
|
|
399
|
+
|
|
400
|
+
### Theme Configuration
|
|
401
|
+
|
|
402
|
+
Customize cart appearance:
|
|
403
|
+
|
|
404
|
+
```javascript
|
|
405
|
+
const client = await Elements('YOUR_API_KEY', {
|
|
406
|
+
env: 'production',
|
|
407
|
+
customTheme: {
|
|
408
|
+
cart: {
|
|
409
|
+
theme: {
|
|
410
|
+
backgroundColor: '#ffffff'
|
|
411
|
+
},
|
|
412
|
+
layout: {
|
|
413
|
+
showQuantityCounter: true,
|
|
414
|
+
quantityCounterStyle: 'outlined', // or 'ghost'
|
|
415
|
+
drawerHeaderText: 'My Bag',
|
|
416
|
+
goToCheckoutButtonText: 'Checkout'
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
## State Persistence
|
|
424
|
+
|
|
425
|
+
### Local Storage
|
|
426
|
+
|
|
427
|
+
The cart automatically persists to `localStorage`
|
|
428
|
+
|
|
429
|
+
This allows the cart to survive:
|
|
430
|
+
- Page refreshes
|
|
431
|
+
- Browser restarts
|
|
432
|
+
- Navigation between pages
|
|
433
|
+
|
|
434
|
+
### Cross-Tab Persistence
|
|
435
|
+
|
|
436
|
+
The cart is persisted to `localStorage` and reloaded on a fresh page load. The SDK does **not** provide live cross-tab synchronization — changes made in one tab will not automatically appear in other already-open tabs (there is no `storage` listener, `BroadcastChannel`, or polling). Another tab reflects the change only after it reloads.
|
|
437
|
+
|
|
438
|
+
### Session Duration
|
|
439
|
+
|
|
440
|
+
Cart and address session IDs are persisted in `localStorage` (with an API fallback) and are not automatically cleared by the SDK; cart lifetime/expiry is governed by server-side policy.
|
|
441
|
+
|
|
442
|
+
## Address Requirement
|
|
443
|
+
|
|
444
|
+
The cart requires a delivery address for:
|
|
445
|
+
- Accurate availability
|
|
446
|
+
- Correct pricing
|
|
447
|
+
- Shipping calculations
|
|
448
|
+
|
|
449
|
+
### Automatic Address Prompt
|
|
450
|
+
|
|
451
|
+
If no address is set when adding to cart, the SDK:
|
|
452
|
+
1. Opens address input drawer
|
|
453
|
+
2. Waits for user to set address
|
|
454
|
+
3. Retries the add-to-cart operation
|
|
455
|
+
|
|
456
|
+
### Pre-set Address
|
|
457
|
+
|
|
458
|
+
Set address before adding to cart:
|
|
459
|
+
|
|
460
|
+
```javascript
|
|
461
|
+
await window.LiquidCommerce.elements.actions.address.setAddressByPlacesId('ChIJ...');
|
|
462
|
+
|
|
463
|
+
// Now add to cart
|
|
464
|
+
await window.LiquidCommerce.elements.actions.cart.addProduct([...]);
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
## Promo Codes
|
|
468
|
+
|
|
469
|
+
### Configuration
|
|
470
|
+
|
|
471
|
+
Enable/disable promo codes globally:
|
|
472
|
+
|
|
473
|
+
```javascript
|
|
474
|
+
customTheme: {
|
|
475
|
+
global: {
|
|
476
|
+
layout: {
|
|
477
|
+
allowPromoCodes: true // or false to disable
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
### Promo Ticker
|
|
484
|
+
|
|
485
|
+
Show promotional codes in a scrolling ticker:
|
|
486
|
+
|
|
487
|
+
```javascript
|
|
488
|
+
const client = await Elements('YOUR_API_KEY', {
|
|
489
|
+
env: 'production',
|
|
490
|
+
promoTicker: [
|
|
491
|
+
{
|
|
492
|
+
promoCode: 'SUMMER20',
|
|
493
|
+
text: ['20% Off Summer Sale', 'Free Shipping on Orders Over $50'],
|
|
494
|
+
separator: '•',
|
|
495
|
+
activeFrom: '2024-06-01T00:00:00Z',
|
|
496
|
+
activeUntil: '2024-08-31T23:59:59Z'
|
|
497
|
+
}
|
|
498
|
+
]
|
|
499
|
+
});
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
Or with data attributes:
|
|
503
|
+
|
|
504
|
+
```html
|
|
505
|
+
<script
|
|
506
|
+
defer
|
|
507
|
+
data-liquid-commerce-elements
|
|
508
|
+
data-token="YOUR_API_KEY"
|
|
509
|
+
data-env="production"
|
|
510
|
+
data-promo-code="SUMMER20"
|
|
511
|
+
data-promo-text="20% Off Summer Sale | Free Shipping on Orders Over $50"
|
|
512
|
+
data-promo-separator="•"
|
|
513
|
+
data-promo-active-from="2024-06-01T00:00:00Z"
|
|
514
|
+
data-promo-active-until="2024-08-31T23:59:59Z"
|
|
515
|
+
type="text/javascript"
|
|
516
|
+
src="https://elements.reservebar-worker.workers.dev/all/elements.js"
|
|
517
|
+
></script>
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
### Auto-Apply from URL
|
|
521
|
+
|
|
522
|
+
Apply promo codes automatically via URL parameters:
|
|
523
|
+
|
|
524
|
+
```html
|
|
525
|
+
<script
|
|
526
|
+
defer
|
|
527
|
+
data-liquid-commerce-elements
|
|
528
|
+
data-token="YOUR_API_KEY"
|
|
529
|
+
data-env="production"
|
|
530
|
+
data-promo-code-param="lce_promo"
|
|
531
|
+
type="text/javascript"
|
|
532
|
+
src="https://elements.reservebar-worker.workers.dev/all/elements.js"
|
|
533
|
+
></script>
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
Now visiting `https://yoursite.com?lce_promo=SUMMER20` automatically applies the code.
|
|
537
|
+
|
|
538
|
+
**Security Note:** Query parameters must start with `lce_` prefix to prevent conflicts with your application.
|
|
539
|
+
|
|
540
|
+
## Retailer Grouping
|
|
541
|
+
|
|
542
|
+
Items are automatically grouped by retailer in the cart:
|
|
543
|
+
|
|
544
|
+
```
|
|
545
|
+
┌─────────────────────────────────────┐
|
|
546
|
+
│ Cart (3 items) │
|
|
547
|
+
├─────────────────────────────────────┤
|
|
548
|
+
│ Spirits Shop │
|
|
549
|
+
│ • Premium Whiskey (750ml) $49 │
|
|
550
|
+
│ • Bourbon Bottle (1L) $65 │
|
|
551
|
+
│ │
|
|
552
|
+
│ Wine & More │
|
|
553
|
+
│ • Red Wine (750ml) $25 │
|
|
554
|
+
├─────────────────────────────────────┤
|
|
555
|
+
│ Subtotal: $139 │
|
|
556
|
+
│ Promo Code (SUMMER20): -$28 │
|
|
557
|
+
│ Total: $111 │
|
|
558
|
+
└─────────────────────────────────────┘
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
## Order Minimums
|
|
562
|
+
|
|
563
|
+
Retailers can require a minimum purchase amount before their items can be checked out. The cart enforces this per retailer:
|
|
564
|
+
|
|
565
|
+
- When a retailer's minimum is not met, the cart drawer shows a per-retailer alert reading `+$X needed for order minimum`, where `$X` is the remaining amount required for that retailer.
|
|
566
|
+
- The **Checkout** button is disabled until every retailer's minimum is met. (It is also disabled while the cart is loading/updating or when the cart is empty.)
|
|
567
|
+
|
|
568
|
+
No configuration is required — the minimums are defined by each retailer and enforced automatically.
|
|
569
|
+
|
|
570
|
+
## Engraving
|
|
571
|
+
|
|
572
|
+
For engravable items, shoppers can add or edit engraving directly from a cart line item, without leaving the drawer.
|
|
573
|
+
|
|
574
|
+
- If an engravable item has no engraving yet, the line item shows an **Add personalization** action (with the engraving fee) that opens the engraving form.
|
|
575
|
+
- If the item already has engraving, its engraving is shown on the line item with an **Edit** button that reopens the form.
|
|
576
|
+
|
|
577
|
+
The form respects the item's engraving constraints — `maxLines`, `maxCharsPerLine`, and the per-item `fee`. Saving emits [`lce:actions.cart_item_engraving_updated`](#engraving-updated) with the item's `engravingLines` and `previousEngravingLines`.
|
|
578
|
+
|
|
579
|
+
**Note:** This in-drawer editing is distinct from the `engravingLines` array passed to [`addProduct`](#add-product-to-cart), which pre-fills engraving at the time an item is added.
|
|
580
|
+
|
|
581
|
+
## Checkout Navigation
|
|
582
|
+
|
|
583
|
+
### Checkout Drawer (Default)
|
|
584
|
+
|
|
585
|
+
By default, clicking "Checkout" opens the checkout drawer:
|
|
586
|
+
|
|
587
|
+
```javascript
|
|
588
|
+
// User clicks checkout
|
|
589
|
+
// Checkout drawer slides in
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
### Checkout Page (Custom URL)
|
|
593
|
+
|
|
594
|
+
Redirect to a custom checkout page:
|
|
595
|
+
|
|
596
|
+
```javascript
|
|
597
|
+
const client = await Elements('YOUR_API_KEY', {
|
|
598
|
+
env: 'production',
|
|
599
|
+
checkout: {
|
|
600
|
+
pageUrl: 'https://yoursite.com/checkout/{token}'
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
Or with data attributes:
|
|
606
|
+
|
|
607
|
+
```html
|
|
608
|
+
<script
|
|
609
|
+
defer
|
|
610
|
+
data-liquid-commerce-elements
|
|
611
|
+
data-token="YOUR_API_KEY"
|
|
612
|
+
data-env="production"
|
|
613
|
+
data-checkout-url="https://yoursite.com/checkout/{token}"
|
|
614
|
+
type="text/javascript"
|
|
615
|
+
src="https://elements.reservebar-worker.workers.dev/all/elements.js"
|
|
616
|
+
></script>
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
The `{token}` placeholder is replaced with the session checkout token.
|
|
620
|
+
|
|
621
|
+
## Use Cases
|
|
622
|
+
|
|
623
|
+
### E-commerce Site
|
|
624
|
+
|
|
625
|
+
```javascript
|
|
626
|
+
// Track cart events for analytics
|
|
627
|
+
window.addEventListener('lce:actions.cart_item_added', (event) => {
|
|
628
|
+
const { itemId, quantity } = event.detail.data;
|
|
629
|
+
gtag('event', 'add_to_cart', {
|
|
630
|
+
items: [{ item_id: itemId, quantity }],
|
|
631
|
+
currency: 'USD'
|
|
632
|
+
});
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
window.addEventListener('lce:actions.cart_updated', (event) => {
|
|
636
|
+
// Update header cart count
|
|
637
|
+
document.getElementById('cart-badge').textContent =
|
|
638
|
+
event.detail.data.current.itemCount;
|
|
639
|
+
});
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
### Marketing Campaign
|
|
643
|
+
|
|
644
|
+
```javascript
|
|
645
|
+
// Check URL for campaign parameter
|
|
646
|
+
const params = new URLSearchParams(window.location.search);
|
|
647
|
+
const campaign = params.get('campaign');
|
|
648
|
+
|
|
649
|
+
if (campaign === 'summer-sale') {
|
|
650
|
+
await window.LiquidCommerce.elements.actions.cart.applyPromoCode('SUMMER20');
|
|
651
|
+
window.LiquidCommerce.elements.actions.cart.openCart();
|
|
652
|
+
}
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
### Abandoned Cart Recovery
|
|
656
|
+
|
|
657
|
+
```javascript
|
|
658
|
+
// Store cart ID in your system
|
|
659
|
+
window.addEventListener('lce:actions.cart_updated', (event) => {
|
|
660
|
+
const { cartId, itemCount } = event.detail.data.current;
|
|
661
|
+
|
|
662
|
+
if (itemCount > 0) {
|
|
663
|
+
// Send cart ID to your backend for abandoned cart emails
|
|
664
|
+
fetch('/api/track-cart', {
|
|
665
|
+
method: 'POST',
|
|
666
|
+
body: JSON.stringify({ cartId, userId: currentUserId })
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
## Best Practices
|
|
673
|
+
|
|
674
|
+
### Initialize Cart Early
|
|
675
|
+
|
|
676
|
+
Pre-load cart on page load for faster access:
|
|
677
|
+
|
|
678
|
+
```javascript
|
|
679
|
+
window.addEventListener('lce:actions.client_ready', () => {
|
|
680
|
+
// Cart loads automatically, but you can pre-fetch if needed
|
|
681
|
+
window.LiquidCommerce.elements.actions.cart.getDetails();
|
|
682
|
+
}, { once: true });
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
### Provide Visual Feedback
|
|
686
|
+
|
|
687
|
+
Show loading states when adding to cart:
|
|
688
|
+
|
|
689
|
+
```javascript
|
|
690
|
+
async function addToCart(productId) {
|
|
691
|
+
const button = document.getElementById('add-to-cart-btn');
|
|
692
|
+
button.disabled = true;
|
|
693
|
+
button.textContent = 'Adding...';
|
|
694
|
+
|
|
695
|
+
try {
|
|
696
|
+
await window.LiquidCommerce.elements.actions.cart.addProduct([
|
|
697
|
+
{ identifier: productId, fulfillmentType: 'shipping', quantity: 1 }
|
|
698
|
+
], true);
|
|
699
|
+
|
|
700
|
+
button.textContent = 'Added!';
|
|
701
|
+
setTimeout(() => {
|
|
702
|
+
button.disabled = false;
|
|
703
|
+
button.textContent = 'Add to Cart';
|
|
704
|
+
}, 2000);
|
|
705
|
+
} catch (error) {
|
|
706
|
+
button.textContent = 'Failed';
|
|
707
|
+
button.disabled = false;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
```
|
|
711
|
+
|
|
712
|
+
### Handle Empty Cart
|
|
713
|
+
|
|
714
|
+
Show appropriate messaging for empty carts:
|
|
715
|
+
|
|
716
|
+
```javascript
|
|
717
|
+
window.addEventListener('lce:actions.cart_updated', (event) => {
|
|
718
|
+
const { itemCount } = event.detail.data.current;
|
|
719
|
+
|
|
720
|
+
if (itemCount === 0) {
|
|
721
|
+
// Show empty state in your UI
|
|
722
|
+
document.getElementById('cart-status').textContent =
|
|
723
|
+
'Your cart is empty';
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
## Troubleshooting
|
|
729
|
+
|
|
730
|
+
### Cart Not Opening
|
|
731
|
+
|
|
732
|
+
1. Check that SDK is initialized: `console.log(window.LiquidCommerce.elements)`
|
|
733
|
+
2. Verify no JavaScript errors in console
|
|
734
|
+
3. Ensure cart button is properly configured
|
|
735
|
+
4. Try manually: `window.LiquidCommerce.elements.actions.cart.openCart()`
|
|
736
|
+
|
|
737
|
+
### Items Not Adding
|
|
738
|
+
|
|
739
|
+
1. Check that address is set: `window.LiquidCommerce.elements.actions.address.getDetails()`
|
|
740
|
+
2. Verify product identifier is valid
|
|
741
|
+
3. Check fulfillment type is available for the product
|
|
742
|
+
4. Look for errors in browser console
|
|
743
|
+
|
|
744
|
+
### Promo Code Not Working
|
|
745
|
+
|
|
746
|
+
1. Verify promo codes are enabled in configuration
|
|
747
|
+
2. Check code is valid and active
|
|
748
|
+
3. Ensure code hasn't already been applied
|
|
749
|
+
4. Check console for error messages
|
|
750
|
+
|
|
751
|
+
## See Also
|
|
752
|
+
|
|
753
|
+
- [Product Component](./product-component.md) - Add products to cart
|
|
754
|
+
- [Checkout Component](./checkout-component.md) - Complete purchase
|
|
755
|
+
- [Actions API](../api/actions/cart-actions.md) - Cart actions reference
|
|
756
|
+
- [Events](./events.md) - All available events
|
|
757
|
+
- [Theming](./theming.md) - Customize appearance
|