zz-shopify-components 0.12.1-beta.2 → 0.13.0

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.
@@ -17,7 +17,6 @@ class BuyNowBottomBar extends HTMLElement {
17
17
  this.hasCare = this.dataset.hasCare || false;
18
18
  this.init();
19
19
  this.currency = this.dataset.currency;
20
- this.isocode = this.dataset.isocode;
21
20
  this.isEduProduct = this.dataset.isEduProduct === 'true';
22
21
  this.isLoggedIn = this.dataset.isLoggedIn === 'true';
23
22
  this.isEduVerified = this.dataset.isEduVerified === 'true';
@@ -37,9 +36,6 @@ class BuyNowBottomBar extends HTMLElement {
37
36
  }
38
37
  );
39
38
  }
40
- window.addEventListener('pageshow', () => {
41
- this.updatePrice();
42
- });
43
39
  }
44
40
  handleAddToCart() {
45
41
  this.getMainProduct();
@@ -57,12 +53,12 @@ class BuyNowBottomBar extends HTMLElement {
57
53
 
58
54
  handleToPay() {
59
55
  this.getMainProduct();
60
- const cartUrl = `/cart/${this.mainProductId}:${this.mainProductQuantity}?checkout&currency=${this.isocode}`;
61
-
56
+ const cartUrl = `/cart/${this.mainProductId}:${this.mainProductQuantity} `
62
57
  window.location.href = cartUrl;
63
58
  }
64
59
 
65
60
  async onSubmitHandler() {
61
+
66
62
  const data = {
67
63
  items: [
68
64
  {
@@ -131,12 +127,10 @@ class BuyNowBottomBar extends HTMLElement {
131
127
  }
132
128
 
133
129
  getMainProduct() {
134
- this.mainProductId = document.querySelector(
135
- 'product-buy-now-selector'
136
- ).currentVariantId;
137
- this.mainProductQuantity = document.querySelector(
138
- 'product-buy-now-counter input'
139
- ).value;
130
+ this.mainProductId =
131
+ document.querySelector('product-buy-now-selector').currentVariantId;
132
+ this.mainProductQuantity =
133
+ document.querySelector('product-buy-now-counter input').value;
140
134
  }
141
135
  getBindProduct() {
142
136
  this.bindProducts = [];
@@ -212,14 +206,10 @@ class BuyNowBottomBar extends HTMLElement {
212
206
  if (!window.Decimal) {
213
207
  return;
214
208
  }
215
- console.log('this.isocode', this.isocode);
216
- console.log('this.currency', this.currency);
217
209
  const main = document
218
210
  .querySelector('.product-version-option input:checked')
219
211
  ?.closest('.product-version-option');
220
- const mainProductQuantity = document.querySelector(
221
- 'product-buy-now-counter input'
222
- ).value;
212
+
223
213
  const {
224
214
  price: mainPrice,
225
215
  before: mainBefore,
@@ -228,11 +218,7 @@ class BuyNowBottomBar extends HTMLElement {
228
218
 
229
219
  let total_price = new Decimal(this.handlePrice(mainPrice));
230
220
  let total_before = new Decimal(this.handlePrice(mainBefore));
231
- total_price = total_price.times(mainProductQuantity);
232
- total_before = total_before.times(mainProductQuantity);
233
221
 
234
- console.log('total_price', total_price);
235
- console.log('total_before', total_before);
236
222
  this.toggleAddToCartButton(mainAvailable);
237
223
 
238
224
  // 找到被选中的附加产品
@@ -292,24 +278,14 @@ class BuyNowBottomBar extends HTMLElement {
292
278
  const showBefore = total_before.greaterThan(total_price);
293
279
  requestAnimationFrame(() => {
294
280
  const priceEl = this.querySelector('.price');
295
- if (priceEl) {
296
- priceEl.textContent = Shopify.formatMoneyFromDecimal(total_price);
297
- }
298
-
299
281
  const beforeEl = this.querySelector('.before');
300
- if (beforeEl) {
301
- beforeEl.textContent = Shopify.formatMoneyFromDecimal(total_before);
302
- }
303
-
304
282
  const mbPriceEl = this.querySelector('.mb_price');
305
- if (mbPriceEl) {
306
- mbPriceEl.textContent = Shopify.formatMoneyFromDecimal(total_price);
307
- }
308
-
309
283
  const mbBeforeEl = this.querySelector('.mb_before');
310
- if (mbBeforeEl) {
311
- mbBeforeEl.textContent = Shopify.formatMoneyFromDecimal(total_before);
312
- }
284
+
285
+ if (priceEl) priceEl.textContent = priceText;
286
+ if (beforeEl) beforeEl.textContent = showBefore ? beforeText : '';
287
+ if (mbPriceEl) mbPriceEl.textContent = priceText;
288
+ if (mbBeforeEl) mbBeforeEl.textContent = showBefore ? beforeText : '';
313
289
 
314
290
  // 计算折扣
315
291
  const discountEl = this.querySelectorAll('.price-discouter');
@@ -343,24 +319,8 @@ class BuyNowBottomBar extends HTMLElement {
343
319
  this.updatePayPal(total_price.toString());
344
320
  }
345
321
  handlePrice(price) {
346
- console.log('handlePrice', price);
347
- if (!price) return 0;
348
- if (this.currency === '€') {
349
- return this.handleEuroPrice(price);
350
- }
351
322
  return price.toString().replace(/,/g, '') || 0;
352
323
  }
353
- handleEuroPrice(price) {
354
- let result = price.toString();
355
- const priceFormat = this.dataset.priceFormat || '';
356
- if (priceFormat.includes('amount_with_comma_separator')) {
357
- result = result.replace('.', '');
358
- result = result.replace(',', '.');
359
- } else {
360
- result = result.replace(/,/g, '');
361
- }
362
- return result || 0;
363
- }
364
324
 
365
325
  updatePayPal(price) {
366
326
  if (!price) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zz-shopify-components",
3
- "version": "0.12.1-beta.2",
3
+ "version": "0.13.0",
4
4
  "description": "Reusable Shopify components for theme projects",
5
5
  "keywords": [
6
6
  "shopify",
@@ -276,19 +276,10 @@
276
276
  #shopify-section-{{ section.id }} .product-version-option:has(input[type='radio']:checked) {
277
277
  border-color: #FFD400;
278
278
  }
279
- @media (max-width: 750px) {
280
- body {
281
- background: #fff;
282
- padding-bottom: 118px !important;
283
- }
284
- }
285
- @media (min-width: 750px) {
286
- body {
287
- background: #fff;
288
- padding-bottom: 72px !important;
289
- }
279
+ body {
280
+ background: #fff;
281
+ padding-bottom: 160px !important;
290
282
  }
291
-
292
283
  </style>
293
284
  <script defer src='{{ 'zz-product-buy-now-select.js' | asset_url }}'></script>
294
285
 
@@ -22,9 +22,7 @@
22
22
  data-care-guide='{{ care_guide_type }}'
23
23
  data-is-edu-product='{{ is_edu_product }}'
24
24
  data-is-logged-in='{{ is_logged_in }}'
25
- data-price-format='{{ shop.money_format }}'
26
25
  data-is-edu-verified='{{ is_edu_verified }}'
27
- data-isocode='{{ localization.country.currency.iso_code }}'
28
26
  data-edu-page-url='{{ shop.metafields.custom.edu_home_page.value.url }}'
29
27
  class=' tw-left-0 tw-right-0 tw-max-w-screen tw-bg-white tw-bottom-0 tw-z-50 !tw-fixed buy-now-bottom-bar'
30
28
  >