@liquidcommerce/elements-sdk 2.6.0-beta.9 → 2.6.0-beta.91

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