zz-shopify-components 0.24.1-beta.2 → 0.24.1-beta.3

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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zz-shopify-components",
3
- "version": "0.24.1-beta.2",
3
+ "version": "0.24.1-beta.3",
4
4
  "description": "Reusable Shopify components for theme projects",
5
5
  "keywords": [
6
6
  "shopify",
@@ -191,32 +191,51 @@
191
191
  });
192
192
 
193
193
  window.accessoriesPointClickHandler = async function(variantId) {
194
- try {
195
- const res = await fetch(window.routes.cart_add_url, {
196
- method: 'POST',
197
- headers: {
198
- 'Content-Type': 'application/json',
199
- 'Accept': 'application/json'
194
+ const data = {
195
+ items: [
196
+ {
197
+ id: variantId,
198
+ quantity: 1,
200
199
  },
201
- body: JSON.stringify({
202
- items: [{ id: variantId, quantity: 1 }]
203
- })
200
+ ],
201
+ sections: 'cart-drawer,cart-icon-bubble',
202
+ };
203
+ const cart = document.querySelector('cart-drawer');
204
+
205
+ await fetch(`${routes.cart_add_url}`, {
206
+ method: 'POST',
207
+ headers: {
208
+ 'Content-Type': 'application/json',
209
+ Accept: 'application/javascript',
210
+ },
211
+ body: JSON.stringify(data),
212
+ })
213
+ .then((response) => response.json())
214
+ .then((response) => {
215
+ if (response.status) {
216
+ publish(PUB_SUB_EVENTS.cartError, {
217
+ source: 'product-form',
218
+ productVariantId: variantId,
219
+ errors: response.errors || response.description,
220
+ message: response.message,
221
+ });
222
+ }
223
+
224
+ publish(PUB_SUB_EVENTS.cartUpdate, {
225
+ source: 'product-form',
226
+ productVariantId: variantId,
227
+ cartData: response,
228
+ });
229
+ cart.renderContents(response, false);
230
+ zzShowToast('1 item added to Cart', { type: 'success' });
231
+
232
+ })
233
+ .catch((e) => {
234
+ console.error(e);
235
+ })
236
+ .finally(() => {
237
+ if (cart && cart.classList.contains('is-empty'))
238
+ cart.classList.remove('is-empty');
204
239
  });
205
- const data = await res.json();
206
- if (data && data.status) {
207
- console.error('Add to cart error:', data);
208
- alert(data.message || 'Failed to add to cart');
209
- return;
210
- }
211
- const cartDrawer = document.querySelector('cart-drawer');
212
- if (cartDrawer && typeof cartDrawer.renderContents === 'function') {
213
- cartDrawer.renderContents(data);
214
- if (typeof cartDrawer.open === 'function') cartDrawer.open();
215
- } else {
216
- window.location.href = window.routes.cart_url;
217
- }
218
- } catch (e) {
219
- console.error(e);
220
- }
221
240
  };
222
241
  </script>