@liquidcommerce/elements-sdk 2.6.0-beta.13 → 2.6.0-beta.130
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 +102 -2518
- package/dist/index.checkout.esm.js +22267 -0
- package/dist/index.esm.js +30400 -20620
- package/dist/ssr-stub.checkout.esm.js +17 -0
- package/dist/ssr-stub.esm.js +281 -0
- package/dist/types/auto-initialize/checkout.d.ts +2 -0
- package/dist/types/auto-initialize/shared-utils.d.ts +51 -0
- package/dist/types/{elements-base-client.d.ts → clients/base.d.ts} +16 -2
- package/dist/types/clients/builder.d.ts +3 -0
- package/dist/types/clients/checkout.d.ts +6 -0
- package/dist/types/clients/helpers.d.ts +8 -0
- package/dist/types/clients/main.d.ts +3 -0
- package/dist/types/constants/core.constant.d.ts +13 -18
- package/dist/types/constants/index.d.ts +1 -0
- package/dist/types/constants/prop65.constant.d.ts +8 -0
- 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 +23 -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-analytics-action.service.d.ts +35 -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 +81 -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 +7 -74
- package/dist/types/core/client/client-config.service.d.ts +12 -5
- package/dist/types/core/debug-panel/debug-panel.styles.d.ts +1 -1
- package/dist/types/core/google-tag-manager.service.d.ts +13 -3
- 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 +6 -1
- package/dist/types/core/pubsub/interfaces/checkout.interface.d.ts +54 -48
- package/dist/types/core/pubsub/interfaces/core.interface.d.ts +18 -7
- 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 +39 -107
- 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 +51 -2
- package/dist/types/enums/index.d.ts +0 -1
- package/dist/types/index.checkout.d.ts +11 -0
- package/dist/types/index.checkout.umd.d.ts +4 -0
- package/dist/types/index.d.ts +9 -3
- package/dist/types/interfaces/analytics.interface.d.ts +41 -0
- package/dist/types/interfaces/api/cart.interface.d.ts +12 -7
- package/dist/types/interfaces/api/checkout.interface.d.ts +275 -0
- package/dist/types/interfaces/api/delivery.interface.d.ts +24 -0
- package/dist/types/interfaces/api/index.d.ts +6 -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 +79 -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 +2 -1
- package/dist/types/interfaces/configs/checkout.interface.d.ts +3 -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 +7 -1
- package/dist/types/interfaces/injection.interface.d.ts +56 -0
- package/dist/types/modules/address/address-display.component.d.ts +3 -1
- package/dist/types/modules/address/address-input.component.d.ts +11 -1
- package/dist/types/modules/address/address.command.d.ts +3 -2
- package/dist/types/modules/address/styles/register-styles.d.ts +1 -0
- package/dist/types/modules/cart/cart.commands.d.ts +11 -5
- package/dist/types/modules/cart/components/cart-body.component.d.ts +1 -0
- package/dist/types/modules/cart/components/cart-fulfillment.component.d.ts +1 -1
- 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 +128 -12
- package/dist/types/modules/checkout/checkout.component.d.ts +7 -1
- package/dist/types/modules/checkout/components/checkout-billing.component.d.ts +5 -2
- package/dist/types/modules/checkout/components/checkout-buyer.component.d.ts +1 -0
- package/dist/types/modules/checkout/components/checkout-completed.component.d.ts +7 -0
- package/dist/types/modules/checkout/components/checkout-deliver-to.component.d.ts +1 -0
- package/dist/types/modules/checkout/components/checkout-delivery-method.component.d.ts +22 -0
- package/dist/types/modules/checkout/components/checkout-delivery-scheduling.component.d.ts +51 -0
- package/dist/types/modules/checkout/components/checkout-express-checkout.component.d.ts +63 -0
- package/dist/types/modules/checkout/components/checkout-express-completion.component.d.ts +21 -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-item.component.d.ts +2 -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 +3 -0
- package/dist/types/modules/checkout/components/checkout-payment.component.d.ts +8 -1
- package/dist/types/modules/checkout/components/checkout-place-order-button.component.d.ts +1 -5
- 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-prop65-warning.component.d.ts +8 -0
- 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 +7 -3
- package/dist/types/modules/checkout/components/checkout-stripe-handler.component.d.ts +4 -0
- package/dist/types/modules/checkout/components/checkout-tips.component.d.ts +4 -2
- package/dist/types/modules/checkout/components/index.d.ts +5 -0
- 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 +15 -0
- package/dist/types/modules/checkout/customer-prefill.d.ts +5 -0
- package/dist/types/modules/checkout/express-wallet.d.ts +12 -0
- package/dist/types/modules/checkout/payment-session-error.d.ts +4 -0
- package/dist/types/modules/checkout/stripe-js.d.ts +2 -0
- package/dist/types/modules/checkout/styles/delivery-method.style.d.ts +1 -0
- package/dist/types/modules/checkout/styles/express-checkout.style.d.ts +1 -0
- package/dist/types/modules/checkout/styles/express-completion.style.d.ts +1 -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/index.d.ts +1 -0
- package/dist/types/modules/product/components/product-add-to-cart-section.component.d.ts +8 -1
- package/dist/types/modules/product/components/product-delivery-estimate.component.d.ts +11 -0
- 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-prop65-warning.d.ts +1 -0
- 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/components/product-retailers-popup.component.d.ts +1 -0
- package/dist/types/modules/product/components/product-retailers.component.d.ts +1 -0
- package/dist/types/modules/product/product.commands.d.ts +5 -5
- package/dist/types/modules/product/product.component.d.ts +3 -0
- package/dist/types/modules/product/styles/prop65-warning.style.d.ts +1 -0
- package/dist/types/modules/product/styles/register-styles.d.ts +1 -0
- package/dist/types/modules/product-list/components/card-components/index.d.ts +6 -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-fulfillment-text.d.ts +2 -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 +39 -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 +54 -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 +27 -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 +10 -10
- 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 +9 -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 +15 -2
- 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 +8 -0
- package/dist/types/ssr/stub.d.ts +12 -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/delivery-scheduling.d.ts +43 -0
- package/dist/types/utils/dom-compat.d.ts +2 -0
- package/dist/types/utils/format.d.ts +9 -14
- package/dist/types/utils/image-bg-removal.d.ts +3 -0
- package/dist/types/utils/places-session-token.d.ts +1 -0
- package/dist/types/utils/product-selection.d.ts +16 -0
- package/dist/types/utils/product.d.ts +21 -0
- package/dist/types/utils/timezone.d.ts +6 -0
- package/docs/v1/README.md +214 -0
- package/docs/v1/api/actions/address-actions.md +290 -0
- package/docs/v1/api/actions/analytics-actions.md +326 -0
- package/docs/v1/api/actions/cart-actions.md +364 -0
- package/docs/v1/api/actions/checkout-actions.md +629 -0
- package/docs/v1/api/actions/product-actions.md +204 -0
- package/docs/v1/api/client.md +671 -0
- package/docs/v1/api/configuration.md +587 -0
- package/docs/v1/api/injection-methods.md +331 -0
- package/docs/v1/api/typescript-types.md +610 -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 +76 -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 +351 -0
- package/docs/v1/getting-started/quick-start.md +410 -0
- package/docs/v1/guides/accessibility.md +295 -0
- package/docs/v1/guides/address-component.md +441 -0
- package/docs/v1/guides/best-practices.md +365 -0
- package/docs/v1/guides/cart-component.md +800 -0
- package/docs/v1/guides/checkout-component.md +916 -0
- package/docs/v1/guides/events.md +1061 -0
- package/docs/v1/guides/product-component.md +761 -0
- package/docs/v1/guides/product-list-component.md +730 -0
- package/docs/v1/guides/theming.md +243 -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 +176 -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-helper.d.ts +0 -4
- 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,326 @@
|
|
|
1
|
+
# Analytics Actions API
|
|
2
|
+
|
|
3
|
+
Analytics actions report shopper steps that **your own UI** renders to the same Google Tag Manager /
|
|
4
|
+
GA4 stream that Elements components report to. Use them when you build part of the shopping
|
|
5
|
+
experience yourself — a product page, an address picker, a cart — and use Elements for the rest,
|
|
6
|
+
typically the checkout. They are available on the full client (`actions.analytics.*`) and on the
|
|
7
|
+
checkout-only client (`ElementsCheckout(...).actions.analytics.*`).
|
|
8
|
+
|
|
9
|
+
Each action pushes a GA4 event onto `window.dataLayer` in exactly the shape the SDK's own components
|
|
10
|
+
use — the same event name, the same `items[]` fields, the same `tenant_*` source fields and
|
|
11
|
+
`send_to` targets — so your reports and GTM triggers treat them like any other Elements event. See
|
|
12
|
+
[Analytics & Google Tag Manager](../../reference/analytics.md) for how the containers are loaded and
|
|
13
|
+
how events are queued.
|
|
14
|
+
|
|
15
|
+
## What to report, and what not to
|
|
16
|
+
|
|
17
|
+
- **Report only steps your UI renders.** A step an Elements component renders is already reported
|
|
18
|
+
by that component: reporting it again counts it twice. A product shown with `injectProductElement`
|
|
19
|
+
sends its own `view_item`, and adding it to the cart from that component sends `add_to_cart` and
|
|
20
|
+
`view_cart`. A list placed with `injectProductList` sends `view_item_list`, `select_item` and, from
|
|
21
|
+
its search box, `search`. The Elements cart sends `view_cart` when it opens and `remove_from_cart`
|
|
22
|
+
when an item goes.
|
|
23
|
+
- **The checkout reports itself.** `add_shipping_info`, `add_payment_info`, `purchase`, and the promo
|
|
24
|
+
code and gift card events come from the Elements checkout, so there are no actions for them.
|
|
25
|
+
- **Report once per state, not once per render.** A framework that re-renders, or runs effects
|
|
26
|
+
twice in development, should guard each report with the state it describes (for example the
|
|
27
|
+
product and size a `view_item` was sent for).
|
|
28
|
+
- **Where events go.** Events are sent only in `production` and `staging`, never in Builder mode.
|
|
29
|
+
They target the partner's enabled LiquidCommerce and partner GTM containers through `send_to`.
|
|
30
|
+
When neither container is enabled, an event still goes onto a `window.dataLayer` that is already on
|
|
31
|
+
the page — your own GTM's, for example — without `send_to`, exactly as the SDK's own events do.
|
|
32
|
+
Events reported before GTM finishes initializing are queued and sent once it is ready.
|
|
33
|
+
- **Reporting never breaks your page.** Malformed input does not throw: the event is skipped and a
|
|
34
|
+
warning is logged (visible with `debugMode: 'console'`, and sent to LiquidCommerce telemetry).
|
|
35
|
+
|
|
36
|
+
## The item
|
|
37
|
+
|
|
38
|
+
Every ecommerce action takes `IAnalyticsItem`, built from the product data your page already has:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
interface IAnalyticsItem {
|
|
42
|
+
id: string; // the selected size's id → item_id and product_id
|
|
43
|
+
name: string; // → item_name
|
|
44
|
+
brand?: string;
|
|
45
|
+
size?: string; // "750 ML"
|
|
46
|
+
categoryPath?: string; // product catPath, "spirits > whiskey > bourbon" → item_category 1–3
|
|
47
|
+
price?: number; // unit price in CENTS, as product responses carry it → dollars
|
|
48
|
+
quantity?: number;
|
|
49
|
+
type?: string;
|
|
50
|
+
subType?: string;
|
|
51
|
+
image?: string;
|
|
52
|
+
upc?: string;
|
|
53
|
+
groupingId?: string; // product salsifyGrouping
|
|
54
|
+
index?: number; // position in a list (viewItemList / selectItem)
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
From a product response (`getProductAvailabilityByState`, or the availability API your page loads
|
|
59
|
+
the product with):
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
const product = response.products[0];
|
|
63
|
+
const size = product.sizes[selectedSizeId];
|
|
64
|
+
|
|
65
|
+
const item = {
|
|
66
|
+
id: size.id,
|
|
67
|
+
name: product.name,
|
|
68
|
+
brand: product.brand,
|
|
69
|
+
size: size.size,
|
|
70
|
+
categoryPath: product.catPath,
|
|
71
|
+
price: selectedVariant ? selectedVariant.price : product.priceInfo.average,
|
|
72
|
+
type: product.type,
|
|
73
|
+
subType: product.subType,
|
|
74
|
+
image: size.image,
|
|
75
|
+
upc: size.upc,
|
|
76
|
+
groupingId: product.salsifyGrouping,
|
|
77
|
+
};
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`price` is in cents and is sent in dollars, like every Elements ecommerce event. Before the shopper
|
|
81
|
+
has an address, the SDK's own product component reports the product's average price; report the
|
|
82
|
+
selected variant's price once there is one.
|
|
83
|
+
|
|
84
|
+
An event is skipped, with a warning naming the problem, when an item has no `id` or `name`, a
|
|
85
|
+
negative or non-numeric `price`, a `quantity` that is not a positive integer, an `index` that is not
|
|
86
|
+
a non-negative integer, or a non-string text field; when a list of items is empty; when a list, an
|
|
87
|
+
option, an address field or coordinates have the wrong type; or when a `reason` / `error` is missing.
|
|
88
|
+
An omitted or empty `placesId` / `formattedAddress` is left out of the event rather than sent blank.
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## actions.analytics.search()
|
|
93
|
+
|
|
94
|
+
`search` — the shopper searches the catalog with your own search box. Sent as `search_term`, trimmed.
|
|
95
|
+
A product list's own search box reports its searches itself.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
search(searchTerm: string): void
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
actions.analytics.search(input.value);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## actions.analytics.viewItem()
|
|
108
|
+
|
|
109
|
+
`view_item` — the shopper sees a product. Report it when the product is shown and again when the
|
|
110
|
+
shopper switches size, as the SDK's product component does.
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
viewItem(item: IAnalyticsItem): void
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
actions.analytics.viewItem(item);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## actions.analytics.viewItemList()
|
|
123
|
+
|
|
124
|
+
`view_item_list` — the shopper sees a list of products.
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
viewItemList(items: IAnalyticsItem[], list?: { id?: string; name?: string }): void
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
```javascript
|
|
131
|
+
actions.analytics.viewItemList(
|
|
132
|
+
products.map((item, index) => ({ ...item, index })),
|
|
133
|
+
{ id: 'holiday-gifts', name: 'Holiday Gifts' }
|
|
134
|
+
);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## actions.analytics.selectItem()
|
|
140
|
+
|
|
141
|
+
`select_item` — the shopper picks a product from a list.
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
selectItem(item: IAnalyticsItem, list?: { id?: string; name?: string }): void
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## actions.analytics.addToCart()
|
|
150
|
+
|
|
151
|
+
`add_to_cart` — `item.quantity` is the quantity added (default 1). `value` is `price × quantity`.
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
addToCart(item: IAnalyticsItem): void
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Report it when the shopper commits to the product in your UI. `actions.cart.addProduct()` and
|
|
158
|
+
`actions.checkout.addProduct()` already report it (the latter reports `begin_checkout` too); `actions.checkout.addAnonymousProduct()` does
|
|
159
|
+
not, because hosts often call it ahead of time to prepare a checkout before the shopper commits.
|
|
160
|
+
|
|
161
|
+
```javascript
|
|
162
|
+
actions.analytics.addToCart({ ...item, quantity: 2 });
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## actions.analytics.removeFromCart()
|
|
168
|
+
|
|
169
|
+
`remove_from_cart` — `item.quantity` is the quantity removed.
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
removeFromCart(item: IAnalyticsItem): void
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## actions.analytics.viewCart()
|
|
178
|
+
|
|
179
|
+
`view_cart` — the shopper sees a cart your UI renders.
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
viewCart(items: IAnalyticsItem[]): void
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## actions.analytics.beginCheckout()
|
|
188
|
+
|
|
189
|
+
`begin_checkout` — the shopper commits to buying `items`. `value` is the sum of `price × quantity`.
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
beginCheckout(items: IAnalyticsItem[], options?: { coupon?: string }): void
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
```javascript
|
|
196
|
+
// "Proceed to checkout" in your own UI, before injecting the Elements checkout
|
|
197
|
+
actions.analytics.addToCart({ ...item, quantity });
|
|
198
|
+
actions.analytics.beginCheckout([{ ...item, quantity }], { coupon: 'WELCOME10' });
|
|
199
|
+
await client.injectCheckout({ containerId: 'checkout', checkoutId });
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Report it when **you** inject the checkout (`injectCheckout()` / `injectCheckoutElement()`) after
|
|
203
|
+
your own "Proceed" control. Don't report it when Elements started the checkout — it reports these
|
|
204
|
+
itself:
|
|
205
|
+
|
|
206
|
+
- the Elements cart's Checkout button, including when it redirects to your checkout page
|
|
207
|
+
(`checkout.pageUrl`) — so a page that injects the checkout for a shopper arriving from that
|
|
208
|
+
button must not report it again;
|
|
209
|
+
- `actions.checkout.addProduct()`;
|
|
210
|
+
- `actions.checkout.openCheckout()` and `toggleCheckout()` when they open the drawer;
|
|
211
|
+
- a presale added from the product component, which goes straight to checkout;
|
|
212
|
+
- the first wallet tap on express buttons placed on their own (below).
|
|
213
|
+
|
|
214
|
+
Wallet (Apple Pay / Google Pay) buttons placed on their own with `injectExpressCheckout` /
|
|
215
|
+
`injectExpressCheckoutElement` report `begin_checkout` themselves on the first tap — a wallet order
|
|
216
|
+
never passes through your "Proceed" control. Don't report it for them. If the buttons sit on your
|
|
217
|
+
product page and the checkout behind them was created with `addAnonymousProduct`, report the add
|
|
218
|
+
when the shopper taps: the tap happens inside Stripe's frame, and
|
|
219
|
+
[`lce:actions.checkout_express_checkout_started`](../../guides/events.md) is how your page hears of
|
|
220
|
+
it.
|
|
221
|
+
|
|
222
|
+
```javascript
|
|
223
|
+
window.addEventListener('lce:actions.checkout_express_checkout_started', () => {
|
|
224
|
+
actions.analytics.addToCart({ ...item, quantity });
|
|
225
|
+
});
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## actions.analytics.addressUpdated()
|
|
231
|
+
|
|
232
|
+
`address_updated` — an address the shopper chose in your UI resolved.
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
addressUpdated(address: {
|
|
236
|
+
placesId?: string; // → address_id
|
|
237
|
+
formattedAddress?: string;
|
|
238
|
+
address: Partial<IAddressAddress>;
|
|
239
|
+
coordinates?: IAddressCoordinates;
|
|
240
|
+
}): void
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
```javascript
|
|
244
|
+
actions.analytics.addressUpdated({
|
|
245
|
+
placesId,
|
|
246
|
+
formattedAddress: details.formattedAddress,
|
|
247
|
+
address: details.address,
|
|
248
|
+
coordinates: details.coordinates,
|
|
249
|
+
});
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
`actions.address.setAddressByPlacesId()` and `setAddressManually()` already report it.
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## actions.analytics.addressFailed()
|
|
257
|
+
|
|
258
|
+
`address_failed` — an address the shopper chose could not be resolved or used.
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
addressFailed(failure: {
|
|
262
|
+
placesId?: string;
|
|
263
|
+
formattedAddress?: string;
|
|
264
|
+
address?: Partial<IAddressAddress>;
|
|
265
|
+
error: string; // → address_error_message
|
|
266
|
+
}): void
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## actions.analytics.productNoAvailability()
|
|
272
|
+
|
|
273
|
+
`product_no_availability` — no size of the product sells where the shopper is.
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
productNoAvailability(details: {
|
|
277
|
+
item: IAnalyticsItem; // the product, keyed on the selected size
|
|
278
|
+
reason: string; // → availability_reason
|
|
279
|
+
address?: Partial<IAddressAddress>;
|
|
280
|
+
}): void
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
The no-availability events carry `product_*` fields rather than an `items[]` array, as the SDK's own
|
|
284
|
+
do, and `product_price` is sent **in cents** (the raw `item.price`), matching them.
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## actions.analytics.productSizeNoAvailability()
|
|
289
|
+
|
|
290
|
+
`product_size_no_availability` — the selected size has no fulfillment at the shopper's address,
|
|
291
|
+
though another size does. `item.id` and `item.size` are sent as `size_id` and `size_name`.
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
productSizeNoAvailability(details: { item: IAnalyticsItem; reason: string; address?: Partial<IAddressAddress> }): void
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
## actions.analytics.productFulfillmentNoAvailability()
|
|
300
|
+
|
|
301
|
+
`product_fulfillment_no_availability` — one fulfillment method (`onDemand` or `shipping`) can't be
|
|
302
|
+
used for the selected size: not offered there, or the retailer is closed.
|
|
303
|
+
|
|
304
|
+
```typescript
|
|
305
|
+
productFulfillmentNoAvailability(details: {
|
|
306
|
+
item: IAnalyticsItem;
|
|
307
|
+
reason: string;
|
|
308
|
+
address?: Partial<IAddressAddress>;
|
|
309
|
+
fulfillmentType: 'onDemand' | 'shipping';
|
|
310
|
+
}): void
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
```javascript
|
|
314
|
+
actions.analytics.productFulfillmentNoAvailability({
|
|
315
|
+
item,
|
|
316
|
+
reason: 'Not available in NY',
|
|
317
|
+
address: details.address,
|
|
318
|
+
fulfillmentType: 'onDemand',
|
|
319
|
+
});
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
## Related
|
|
323
|
+
|
|
324
|
+
- [Analytics & Google Tag Manager](../../reference/analytics.md)
|
|
325
|
+
- [Product Actions](./product-actions.md) · [Address Actions](./address-actions.md) · [Cart Actions](./cart-actions.md) · [Checkout Actions](./checkout-actions.md)
|
|
326
|
+
- [TypeScript Types](../typescript-types.md)
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
# Cart Actions API
|
|
2
|
+
|
|
3
|
+
Cart actions allow you to programmatically control the shopping cart.
|
|
4
|
+
|
|
5
|
+
## actions.cart.openCart()
|
|
6
|
+
|
|
7
|
+
Open the cart drawer.
|
|
8
|
+
|
|
9
|
+
### Signature
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
openCart(): void
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Example
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
window.LiquidCommerce.elements.actions.cart.openCart();
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## actions.cart.closeCart()
|
|
24
|
+
|
|
25
|
+
Close the cart drawer.
|
|
26
|
+
|
|
27
|
+
### Signature
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
closeCart(): void
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Example
|
|
34
|
+
|
|
35
|
+
```javascript
|
|
36
|
+
window.LiquidCommerce.elements.actions.cart.closeCart();
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## actions.cart.toggleCart()
|
|
42
|
+
|
|
43
|
+
Toggle the cart drawer open/closed.
|
|
44
|
+
|
|
45
|
+
### Signature
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
toggleCart(): void
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Example
|
|
52
|
+
|
|
53
|
+
```javascript
|
|
54
|
+
// Add to your cart button
|
|
55
|
+
document.getElementById('cart-btn').addEventListener('click', () => {
|
|
56
|
+
window.LiquidCommerce.elements.actions.cart.toggleCart();
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## actions.cart.addProduct()
|
|
63
|
+
|
|
64
|
+
Add products to the cart programmatically.
|
|
65
|
+
|
|
66
|
+
### Signature
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
addProduct(params: IAddProductParams[], openCart?: boolean): Promise<void>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Parameters
|
|
73
|
+
|
|
74
|
+
| Parameter | Type | Required | Description |
|
|
75
|
+
|-----------|------|----------|-------------|
|
|
76
|
+
| `params` | IAddProductParams[] | Yes | Array of products to add |
|
|
77
|
+
| `openCart` | boolean | No | Open cart after adding (default: false) |
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
interface IAddProductParams {
|
|
81
|
+
identifier: string; // Product UPC, size ID, or salsify grouping ID
|
|
82
|
+
fulfillmentType: FulfillmentType; // 'shipping' or 'onDemand'
|
|
83
|
+
quantity: number; // Number of items
|
|
84
|
+
engravingLines?: string[]; // Optional engraving (see below)
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
#### `engravingLines` (optional)
|
|
89
|
+
|
|
90
|
+
Pre-fills an engraving for the added item. The SDK enforces the product's engraving rules and degrades silently rather than failing the call:
|
|
91
|
+
|
|
92
|
+
- Non-string-array input is ignored (warning logged).
|
|
93
|
+
- Blank/whitespace-only entries are stripped; an empty result is treated as no engraving.
|
|
94
|
+
- If the product/size doesn't support engraving, lines are dropped.
|
|
95
|
+
- Lines beyond `maxLines` are sliced off; any line longer than `maxCharsPerLine` is truncated.
|
|
96
|
+
- If no engravable variant is available for the chosen fulfillment, lines are dropped and the item is still added.
|
|
97
|
+
|
|
98
|
+
### Example
|
|
99
|
+
|
|
100
|
+
```javascript
|
|
101
|
+
// Add single product
|
|
102
|
+
await window.LiquidCommerce.elements.actions.cart.addProduct([
|
|
103
|
+
{
|
|
104
|
+
identifier: '00619947000020',
|
|
105
|
+
fulfillmentType: 'shipping',
|
|
106
|
+
quantity: 1
|
|
107
|
+
}
|
|
108
|
+
], true); // Open cart after adding
|
|
109
|
+
|
|
110
|
+
// Add multiple products
|
|
111
|
+
await window.LiquidCommerce.elements.actions.cart.addProduct([
|
|
112
|
+
{
|
|
113
|
+
identifier: '00619947000020',
|
|
114
|
+
fulfillmentType: 'shipping',
|
|
115
|
+
quantity: 2
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
identifier: '08504405135',
|
|
119
|
+
fulfillmentType: 'onDemand',
|
|
120
|
+
quantity: 1
|
|
121
|
+
}
|
|
122
|
+
]);
|
|
123
|
+
|
|
124
|
+
// Add a product with engraving
|
|
125
|
+
await window.LiquidCommerce.elements.actions.cart.addProduct([
|
|
126
|
+
{
|
|
127
|
+
identifier: '00619947000020',
|
|
128
|
+
fulfillmentType: 'shipping',
|
|
129
|
+
quantity: 1,
|
|
130
|
+
engravingLines: ['Happy Birthday', 'Love, Sam']
|
|
131
|
+
}
|
|
132
|
+
], true);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Address Requirement
|
|
136
|
+
|
|
137
|
+
If no address is set, the SDK automatically:
|
|
138
|
+
1. Opens address input drawer
|
|
139
|
+
2. Waits for user to set address
|
|
140
|
+
3. Retries add-to-cart operation
|
|
141
|
+
|
|
142
|
+
### Errors
|
|
143
|
+
|
|
144
|
+
**Throws `SDKError` if:**
|
|
145
|
+
- Identifier is invalid
|
|
146
|
+
- Fulfillment type is not `'shipping'` or `'onDemand'`
|
|
147
|
+
- Quantity is less than 1
|
|
148
|
+
|
|
149
|
+
Unavailable products and presale items are **not** thrown — they are silently skipped (a `cart.error` is set on the store). If no products could be added, a `cart_product_add_failed` event is emitted with `{ cartId, identifiers, error }` and the returned promise still resolves (it does not reject).
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## actions.cart.applyPromoCode()
|
|
154
|
+
|
|
155
|
+
Apply a promo code to the cart.
|
|
156
|
+
|
|
157
|
+
### Signature
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
applyPromoCode(promoCode: string): Promise<void>
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Parameters
|
|
164
|
+
|
|
165
|
+
| Parameter | Type | Required | Description |
|
|
166
|
+
|-----------|------|----------|-------------|
|
|
167
|
+
| `promoCode` | string | Yes | Promo code to apply |
|
|
168
|
+
|
|
169
|
+
### Example
|
|
170
|
+
|
|
171
|
+
```javascript
|
|
172
|
+
// Listen for the outcome — an invalid code surfaces here, not as a rejection
|
|
173
|
+
window.addEventListener('lce:actions.cart_promo_code_failed', (event) => {
|
|
174
|
+
console.error('Invalid promo code:', event.detail.data);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
try {
|
|
178
|
+
await window.LiquidCommerce.elements.actions.cart.applyPromoCode('SUMMER20');
|
|
179
|
+
} catch (error) {
|
|
180
|
+
// Only reached on unexpected errors, not for an invalid code
|
|
181
|
+
console.error('Failed to apply promo code:', error);
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Notes
|
|
186
|
+
|
|
187
|
+
- Code is automatically normalized (trimmed, uppercased)
|
|
188
|
+
- Promo codes must be enabled in configuration
|
|
189
|
+
- Only one promo code can be active at a time
|
|
190
|
+
- Applying a new code replaces the existing one
|
|
191
|
+
- An invalid/rejected code does **not** reject the promise — the failure is surfaced via the `lce:actions.cart_promo_code_failed` event. Listen for that event to handle invalid codes.
|
|
192
|
+
- An empty or whitespace-only code is a silent no-op: it sets a `cart.error` on the store and returns without throwing.
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## actions.cart.removePromoCode()
|
|
197
|
+
|
|
198
|
+
Remove the active promo code.
|
|
199
|
+
|
|
200
|
+
### Signature
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
removePromoCode(): Promise<void>
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Example
|
|
207
|
+
|
|
208
|
+
```javascript
|
|
209
|
+
await window.LiquidCommerce.elements.actions.cart.removePromoCode();
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## actions.cart.resetCart()
|
|
215
|
+
|
|
216
|
+
Clear all items from the cart.
|
|
217
|
+
|
|
218
|
+
### Signature
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
resetCart(): Promise<void>
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Example
|
|
225
|
+
|
|
226
|
+
```javascript
|
|
227
|
+
await window.LiquidCommerce.elements.actions.cart.resetCart();
|
|
228
|
+
console.log('Cart cleared');
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Warning
|
|
232
|
+
|
|
233
|
+
This permanently removes all cart items. There is no undo.
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## actions.cart.getDetails()
|
|
238
|
+
|
|
239
|
+
Retrieve current cart information.
|
|
240
|
+
|
|
241
|
+
### Signature
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
getDetails(): IBaseCartEventData
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Returns
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
interface IBaseCartEventData {
|
|
251
|
+
cartId: string;
|
|
252
|
+
promoCodeDiscount: number | null; // in cents
|
|
253
|
+
subtotal: number; // in cents
|
|
254
|
+
itemCount: number;
|
|
255
|
+
items: Record<string, ICartItem>; // keyed by item ID
|
|
256
|
+
retailers: Record<string, ICartRetailer>; // keyed by retailer ID
|
|
257
|
+
location: {
|
|
258
|
+
placesId: string;
|
|
259
|
+
formattedAddress: string;
|
|
260
|
+
address: IAddressAddress;
|
|
261
|
+
coordinates: IAddressCoordinates;
|
|
262
|
+
} | null;
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Example
|
|
267
|
+
|
|
268
|
+
```javascript
|
|
269
|
+
const cart = window.LiquidCommerce.elements.actions.cart.getDetails();
|
|
270
|
+
|
|
271
|
+
console.log(`Cart ID: ${cart.cartId}`);
|
|
272
|
+
console.log(`Items: ${cart.itemCount}`);
|
|
273
|
+
console.log(`Subtotal: $${cart.subtotal / 100}`);
|
|
274
|
+
|
|
275
|
+
if (cart.promoCodeDiscount) {
|
|
276
|
+
console.log(`Discount: $${cart.promoCodeDiscount / 100}`);
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Use Cases
|
|
281
|
+
|
|
282
|
+
#### Display Cart Summary
|
|
283
|
+
|
|
284
|
+
```javascript
|
|
285
|
+
function updateCartSummary() {
|
|
286
|
+
const cart = window.LiquidCommerce.elements.actions.cart.getDetails();
|
|
287
|
+
|
|
288
|
+
document.getElementById('cart-count').textContent = cart.itemCount;
|
|
289
|
+
document.getElementById('cart-total').textContent = `$${cart.subtotal / 100}`;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Update on cart changes
|
|
293
|
+
window.addEventListener('lce:actions.cart_updated', updateCartSummary);
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
#### Check Cart Before Checkout
|
|
297
|
+
|
|
298
|
+
```javascript
|
|
299
|
+
document.getElementById('checkout-btn').addEventListener('click', () => {
|
|
300
|
+
const cart = window.LiquidCommerce.elements.actions.cart.getDetails();
|
|
301
|
+
|
|
302
|
+
if (cart.itemCount === 0) {
|
|
303
|
+
alert('Your cart is empty');
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
window.LiquidCommerce.elements.actions.checkout.openCheckout();
|
|
308
|
+
});
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
#### Track Cart Value
|
|
312
|
+
|
|
313
|
+
```javascript
|
|
314
|
+
const cart = window.LiquidCommerce.elements.actions.cart.getDetails();
|
|
315
|
+
|
|
316
|
+
gtag('event', 'view_cart', {
|
|
317
|
+
value: cart.subtotal / 100,
|
|
318
|
+
currency: 'USD',
|
|
319
|
+
items: Object.values(cart.items).map(item => ({
|
|
320
|
+
item_id: item.partNumber,
|
|
321
|
+
quantity: item.quantity
|
|
322
|
+
}))
|
|
323
|
+
});
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## Events
|
|
327
|
+
|
|
328
|
+
Cart actions trigger events that you can listen for:
|
|
329
|
+
|
|
330
|
+
```javascript
|
|
331
|
+
// Item added
|
|
332
|
+
window.addEventListener('lce:actions.cart_item_added', (event) => {
|
|
333
|
+
console.log('Item added:', event.detail.data);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// Cart updated
|
|
337
|
+
window.addEventListener('lce:actions.cart_updated', (event) => {
|
|
338
|
+
console.log('Cart updated:', event.detail.data);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
// Promo code applied
|
|
342
|
+
window.addEventListener('lce:actions.cart_promo_code_applied', (event) => {
|
|
343
|
+
console.log('Promo applied:', event.detail.data);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
// Product add success
|
|
347
|
+
window.addEventListener('lce:actions.cart_product_add_success', (event) => {
|
|
348
|
+
console.log('Products added:', event.detail.data);
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
// Product add failed
|
|
352
|
+
window.addEventListener('lce:actions.cart_product_add_failed', (event) => {
|
|
353
|
+
console.error('Failed to add:', event.detail.data);
|
|
354
|
+
});
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
See [Events Guide](../../guides/events.md) for all cart events.
|
|
358
|
+
|
|
359
|
+
## See Also
|
|
360
|
+
|
|
361
|
+
- [Cart Component Guide](../../guides/cart-component.md)
|
|
362
|
+
- [Cart Events](../../guides/events.md#cart-events)
|
|
363
|
+
- [Product Actions](./product-actions.md)
|
|
364
|
+
- [Checkout Actions](./checkout-actions.md)
|