@ordergroove/offers 2.30.3 → 2.30.4
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/CHANGELOG.md +11 -0
- package/dist/bundle-report.html +2 -2
- package/dist/offers.js +16 -16
- package/dist/offers.js.map +2 -2
- package/package.json +2 -2
- package/src/shopify/shopifyMiddleware.ts +12 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ordergroove/offers",
|
|
3
|
-
"version": "2.30.
|
|
3
|
+
"version": "2.30.4",
|
|
4
4
|
"description": "offer state component",
|
|
5
5
|
"author": "Eugenio Lattanzio <eugenio63@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/ordergroove/plush-toys#readme",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@ordergroove/offers-templates": "^0.5.2"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "8f41940bb20d4eb376250add3aaa154e773a481b"
|
|
51
51
|
}
|
|
@@ -27,14 +27,15 @@ const PRODUCTS_URL = `${SHOPIFY_ROOT}products/`;
|
|
|
27
27
|
*/
|
|
28
28
|
const DEFAULT_SHOPIFY_CART_AJAX_SECTIONS =
|
|
29
29
|
'[id^="shopify-section-"][id$=__cart-items], [id^="shopify-section-"][id$="__cart-footer"],#cart-live-region-text,#cart-icon-bubble';
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
30
|
+
const makeSyncProductId = offer =>
|
|
31
|
+
debounce(100, false, function(form) {
|
|
32
|
+
const { id } = Object.fromEntries([...new FormData(form).entries()]);
|
|
33
|
+
if (id) {
|
|
34
|
+
offer.setAttribute('product', id);
|
|
35
|
+
} else {
|
|
36
|
+
offer.removeAttribute('product');
|
|
37
|
+
}
|
|
38
|
+
});
|
|
38
39
|
|
|
39
40
|
async function setupPdp(store, offer) {
|
|
40
41
|
const handle = guessProductHandle(offer);
|
|
@@ -48,7 +49,6 @@ async function setupPdp(store, offer) {
|
|
|
48
49
|
}
|
|
49
50
|
// try closest form (safer)
|
|
50
51
|
let form = offer.closest('form');
|
|
51
|
-
|
|
52
52
|
// sometimes template is so closest does not work
|
|
53
53
|
// <div>
|
|
54
54
|
// <og-offer ..>
|
|
@@ -69,8 +69,9 @@ async function setupPdp(store, offer) {
|
|
|
69
69
|
|
|
70
70
|
if (form) {
|
|
71
71
|
// since syncProductId is debounced not matter which comes first mutation or onchange
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
const syncProductId = makeSyncProductId(offer);
|
|
73
|
+
form.addEventListener('change', ev => syncProductId(form));
|
|
74
|
+
const mo = new MutationObserver(() => syncProductId(form));
|
|
74
75
|
mo.observe(form, { subtree: true, childList: true });
|
|
75
76
|
} else {
|
|
76
77
|
console.info('no /cart/add form found for og-offer', offer);
|