zz-shopify-components 0.13.0 → 0.15.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,6 +17,7 @@ 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;
|
|
20
21
|
this.isEduProduct = this.dataset.isEduProduct === 'true';
|
|
21
22
|
this.isLoggedIn = this.dataset.isLoggedIn === 'true';
|
|
22
23
|
this.isEduVerified = this.dataset.isEduVerified === 'true';
|
|
@@ -36,6 +37,9 @@ class BuyNowBottomBar extends HTMLElement {
|
|
|
36
37
|
}
|
|
37
38
|
);
|
|
38
39
|
}
|
|
40
|
+
window.addEventListener('pageshow', () => {
|
|
41
|
+
this.updatePrice();
|
|
42
|
+
});
|
|
39
43
|
}
|
|
40
44
|
handleAddToCart() {
|
|
41
45
|
this.getMainProduct();
|
|
@@ -53,12 +57,12 @@ class BuyNowBottomBar extends HTMLElement {
|
|
|
53
57
|
|
|
54
58
|
handleToPay() {
|
|
55
59
|
this.getMainProduct();
|
|
56
|
-
const cartUrl = `/cart/${this.mainProductId}:${this.mainProductQuantity}
|
|
60
|
+
const cartUrl = `/cart/${this.mainProductId}:${this.mainProductQuantity}?checkout¤cy=${this.isocode}`;
|
|
61
|
+
|
|
57
62
|
window.location.href = cartUrl;
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
async onSubmitHandler() {
|
|
61
|
-
|
|
62
66
|
const data = {
|
|
63
67
|
items: [
|
|
64
68
|
{
|
|
@@ -127,10 +131,12 @@ class BuyNowBottomBar extends HTMLElement {
|
|
|
127
131
|
}
|
|
128
132
|
|
|
129
133
|
getMainProduct() {
|
|
130
|
-
this.mainProductId =
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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;
|
|
134
140
|
}
|
|
135
141
|
getBindProduct() {
|
|
136
142
|
this.bindProducts = [];
|
|
@@ -206,10 +212,14 @@ class BuyNowBottomBar extends HTMLElement {
|
|
|
206
212
|
if (!window.Decimal) {
|
|
207
213
|
return;
|
|
208
214
|
}
|
|
215
|
+
console.log('this.isocode', this.isocode);
|
|
216
|
+
console.log('this.currency', this.currency);
|
|
209
217
|
const main = document
|
|
210
218
|
.querySelector('.product-version-option input:checked')
|
|
211
219
|
?.closest('.product-version-option');
|
|
212
|
-
|
|
220
|
+
const mainProductQuantity = document.querySelector(
|
|
221
|
+
'product-buy-now-counter input'
|
|
222
|
+
).value;
|
|
213
223
|
const {
|
|
214
224
|
price: mainPrice,
|
|
215
225
|
before: mainBefore,
|
|
@@ -218,7 +228,11 @@ class BuyNowBottomBar extends HTMLElement {
|
|
|
218
228
|
|
|
219
229
|
let total_price = new Decimal(this.handlePrice(mainPrice));
|
|
220
230
|
let total_before = new Decimal(this.handlePrice(mainBefore));
|
|
231
|
+
total_price = total_price.times(mainProductQuantity);
|
|
232
|
+
total_before = total_before.times(mainProductQuantity);
|
|
221
233
|
|
|
234
|
+
console.log('total_price', total_price);
|
|
235
|
+
console.log('total_before', total_before);
|
|
222
236
|
this.toggleAddToCartButton(mainAvailable);
|
|
223
237
|
|
|
224
238
|
// 找到被选中的附加产品
|
|
@@ -278,14 +292,24 @@ class BuyNowBottomBar extends HTMLElement {
|
|
|
278
292
|
const showBefore = total_before.greaterThan(total_price);
|
|
279
293
|
requestAnimationFrame(() => {
|
|
280
294
|
const priceEl = this.querySelector('.price');
|
|
295
|
+
if (priceEl) {
|
|
296
|
+
priceEl.textContent = Shopify.formatMoneyFromDecimal(total_price);
|
|
297
|
+
}
|
|
298
|
+
|
|
281
299
|
const beforeEl = this.querySelector('.before');
|
|
300
|
+
if (beforeEl) {
|
|
301
|
+
beforeEl.textContent = Shopify.formatMoneyFromDecimal(total_before);
|
|
302
|
+
}
|
|
303
|
+
|
|
282
304
|
const mbPriceEl = this.querySelector('.mb_price');
|
|
283
|
-
|
|
305
|
+
if (mbPriceEl) {
|
|
306
|
+
mbPriceEl.textContent = Shopify.formatMoneyFromDecimal(total_price);
|
|
307
|
+
}
|
|
284
308
|
|
|
285
|
-
|
|
286
|
-
if (
|
|
287
|
-
|
|
288
|
-
|
|
309
|
+
const mbBeforeEl = this.querySelector('.mb_before');
|
|
310
|
+
if (mbBeforeEl) {
|
|
311
|
+
mbBeforeEl.textContent = Shopify.formatMoneyFromDecimal(total_before);
|
|
312
|
+
}
|
|
289
313
|
|
|
290
314
|
// 计算折扣
|
|
291
315
|
const discountEl = this.querySelectorAll('.price-discouter');
|
|
@@ -319,8 +343,24 @@ class BuyNowBottomBar extends HTMLElement {
|
|
|
319
343
|
this.updatePayPal(total_price.toString());
|
|
320
344
|
}
|
|
321
345
|
handlePrice(price) {
|
|
346
|
+
console.log('handlePrice', price);
|
|
347
|
+
if (!price) return 0;
|
|
348
|
+
if (this.currency === '€') {
|
|
349
|
+
return this.handleEuroPrice(price);
|
|
350
|
+
}
|
|
322
351
|
return price.toString().replace(/,/g, '') || 0;
|
|
323
352
|
}
|
|
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
|
+
}
|
|
324
364
|
|
|
325
365
|
updatePayPal(price) {
|
|
326
366
|
if (!price) return;
|
package/assets/zz-components.css
CHANGED
|
@@ -183,6 +183,17 @@
|
|
|
183
183
|
"label": "移动端圆角大小",
|
|
184
184
|
"default": 0
|
|
185
185
|
},
|
|
186
|
+
{
|
|
187
|
+
"type": "select",
|
|
188
|
+
"id": "pc_mobile_show",
|
|
189
|
+
"label": "PC/移动端分开显示",
|
|
190
|
+
"options": [
|
|
191
|
+
{ "value": "pc_mobile_show", "label": "PC/移动端都显示" },
|
|
192
|
+
{ "value": "pc_only", "label": "PC端显示" },
|
|
193
|
+
{ "value": "mobile_only", "label": "移动端显示" }
|
|
194
|
+
],
|
|
195
|
+
"default": "pc_mobile_show"
|
|
196
|
+
},
|
|
186
197
|
{
|
|
187
198
|
"type": "header",
|
|
188
199
|
"content": "动画设置"
|
|
@@ -256,13 +267,18 @@
|
|
|
256
267
|
{% endschema %}
|
|
257
268
|
|
|
258
269
|
<style>
|
|
259
|
-
|
|
260
|
-
{
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
270
|
+
@media (max-width: 1024px) {
|
|
271
|
+
#shopify-block-{{ block.id }} {
|
|
272
|
+
{% if block.settings.mobile_width == 0 %}
|
|
273
|
+
width: 100%;
|
|
274
|
+
flex: 1;
|
|
275
|
+
{% else %}
|
|
276
|
+
width: {{ block.settings.mobile_width }}%;
|
|
277
|
+
{% endif %}
|
|
278
|
+
{% if block.settings.pc_mobile_show == "pc_only" %}
|
|
279
|
+
display: none;
|
|
280
|
+
{% endif %}
|
|
281
|
+
}
|
|
266
282
|
}
|
|
267
283
|
#shopify-block-{{ block.id }} .flex-layout-widget-container {
|
|
268
284
|
width: 100%;
|
|
@@ -288,6 +304,9 @@
|
|
|
288
304
|
{% else %}
|
|
289
305
|
width: {{ block.settings.pc_width }}%;
|
|
290
306
|
{% endif %}
|
|
307
|
+
{% if block.settings.pc_mobile_show == "mobile_only" %}
|
|
308
|
+
display: none;
|
|
309
|
+
{% endif %}
|
|
291
310
|
}
|
|
292
311
|
#shopify-block-{{ block.id }} .flex-layout-widget-container {
|
|
293
312
|
width: 100%;
|
package/package.json
CHANGED
|
@@ -276,10 +276,19 @@
|
|
|
276
276
|
#shopify-section-{{ section.id }} .product-version-option:has(input[type='radio']:checked) {
|
|
277
277
|
border-color: #FFD400;
|
|
278
278
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
+
}
|
|
282
290
|
}
|
|
291
|
+
|
|
283
292
|
</style>
|
|
284
293
|
<script defer src='{{ 'zz-product-buy-now-select.js' | asset_url }}'></script>
|
|
285
294
|
|
|
@@ -22,7 +22,9 @@
|
|
|
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 }}'
|
|
25
26
|
data-is-edu-verified='{{ is_edu_verified }}'
|
|
27
|
+
data-isocode='{{ localization.country.currency.iso_code }}'
|
|
26
28
|
data-edu-page-url='{{ shop.metafields.custom.edu_home_page.value.url }}'
|
|
27
29
|
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'
|
|
28
30
|
>
|