@magic-spells/gift-with-purchase 1.0.0 → 2.0.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.
- package/README.md +56 -16
- package/dist/{gift-with-purchase.cjs.css → gift-with-purchase.css} +12 -9
- package/dist/gift-with-purchase.esm.js +226 -205
- package/dist/gift-with-purchase.min.css +2 -2
- package/dist/gift-with-purchase.min.js +1 -2
- package/package.json +16 -23
- package/dist/gift-with-purchase.cjs.css.map +0 -1
- package/dist/gift-with-purchase.cjs.js +0 -429
- package/dist/gift-with-purchase.cjs.js.map +0 -1
- package/dist/gift-with-purchase.esm.css +0 -46
- package/dist/gift-with-purchase.esm.css.map +0 -1
- package/dist/gift-with-purchase.esm.js.map +0 -1
- package/dist/gift-with-purchase.min.css.map +0 -1
- package/dist/gift-with-purchase.min.js.map +0 -1
- package/dist/gift-with-purchase.scss +0 -75
- package/src/gift-with-purchase.js +0 -428
- package/src/gift-with-purchase.scss +0 -75
|
@@ -1,2 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).GiftWithPurchase={})}(this,function(e){"
|
|
2
|
-
//# sourceMappingURL=gift-with-purchase.min.js.map
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).GiftWithPurchase={})}(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});var GiftWithPurchase=class extends HTMLElement{#e=0;#t=0;#a=null;#r=!1;#s=!1;#i=!1;#n=!0;#o=!1;#d=null;#l={};#c=null;#u=null;#h=!1;#m=!1;#p=null;#g=null;#b=null;static get observedAttributes(){return["threshold","current","variant-id","promo-ended","product-available","message-above","message-below","money-format"]}constructor(){super();const e=this;e.#e=parseFloat(e.getAttribute("threshold"))||0,e.#t=parseFloat(e.getAttribute("current"))||0,e.#a=e.getAttribute("variant-id"),e.#i=e.hasAttribute("promo-ended"),e.#n=e.#f(e.getAttribute("product-available"),!0),e.#p=e.getAttribute("message-above"),e.#g=e.getAttribute("message-below"),e.#b=e.getAttribute("money-format"),e.#l={cartDataChange:e.#v.bind(e)}}connectedCallback(){const e=this;e.#A(),e.#y(),e.#w(),e.#C(),!e.#o||e.#d&&!e.#d.hasAttribute("manual")||e.#T(null)}#A(){const e=this,t=e.#S();e.#o=e.#i||!e.#n,e.#r=e.#t>=t&&!e.#o}disconnectedCallback(){const e=this;e.#c&&clearTimeout(e.#c),e.#u&&clearTimeout(e.#u),e.#d&&e.#d.removeEventListener("cart-panel:data-changed",e.#l.cartDataChange)}attributeChangedCallback(e,t,a){const r=this;if(t===a)return;switch(e){case"threshold":r.#e=parseFloat(a)||0;break;case"current":r.#t=parseFloat(a)||0;break;case"variant-id":r.#a=a;break;case"promo-ended":r.#i=null!==a;break;case"product-available":r.#n=r.#f(a,!0);break;case"message-above":r.#p=a;break;case"message-below":r.#g=a;break;case"money-format":r.#b=a}if(!r.isConnected)return;const s=r.#o;r.#A(),r.#w(),r.#E(),r.#o&&!s&&r.#T(null)}#y(){this.classList.add("gift-with-purchase"),this.#P()}#P(){this.#E()}#M(e){if(!this.#b)return e.toFixed(2).replace(/\.00$/,"");const t=e.toFixed(2),a=Math.round(e).toString(),r=t.replace(".",","),s=a.replace(/\B(?=(\d{3})+(?!\d))/g,",");return this.#b.replace(/\{\{\s*amount_no_decimals_with_comma_separator\s*\}\}/g,s).replace(/\{\{\s*amount_with_comma_separator\s*\}\}/g,r).replace(/\{\{\s*amount_no_decimals\s*\}\}/g,a).replace(/\{\{\s*amount\s*\}\}/g,t)}#S(){const e=parseFloat(window.Shopify?.currency?.rate)||1;return this.#e*e}#f(e,t=!0){if(null==e)return t;if(""===e)return!0;const a=String(e).trim().toLowerCase();return"false"!==a&&"0"!==a&&("true"===a||"1"===a||t)}#E(){const e=this,t=e.querySelector("[data-content-gwp-message]");if(!t)return;let a="";if(e.#r&&e.#p)a=e.#p;else if(!e.#r&&e.#g){const t=e.#S()-e.#t,r=e.#M(t);a=e.#g.replace(/\[\s*amount\s*\]/g,r).replace(/\[amount\]/g,r)}t.textContent=a,t.style.display=a?"block":"none"}#C(){const e=this;e.#d=e.closest("cart-panel"),e.#d?e.#d.addEventListener("cart-panel:data-changed",e.#l.cartDataChange):e.#u=setTimeout(()=>{e.#u=null,e.#d=e.closest("cart-panel"),e.#d?e.#d.addEventListener("cart-panel:data-changed",e.#l.cartDataChange):console.error("GWP - cart-panel still not found after delay")},100)}#I(){const e=this.#d;e&&("function"==typeof e.refreshCart?e.refreshCart():"function"==typeof e.getCartAndRefresh&&e.getCartAndRefresh())}#v(e){const t=this,a=e.detail;a&&void 0!==a.calculated_subtotal&&(t.#c&&clearTimeout(t.#c),t.#c=setTimeout(()=>{t.#c=null,t.#h?t.#m=!0:(t.#t=parseFloat(a.calculated_subtotal/100)||0,t.#_(a),t.#T(a))},300))}#_(e){const t=this,a=t.#k(e);t.#s=a.length>0;const r=a.find(e=>e.quantity>1);r&&t.#D(r)}async#D(e){const t=this;t.#h=!0;try{const a=await fetch("/cart/change.js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},body:JSON.stringify({id:e.key,quantity:1})});if(!a.ok)throw new Error(`http ${a.status}`);t.#I()}catch(a){console.error("giftwithpurchase: quantity trim error",a),t.dispatchEvent(new CustomEvent("gwp:error",{detail:{action:"trim",error:a.message},bubbles:!0}))}finally{t.#h=!1,t.#F()}}#k(e){const t=this;return e?.items&&t.#a?e.items.filter(e=>"true"===e.properties?._gwp_item&&e.variant_id?.toString()===t.#a.toString()):[]}#F(){const e=this;e.#c&&(clearTimeout(e.#c),e.#c=null,e.#m=!0),e.#m&&(e.#m=!1,e.#d?e.#I():e.#T(null))}#T(e){const t=this;if(t.#h)return void(t.#m=!0);const a=t.#S();t.#o=t.#i||!t.#n,t.#r=t.#t>=a&&!t.#o,t.#o?t.#G(e):t.#r&&!t.#s&&t.#a?t.#L():!t.#r&&t.#s&&t.#a&&t.#G(e),t.#w(),t.#E()}#w(){const e=this;return e.#i?(e.setAttribute("state","ended"),void(e.style.display="none")):e.#n?(e.style.display="",void(e.#s?e.setAttribute("state","added"):e.#r?e.setAttribute("state","active"):e.setAttribute("state","inactive"))):(e.setAttribute("state","disabled"),void(e.style.display="none"))}async#L(){const e=this;e.#h=!0;try{const t=await fetch("/cart/add.js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},body:JSON.stringify({items:[{id:e.#a,quantity:1,properties:{_gwp_item:"true",_hide_in_cart:"true",_ignore_price_in_subtotal:"true"}}]})});if(!t.ok)throw new Error(`http ${t.status}`);await t.json(),e.#s=!0,e.dispatchEvent(new CustomEvent("gwp:added",{detail:{variantId:e.#a},bubbles:!0})),e.#I()}catch(t){console.error("giftwithpurchase: add error",t),e.dispatchEvent(new CustomEvent("gwp:error",{detail:{action:"add",error:t.message},bubbles:!0}))}finally{e.#h=!1,e.#F()}}async#G(e){const t=this;t.#h=!0;try{if(e?.items||(e=await t.#R()),!e?.items)return;const a=t.#k(e);if(!a.length)return void(t.#s=!1);await t.#q(a)}finally{t.#h=!1,t.#F()}}async#R(){const e=this;try{let t;if("function"==typeof e.#d?.getCart)t=await e.#d.getCart();else{const e=await fetch("/cart.js",{credentials:"same-origin"});if(!e.ok)throw new Error(`http ${e.status}`);t=await e.json()}return t?.error?null:t}catch(t){return console.error("giftwithpurchase: cart fetch error",t),null}}async#q(e){const t=this;try{await Promise.all(e.map(async e=>{const t=await fetch("/cart/change.js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},body:JSON.stringify({id:e.key,quantity:0})});if(!t.ok)throw new Error(`http ${t.status}`)})),t.#s=!1,t.dispatchEvent(new CustomEvent("gwp:removed",{detail:{variantId:t.#a},bubbles:!0})),t.#I()}catch(a){console.error("giftwithpurchase: bulk remove error",a),t.dispatchEvent(new CustomEvent("gwp:error",{detail:{action:"remove",error:a.message},bubbles:!0}))}}getState(){const e=this,t=e.#S();return{currentAmount:e.#t,threshold:e.#e,convertedThreshold:t,variantId:e.#a,isActive:e.#r,isAdded:e.#s,promoEnded:e.#i,productAvailable:e.#n,isDisabled:e.#o,remainingAmount:Math.max(0,t-e.#t),currencyRate:parseFloat(window.Shopify?.currency?.rate)||1}}get currentAmount(){return this.#t}get threshold(){return this.#e}get variantId(){return this.#a}get isActive(){return this.#r}get isAdded(){return this.#s}get promoEnded(){return this.#i}get productAvailable(){return this.#n}get isDisabled(){return this.#o}setCurrentAmount(e){const t=this;t.#t=parseFloat(e)||0,t.#T(null),t.#E()}setThreshold(e){const t=this;t.#e=parseFloat(e)||0,t.#T(null),t.#E()}setVariantId(e){this.#a=e}};customElements.get("gift-with-purchase")||customElements.define("gift-with-purchase",GiftWithPurchase),e.GiftWithPurchase=GiftWithPurchase});
|
package/package.json
CHANGED
|
@@ -1,33 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magic-spells/gift-with-purchase",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Gift with purchase web component for e-commerce threshold promotions.",
|
|
5
5
|
"author": "Cory Schulz",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"main": "dist/gift-with-purchase.
|
|
8
|
+
"main": "dist/gift-with-purchase.esm.js",
|
|
9
9
|
"module": "dist/gift-with-purchase.esm.js",
|
|
10
10
|
"unpkg": "dist/gift-with-purchase.min.js",
|
|
11
11
|
"style": "dist/gift-with-purchase.min.css",
|
|
12
|
-
"sass": "dist/gift-with-purchase.scss",
|
|
13
12
|
"exports": {
|
|
14
13
|
".": {
|
|
15
14
|
"import": "./dist/gift-with-purchase.esm.js",
|
|
16
|
-
"require": "./dist/gift-with-purchase.cjs.js",
|
|
17
15
|
"default": "./dist/gift-with-purchase.esm.js"
|
|
18
16
|
},
|
|
19
17
|
"./css": "./dist/gift-with-purchase.css",
|
|
20
|
-
"./css/min": "./dist/gift-with-purchase.min.css"
|
|
21
|
-
"./scss": "./dist/gift-with-purchase.scss"
|
|
18
|
+
"./css/min": "./dist/gift-with-purchase.min.css"
|
|
22
19
|
},
|
|
23
20
|
"sideEffects": true,
|
|
24
21
|
"repository": {
|
|
25
22
|
"type": "git",
|
|
26
|
-
"url": "https://github.com/magic-spells/
|
|
23
|
+
"url": "git+https://github.com/magic-spells/cart.git",
|
|
24
|
+
"directory": "packages/gift-with-purchase"
|
|
27
25
|
},
|
|
28
|
-
"homepage": "https://github.com/magic-spells/gift-with-purchase#readme",
|
|
26
|
+
"homepage": "https://github.com/magic-spells/cart/tree/main/packages/gift-with-purchase#readme",
|
|
29
27
|
"bugs": {
|
|
30
|
-
"url": "https://github.com/magic-spells/
|
|
28
|
+
"url": "https://github.com/magic-spells/cart/issues"
|
|
31
29
|
},
|
|
32
30
|
"keywords": [
|
|
33
31
|
"gift-with-purchase",
|
|
@@ -39,16 +37,14 @@
|
|
|
39
37
|
"cart-promotion"
|
|
40
38
|
],
|
|
41
39
|
"files": [
|
|
42
|
-
"dist/"
|
|
43
|
-
"src/"
|
|
40
|
+
"dist/"
|
|
44
41
|
],
|
|
45
42
|
"scripts": {
|
|
46
|
-
"build": "
|
|
47
|
-
"
|
|
43
|
+
"build": "NODE_ENV=production node scripts/build.mjs",
|
|
44
|
+
"dev": "NODE_ENV=development node scripts/build.mjs",
|
|
45
|
+
"lint": "eslint src/ scripts/",
|
|
48
46
|
"format": "prettier --write .",
|
|
49
|
-
"prepublishOnly": "npm run build"
|
|
50
|
-
"serve": "rollup -c --watch",
|
|
51
|
-
"dev": "rollup -c --watch"
|
|
47
|
+
"prepublishOnly": "npm run build"
|
|
52
48
|
},
|
|
53
49
|
"publishConfig": {
|
|
54
50
|
"access": "public",
|
|
@@ -61,15 +57,12 @@
|
|
|
61
57
|
],
|
|
62
58
|
"devDependencies": {
|
|
63
59
|
"@eslint/js": "^9.38.0",
|
|
64
|
-
"@
|
|
65
|
-
"@rollup/plugin-terser": "^0.4.4",
|
|
60
|
+
"@magic-spells/vite-plugin-live-reload": "^0.1.0",
|
|
66
61
|
"eslint": "^9.38.0",
|
|
67
62
|
"globals": "^15.15.0",
|
|
63
|
+
"lightningcss": "^1.29.3",
|
|
68
64
|
"prettier": "^3.3.3",
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"rollup-plugin-postcss": "^4.0.2",
|
|
72
|
-
"rollup-plugin-serve": "^1.1.1",
|
|
73
|
-
"sass": "^1.86.3"
|
|
65
|
+
"terser": "^5.16.0",
|
|
66
|
+
"vite": "^8.0.10"
|
|
74
67
|
}
|
|
75
68
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["gift-with-purchase.scss"],"names":[],"mappings":"AAAA;EACE,wBAAwB;EACxB,mBAAmB;EACnB,eAAe;EACf,wBAAwB;EACxB,uBAAuB;EACvB,4BAA4B;EAC5B,2BAA2B;EAC3B,0BAA0B;EAC1B,yBAAyB;EACzB,cAAc;EACd,0CAA0C;EAC1C,uCAAuC;EACvC,2BAA2B;EAC3B,sCAAsC;EACtC,6BAA6B;AAC/B;AACA;EACE,aAAa;EACb,uBAAuB;EACvB,mBAAmB;AACrB;AACA;EACE,cAAc;AAChB;AACA;EACE,OAAO;EACP,YAAY;AACd;AACA;EACE,sCAAsC;EACtC,sCAAsC;EACtC,6BAA6B;AAC/B;AACA;EACE,qCAAqC;EACrC,qCAAqC;EACrC,4BAA4B;AAC9B;AACA;EACE,aAAa;AACf;AACA;EACE,aAAa;AACf","file":"gift-with-purchase.cjs.css","sourcesContent":["gift-with-purchase {\n --gwp-border-radius: 8px;\n --gwp-padding: 1rem;\n --gwp-gap: 1rem;\n --gwp-bg-active: #e8f5e8;\n --gwp-bg-added: #d4edda;\n --gwp-border-active: #28a745;\n --gwp-border-added: #155724;\n --gwp-text-active: #155724;\n --gwp-text-added: #155724;\n display: block;\n border: 2px solid var(--gwp-border-active);\n border-radius: var(--gwp-border-radius);\n padding: var(--gwp-padding);\n background-color: var(--gwp-bg-active);\n color: var(--gwp-text-active);\n}\ngift-with-purchase .gwp-product {\n display: flex;\n align-items: flex-start;\n gap: var(--gwp-gap);\n}\ngift-with-purchase [data-gwp-image] {\n flex-shrink: 0;\n}\ngift-with-purchase .gwp-content {\n flex: 1;\n min-width: 0;\n}\ngift-with-purchase[state=active] {\n background-color: var(--gwp-bg-active);\n border-color: var(--gwp-border-active);\n color: var(--gwp-text-active);\n}\ngift-with-purchase[state=added] {\n background-color: var(--gwp-bg-added);\n border-color: var(--gwp-border-added);\n color: var(--gwp-text-added);\n}\ngift-with-purchase[state=ended] {\n display: none;\n}\ngift-with-purchase[state=disabled] {\n display: none;\n}"]}
|
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Gift With Purchase Component - automatically adds/removes gift when cart threshold is met
|
|
5
|
-
* Emits gwp:added/gwp:removed/gwp:error events and broadcasts cart updates
|
|
6
|
-
*/
|
|
7
|
-
class GiftWithPurchase extends HTMLElement {
|
|
8
|
-
#threshold = 0;
|
|
9
|
-
#currentAmount = 0;
|
|
10
|
-
#variantId = null;
|
|
11
|
-
#isActive = false;
|
|
12
|
-
#isAdded = false;
|
|
13
|
-
#promoEnded = false;
|
|
14
|
-
#productAvailable = true;
|
|
15
|
-
#isDisabled = false;
|
|
16
|
-
#cartPanel = null;
|
|
17
|
-
#handlers = {};
|
|
18
|
-
#debounceTimer = null;
|
|
19
|
-
#attachRetryTimer = null;
|
|
20
|
-
#isMutating = false; // prevents overlapping cart mutations
|
|
21
|
-
#pendingCart = null; // stores cart snapshot during mutation for recheck
|
|
22
|
-
#messageAbove = null;
|
|
23
|
-
#messageBelow = null;
|
|
24
|
-
#moneyFormat = null;
|
|
25
|
-
|
|
26
|
-
static get observedAttributes() {
|
|
27
|
-
return [
|
|
28
|
-
'threshold',
|
|
29
|
-
'current',
|
|
30
|
-
'variant-id',
|
|
31
|
-
'promo-ended',
|
|
32
|
-
'product-available',
|
|
33
|
-
'message-above',
|
|
34
|
-
'message-below',
|
|
35
|
-
'money-format',
|
|
36
|
-
];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
constructor() {
|
|
40
|
-
super();
|
|
41
|
-
const _ = this;
|
|
42
|
-
_.#threshold = parseFloat(_.getAttribute('threshold')) || 0;
|
|
43
|
-
_.#currentAmount = parseFloat(_.getAttribute('current')) || 0;
|
|
44
|
-
_.#variantId = _.getAttribute('variant-id');
|
|
45
|
-
_.#promoEnded = _.hasAttribute('promo-ended');
|
|
46
|
-
_.#productAvailable = _.#parseBooleanValue(_.getAttribute('product-available'), true);
|
|
47
|
-
_.#messageAbove = _.getAttribute('message-above');
|
|
48
|
-
_.#messageBelow = _.getAttribute('message-below');
|
|
49
|
-
_.#moneyFormat = _.getAttribute('money-format');
|
|
50
|
-
_.#handlers = { cartDataChange: _.#handleCartDataChange.bind(_) };
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
connectedCallback() {
|
|
54
|
-
const _ = this;
|
|
55
|
-
|
|
56
|
-
_.#calculateInitialState();
|
|
57
|
-
_.#render();
|
|
58
|
-
_.#updateVisualState();
|
|
59
|
-
_.#attachListeners();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
#calculateInitialState() {
|
|
63
|
-
const _ = this;
|
|
64
|
-
// Calculate initial active state based on attributes (before any cart events)
|
|
65
|
-
const convertedThreshold = _.#getConvertedThreshold();
|
|
66
|
-
_.#isDisabled = _.#promoEnded || !_.#productAvailable;
|
|
67
|
-
_.#isActive = _.#currentAmount >= convertedThreshold && !_.#isDisabled;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
disconnectedCallback() {
|
|
71
|
-
const _ = this;
|
|
72
|
-
if (_.#debounceTimer) clearTimeout(_.#debounceTimer);
|
|
73
|
-
if (_.#attachRetryTimer) clearTimeout(_.#attachRetryTimer);
|
|
74
|
-
if (_.#cartPanel) _.#cartPanel.removeEventListener('cart-panel:data-changed', _.#handlers.cartDataChange);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
attributeChangedCallback(name, oldValue, newValue) {
|
|
78
|
-
const _ = this;
|
|
79
|
-
if (oldValue === newValue) return;
|
|
80
|
-
|
|
81
|
-
switch (name) {
|
|
82
|
-
case 'threshold':
|
|
83
|
-
_.#threshold = parseFloat(newValue) || 0;
|
|
84
|
-
break;
|
|
85
|
-
case 'current':
|
|
86
|
-
_.#currentAmount = parseFloat(newValue) || 0;
|
|
87
|
-
break;
|
|
88
|
-
case 'variant-id':
|
|
89
|
-
_.#variantId = newValue;
|
|
90
|
-
break;
|
|
91
|
-
case 'promo-ended':
|
|
92
|
-
_.#promoEnded = newValue !== null;
|
|
93
|
-
break;
|
|
94
|
-
case 'product-available':
|
|
95
|
-
_.#productAvailable = _.#parseBooleanValue(newValue, true);
|
|
96
|
-
break;
|
|
97
|
-
case 'message-above':
|
|
98
|
-
_.#messageAbove = newValue;
|
|
99
|
-
break;
|
|
100
|
-
case 'message-below':
|
|
101
|
-
_.#messageBelow = newValue;
|
|
102
|
-
break;
|
|
103
|
-
case 'money-format':
|
|
104
|
-
_.#moneyFormat = newValue;
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Recalculate state and update UI if component is connected
|
|
109
|
-
if (_.isConnected) {
|
|
110
|
-
_.#calculateInitialState();
|
|
111
|
-
_.#updateVisualState();
|
|
112
|
-
_.#updateMessages();
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
#render() {
|
|
117
|
-
this.classList.add('gift-with-purchase');
|
|
118
|
-
this.#renderMessages();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
#renderMessages() {
|
|
122
|
-
// Look for existing message element with data-content-gwp-message
|
|
123
|
-
this.#updateMessages();
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
#formatMoney(amount) {
|
|
127
|
-
if (!this.#moneyFormat) return amount.toFixed(2).replace(/\.00$/, '');
|
|
128
|
-
|
|
129
|
-
const amountFixed = amount.toFixed(2);
|
|
130
|
-
const amountNoDecimals = Math.round(amount).toString();
|
|
131
|
-
const amountWithComma = amountFixed.replace('.', ',');
|
|
132
|
-
const amountNoDecimalsWithComma = amountNoDecimals.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
133
|
-
|
|
134
|
-
return this.#moneyFormat
|
|
135
|
-
.replace(/\{\{\s*amount_no_decimals_with_comma_separator\s*\}\}/g, amountNoDecimalsWithComma)
|
|
136
|
-
.replace(/\{\{\s*amount_with_comma_separator\s*\}\}/g, amountWithComma)
|
|
137
|
-
.replace(/\{\{\s*amount_no_decimals\s*\}\}/g, amountNoDecimals)
|
|
138
|
-
.replace(/\{\{\s*amount\s*\}\}/g, amountFixed);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
#getConvertedThreshold() {
|
|
142
|
-
// Convert threshold using Shopify currency rate if available (for multi-currency stores)
|
|
143
|
-
const rate = parseFloat(window.Shopify?.currency?.rate) || 1;
|
|
144
|
-
return this.#threshold * rate;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
#parseBooleanValue(value, defaultValue = true) {
|
|
148
|
-
if (value === null || typeof value === 'undefined') return defaultValue;
|
|
149
|
-
if (value === '') return true;
|
|
150
|
-
const normalized = String(value).trim().toLowerCase();
|
|
151
|
-
if (normalized === 'false' || normalized === '0') return false;
|
|
152
|
-
if (normalized === 'true' || normalized === '1') return true;
|
|
153
|
-
return defaultValue;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
#updateMessages() {
|
|
157
|
-
const _ = this;
|
|
158
|
-
const messageEl = _.querySelector('[data-content-gwp-message]');
|
|
159
|
-
if (!messageEl) return;
|
|
160
|
-
|
|
161
|
-
let message = '';
|
|
162
|
-
if (_.#isActive && _.#messageAbove) {
|
|
163
|
-
message = _.#messageAbove;
|
|
164
|
-
} else if (!_.#isActive && _.#messageBelow) {
|
|
165
|
-
const remaining = _.#getConvertedThreshold() - _.#currentAmount;
|
|
166
|
-
const formattedAmount = _.#formatMoney(remaining);
|
|
167
|
-
message = _.#messageBelow
|
|
168
|
-
.replace(/\[\s*amount\s*\]/g, formattedAmount)
|
|
169
|
-
.replace(/\[amount\]/g, formattedAmount);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
messageEl.textContent = message;
|
|
173
|
-
messageEl.style.display = message ? 'block' : 'none';
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
#attachListeners() {
|
|
177
|
-
const _ = this;
|
|
178
|
-
_.#cartPanel = _.closest('cart-panel');
|
|
179
|
-
|
|
180
|
-
if (_.#cartPanel) {
|
|
181
|
-
_.#cartPanel.addEventListener('cart-panel:data-changed', _.#handlers.cartDataChange);
|
|
182
|
-
} else {
|
|
183
|
-
_.#attachRetryTimer = setTimeout(() => {
|
|
184
|
-
_.#attachRetryTimer = null;
|
|
185
|
-
_.#cartPanel = _.closest('cart-panel');
|
|
186
|
-
if (_.#cartPanel) _.#cartPanel.addEventListener('cart-panel:data-changed', _.#handlers.cartDataChange);
|
|
187
|
-
else console.error('GWP - cart-panel still not found after delay');
|
|
188
|
-
}, 100);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
#handleCartDataChange(event) {
|
|
193
|
-
const _ = this;
|
|
194
|
-
const cart = event.detail;
|
|
195
|
-
if (!cart || typeof cart.calculated_subtotal === 'undefined') return;
|
|
196
|
-
if (_.#debounceTimer) clearTimeout(_.#debounceTimer);
|
|
197
|
-
|
|
198
|
-
_.#debounceTimer = setTimeout(() => {
|
|
199
|
-
_.#debounceTimer = null;
|
|
200
|
-
_.#currentAmount = parseFloat(cart.calculated_subtotal / 100) || 0;
|
|
201
|
-
_.#checkGiftInCart(cart);
|
|
202
|
-
_.#updateState(cart);
|
|
203
|
-
}, 300);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
#checkGiftInCart(cart) {
|
|
207
|
-
const _ = this;
|
|
208
|
-
const giftLines = _.#getGiftLines(cart, true);
|
|
209
|
-
_.#isAdded = giftLines.length > 0;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
#getGiftLines(cart, matchVariantId = true) {
|
|
213
|
-
const _ = this;
|
|
214
|
-
if (!cart?.items) return [];
|
|
215
|
-
return cart.items.filter((item) => {
|
|
216
|
-
if (item.properties?._gwp_item !== 'true') return false;
|
|
217
|
-
if (!matchVariantId) return true;
|
|
218
|
-
if (!_.#variantId) return false;
|
|
219
|
-
return item.variant_id?.toString() === _.#variantId.toString();
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
#recheckIfPending() {
|
|
224
|
-
const _ = this;
|
|
225
|
-
if (_.#pendingCart) {
|
|
226
|
-
const cart = _.#pendingCart;
|
|
227
|
-
_.#pendingCart = null;
|
|
228
|
-
_.#checkGiftInCart(cart);
|
|
229
|
-
_.#updateState(cart);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
#updateState(cart) {
|
|
234
|
-
const _ = this;
|
|
235
|
-
|
|
236
|
-
// If mutation in progress, queue this cart for recheck later
|
|
237
|
-
if (_.#isMutating) {
|
|
238
|
-
_.#pendingCart = cart;
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const wasActive = _.#isActive;
|
|
243
|
-
const convertedThreshold = _.#getConvertedThreshold();
|
|
244
|
-
_.#isDisabled = _.#promoEnded || !_.#productAvailable;
|
|
245
|
-
_.#isActive = _.#currentAmount >= convertedThreshold && !_.#isDisabled;
|
|
246
|
-
|
|
247
|
-
if (_.#isDisabled) _.#removeAllGiftsFromCart(cart);
|
|
248
|
-
else if (_.#isActive && !wasActive && !_.#isAdded && _.#variantId) _.#addGiftToCart();
|
|
249
|
-
else if (!_.#isActive && _.#isAdded && _.#variantId) _.#removeGiftFromCart(cart);
|
|
250
|
-
|
|
251
|
-
_.#updateVisualState();
|
|
252
|
-
_.#updateMessages();
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
#updateVisualState() {
|
|
256
|
-
const _ = this;
|
|
257
|
-
if (_.#promoEnded) {
|
|
258
|
-
_.setAttribute('state', 'ended');
|
|
259
|
-
_.style.display = 'none';
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (!_.#productAvailable) {
|
|
264
|
-
_.setAttribute('state', 'disabled');
|
|
265
|
-
_.style.display = 'none';
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
_.style.display = '';
|
|
270
|
-
if (_.#isAdded) _.setAttribute('state', 'added');
|
|
271
|
-
else if (_.#isActive) _.setAttribute('state', 'active');
|
|
272
|
-
else _.setAttribute('state', 'inactive');
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
async #addGiftToCart() {
|
|
276
|
-
const _ = this;
|
|
277
|
-
_.#isMutating = true;
|
|
278
|
-
try {
|
|
279
|
-
const res = await fetch('/cart/add.js', {
|
|
280
|
-
method: 'POST',
|
|
281
|
-
credentials: 'same-origin',
|
|
282
|
-
headers: { 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest' },
|
|
283
|
-
body: JSON.stringify({
|
|
284
|
-
items: [{ id: _.#variantId, quantity: 1, properties: { _gwp_item: 'true', _hide_in_cart: 'true', _ignore_price_in_subtotal: 'true' } }],
|
|
285
|
-
}),
|
|
286
|
-
});
|
|
287
|
-
if (!res.ok) throw new Error(`http ${res.status}`);
|
|
288
|
-
await res.json();
|
|
289
|
-
_.#isAdded = true;
|
|
290
|
-
_.dispatchEvent(new CustomEvent('gwp:added', { detail: { variantId: _.#variantId }, bubbles: true }));
|
|
291
|
-
_.#cartPanel?.getCartAndRefresh();
|
|
292
|
-
} catch (err) {
|
|
293
|
-
console.error('giftwithpurchase: add error', err);
|
|
294
|
-
_.dispatchEvent(new CustomEvent('gwp:error', { detail: { action: 'add', error: err.message }, bubbles: true }));
|
|
295
|
-
} finally {
|
|
296
|
-
_.#isMutating = false;
|
|
297
|
-
_.#recheckIfPending();
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
async #removeGiftFromCart(cart) {
|
|
302
|
-
const _ = this;
|
|
303
|
-
if (!cart?.items) return;
|
|
304
|
-
|
|
305
|
-
const giftLines = _.#getGiftLines(cart, true);
|
|
306
|
-
if (!giftLines.length) {
|
|
307
|
-
_.#isAdded = false;
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
_.#isMutating = true;
|
|
312
|
-
try {
|
|
313
|
-
await _.#removeAllGiftItems(giftLines);
|
|
314
|
-
} finally {
|
|
315
|
-
_.#isMutating = false;
|
|
316
|
-
_.#recheckIfPending();
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
async #removeAllGiftsFromCart(cart) {
|
|
321
|
-
const _ = this;
|
|
322
|
-
if (!cart?.items) return;
|
|
323
|
-
|
|
324
|
-
const giftLines = _.#getGiftLines(cart, false);
|
|
325
|
-
if (!giftLines.length) {
|
|
326
|
-
_.#isAdded = false;
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
_.#isMutating = true;
|
|
331
|
-
try {
|
|
332
|
-
await _.#removeAllGiftItems(giftLines);
|
|
333
|
-
} finally {
|
|
334
|
-
_.#isMutating = false;
|
|
335
|
-
_.#recheckIfPending();
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
async #removeAllGiftItems(giftLines) {
|
|
340
|
-
const _ = this;
|
|
341
|
-
try {
|
|
342
|
-
await Promise.all(
|
|
343
|
-
giftLines.map(async (item) => {
|
|
344
|
-
const res = await fetch('/cart/change.js', {
|
|
345
|
-
method: 'POST',
|
|
346
|
-
credentials: 'same-origin',
|
|
347
|
-
headers: { 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest' },
|
|
348
|
-
body: JSON.stringify({ id: item.key, quantity: 0 }),
|
|
349
|
-
});
|
|
350
|
-
if (!res.ok) throw new Error(`http ${res.status}`);
|
|
351
|
-
})
|
|
352
|
-
);
|
|
353
|
-
_.#isAdded = false;
|
|
354
|
-
_.dispatchEvent(new CustomEvent('gwp:removed', { detail: { variantId: _.#variantId }, bubbles: true }));
|
|
355
|
-
_.#cartPanel?.getCartAndRefresh();
|
|
356
|
-
} catch (err) {
|
|
357
|
-
console.error('giftwithpurchase: bulk remove error', err);
|
|
358
|
-
_.dispatchEvent(new CustomEvent('gwp:error', { detail: { action: 'remove', error: err.message }, bubbles: true }));
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
getState() {
|
|
363
|
-
const _ = this;
|
|
364
|
-
const convertedThreshold = _.#getConvertedThreshold();
|
|
365
|
-
return {
|
|
366
|
-
currentAmount: _.#currentAmount,
|
|
367
|
-
threshold: _.#threshold,
|
|
368
|
-
convertedThreshold,
|
|
369
|
-
variantId: _.#variantId,
|
|
370
|
-
isActive: _.#isActive,
|
|
371
|
-
isAdded: _.#isAdded,
|
|
372
|
-
promoEnded: _.#promoEnded,
|
|
373
|
-
productAvailable: _.#productAvailable,
|
|
374
|
-
isDisabled: _.#isDisabled,
|
|
375
|
-
remainingAmount: Math.max(0, convertedThreshold - _.#currentAmount),
|
|
376
|
-
currencyRate: parseFloat(window.Shopify?.currency?.rate) || 1,
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
get currentAmount() {
|
|
381
|
-
return this.#currentAmount;
|
|
382
|
-
}
|
|
383
|
-
get threshold() {
|
|
384
|
-
return this.#threshold;
|
|
385
|
-
}
|
|
386
|
-
get variantId() {
|
|
387
|
-
return this.#variantId;
|
|
388
|
-
}
|
|
389
|
-
get isActive() {
|
|
390
|
-
return this.#isActive;
|
|
391
|
-
}
|
|
392
|
-
get isAdded() {
|
|
393
|
-
return this.#isAdded;
|
|
394
|
-
}
|
|
395
|
-
get promoEnded() {
|
|
396
|
-
return this.#promoEnded;
|
|
397
|
-
}
|
|
398
|
-
get productAvailable() {
|
|
399
|
-
return this.#productAvailable;
|
|
400
|
-
}
|
|
401
|
-
get isDisabled() {
|
|
402
|
-
return this.#isDisabled;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
setCurrentAmount(amount) {
|
|
406
|
-
const _ = this;
|
|
407
|
-
_.#currentAmount = parseFloat(amount) || 0;
|
|
408
|
-
_.#updateState({ items: [] });
|
|
409
|
-
_.#updateMessages();
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
setThreshold(threshold) {
|
|
413
|
-
const _ = this;
|
|
414
|
-
_.#threshold = parseFloat(threshold) || 0;
|
|
415
|
-
_.#updateState({ items: [] });
|
|
416
|
-
_.#updateMessages();
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
setVariantId(variantId) {
|
|
420
|
-
this.#variantId = variantId;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
if (!customElements.get('gift-with-purchase')) {
|
|
425
|
-
customElements.define('gift-with-purchase', GiftWithPurchase);
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
exports.GiftWithPurchase = GiftWithPurchase;
|
|
429
|
-
//# sourceMappingURL=gift-with-purchase.cjs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gift-with-purchase.cjs.js","sources":["../src/gift-with-purchase.js"],"sourcesContent":["import './gift-with-purchase.scss';\n\n/**\n * Gift With Purchase Component - automatically adds/removes gift when cart threshold is met\n * Emits gwp:added/gwp:removed/gwp:error events and broadcasts cart updates\n */\nclass GiftWithPurchase extends HTMLElement {\n\t#threshold = 0;\n\t#currentAmount = 0;\n\t#variantId = null;\n\t#isActive = false;\n\t#isAdded = false;\n\t#promoEnded = false;\n\t#productAvailable = true;\n\t#isDisabled = false;\n\t#cartPanel = null;\n\t#handlers = {};\n\t#debounceTimer = null;\n\t#attachRetryTimer = null;\n\t#isMutating = false; // prevents overlapping cart mutations\n\t#pendingCart = null; // stores cart snapshot during mutation for recheck\n\t#messageAbove = null;\n\t#messageBelow = null;\n\t#moneyFormat = null;\n\n\tstatic get observedAttributes() {\n\t\treturn [\n\t\t\t'threshold',\n\t\t\t'current',\n\t\t\t'variant-id',\n\t\t\t'promo-ended',\n\t\t\t'product-available',\n\t\t\t'message-above',\n\t\t\t'message-below',\n\t\t\t'money-format',\n\t\t];\n\t}\n\n\tconstructor() {\n\t\tsuper();\n\t\tconst _ = this;\n\t\t_.#threshold = parseFloat(_.getAttribute('threshold')) || 0;\n\t\t_.#currentAmount = parseFloat(_.getAttribute('current')) || 0;\n\t\t_.#variantId = _.getAttribute('variant-id');\n\t\t_.#promoEnded = _.hasAttribute('promo-ended');\n\t\t_.#productAvailable = _.#parseBooleanValue(_.getAttribute('product-available'), true);\n\t\t_.#messageAbove = _.getAttribute('message-above');\n\t\t_.#messageBelow = _.getAttribute('message-below');\n\t\t_.#moneyFormat = _.getAttribute('money-format');\n\t\t_.#handlers = { cartDataChange: _.#handleCartDataChange.bind(_) };\n\t}\n\n\tconnectedCallback() {\n\t\tconst _ = this;\n\n\t\t_.#calculateInitialState();\n\t\t_.#render();\n\t\t_.#updateVisualState();\n\t\t_.#attachListeners();\n\t}\n\n\t#calculateInitialState() {\n\t\tconst _ = this;\n\t\t// Calculate initial active state based on attributes (before any cart events)\n\t\tconst convertedThreshold = _.#getConvertedThreshold();\n\t\t_.#isDisabled = _.#promoEnded || !_.#productAvailable;\n\t\t_.#isActive = _.#currentAmount >= convertedThreshold && !_.#isDisabled;\n\t}\n\n\tdisconnectedCallback() {\n\t\tconst _ = this;\n\t\tif (_.#debounceTimer) clearTimeout(_.#debounceTimer);\n\t\tif (_.#attachRetryTimer) clearTimeout(_.#attachRetryTimer);\n\t\tif (_.#cartPanel) _.#cartPanel.removeEventListener('cart-panel:data-changed', _.#handlers.cartDataChange);\n\t}\n\n\tattributeChangedCallback(name, oldValue, newValue) {\n\t\tconst _ = this;\n\t\tif (oldValue === newValue) return;\n\n\t\tswitch (name) {\n\t\t\tcase 'threshold':\n\t\t\t\t_.#threshold = parseFloat(newValue) || 0;\n\t\t\t\tbreak;\n\t\t\tcase 'current':\n\t\t\t\t_.#currentAmount = parseFloat(newValue) || 0;\n\t\t\t\tbreak;\n\t\t\tcase 'variant-id':\n\t\t\t\t_.#variantId = newValue;\n\t\t\t\tbreak;\n\t\t\tcase 'promo-ended':\n\t\t\t\t_.#promoEnded = newValue !== null;\n\t\t\t\tbreak;\n\t\t\tcase 'product-available':\n\t\t\t\t_.#productAvailable = _.#parseBooleanValue(newValue, true);\n\t\t\t\tbreak;\n\t\t\tcase 'message-above':\n\t\t\t\t_.#messageAbove = newValue;\n\t\t\t\tbreak;\n\t\t\tcase 'message-below':\n\t\t\t\t_.#messageBelow = newValue;\n\t\t\t\tbreak;\n\t\t\tcase 'money-format':\n\t\t\t\t_.#moneyFormat = newValue;\n\t\t\t\tbreak;\n\t\t}\n\n\t\t// Recalculate state and update UI if component is connected\n\t\tif (_.isConnected) {\n\t\t\t_.#calculateInitialState();\n\t\t\t_.#updateVisualState();\n\t\t\t_.#updateMessages();\n\t\t}\n\t}\n\n\t#render() {\n\t\tthis.classList.add('gift-with-purchase');\n\t\tthis.#renderMessages();\n\t}\n\n\t#renderMessages() {\n\t\t// Look for existing message element with data-content-gwp-message\n\t\tthis.#updateMessages();\n\t}\n\n\t#formatMoney(amount) {\n\t\tif (!this.#moneyFormat) return amount.toFixed(2).replace(/\\.00$/, '');\n\n\t\tconst amountFixed = amount.toFixed(2);\n\t\tconst amountNoDecimals = Math.round(amount).toString();\n\t\tconst amountWithComma = amountFixed.replace('.', ',');\n\t\tconst amountNoDecimalsWithComma = amountNoDecimals.replace(/\\B(?=(\\d{3})+(?!\\d))/g, ',');\n\n\t\treturn this.#moneyFormat\n\t\t\t.replace(/\\{\\{\\s*amount_no_decimals_with_comma_separator\\s*\\}\\}/g, amountNoDecimalsWithComma)\n\t\t\t.replace(/\\{\\{\\s*amount_with_comma_separator\\s*\\}\\}/g, amountWithComma)\n\t\t\t.replace(/\\{\\{\\s*amount_no_decimals\\s*\\}\\}/g, amountNoDecimals)\n\t\t\t.replace(/\\{\\{\\s*amount\\s*\\}\\}/g, amountFixed);\n\t}\n\n\t#getConvertedThreshold() {\n\t\t// Convert threshold using Shopify currency rate if available (for multi-currency stores)\n\t\tconst rate = parseFloat(window.Shopify?.currency?.rate) || 1;\n\t\treturn this.#threshold * rate;\n\t}\n\n\t#parseBooleanValue(value, defaultValue = true) {\n\t\tif (value === null || typeof value === 'undefined') return defaultValue;\n\t\tif (value === '') return true;\n\t\tconst normalized = String(value).trim().toLowerCase();\n\t\tif (normalized === 'false' || normalized === '0') return false;\n\t\tif (normalized === 'true' || normalized === '1') return true;\n\t\treturn defaultValue;\n\t}\n\n\t#updateMessages() {\n\t\tconst _ = this;\n\t\tconst messageEl = _.querySelector('[data-content-gwp-message]');\n\t\tif (!messageEl) return;\n\n\t\tlet message = '';\n\t\tif (_.#isActive && _.#messageAbove) {\n\t\t\tmessage = _.#messageAbove;\n\t\t} else if (!_.#isActive && _.#messageBelow) {\n\t\t\tconst remaining = _.#getConvertedThreshold() - _.#currentAmount;\n\t\t\tconst formattedAmount = _.#formatMoney(remaining);\n\t\t\tmessage = _.#messageBelow\n\t\t\t\t.replace(/\\[\\s*amount\\s*\\]/g, formattedAmount)\n\t\t\t\t.replace(/\\[amount\\]/g, formattedAmount);\n\t\t}\n\n\t\tmessageEl.textContent = message;\n\t\tmessageEl.style.display = message ? 'block' : 'none';\n\t}\n\n\t#attachListeners() {\n\t\tconst _ = this;\n\t\t_.#cartPanel = _.closest('cart-panel');\n\n\t\tif (_.#cartPanel) {\n\t\t\t_.#cartPanel.addEventListener('cart-panel:data-changed', _.#handlers.cartDataChange);\n\t\t} else {\n\t\t\t_.#attachRetryTimer = setTimeout(() => {\n\t\t\t\t_.#attachRetryTimer = null;\n\t\t\t\t_.#cartPanel = _.closest('cart-panel');\n\t\t\t\tif (_.#cartPanel) _.#cartPanel.addEventListener('cart-panel:data-changed', _.#handlers.cartDataChange);\n\t\t\t\telse console.error('GWP - cart-panel still not found after delay');\n\t\t\t}, 100);\n\t\t}\n\t}\n\n\t#handleCartDataChange(event) {\n\t\tconst _ = this;\n\t\tconst cart = event.detail;\n\t\tif (!cart || typeof cart.calculated_subtotal === 'undefined') return;\n\t\tif (_.#debounceTimer) clearTimeout(_.#debounceTimer);\n\n\t\t_.#debounceTimer = setTimeout(() => {\n\t\t\t_.#debounceTimer = null;\n\t\t\t_.#currentAmount = parseFloat(cart.calculated_subtotal / 100) || 0;\n\t\t\t_.#checkGiftInCart(cart);\n\t\t\t_.#updateState(cart);\n\t\t}, 300);\n\t}\n\n\t#checkGiftInCart(cart) {\n\t\tconst _ = this;\n\t\tconst giftLines = _.#getGiftLines(cart, true);\n\t\t_.#isAdded = giftLines.length > 0;\n\t}\n\n\t#getGiftLines(cart, matchVariantId = true) {\n\t\tconst _ = this;\n\t\tif (!cart?.items) return [];\n\t\treturn cart.items.filter((item) => {\n\t\t\tif (item.properties?._gwp_item !== 'true') return false;\n\t\t\tif (!matchVariantId) return true;\n\t\t\tif (!_.#variantId) return false;\n\t\t\treturn item.variant_id?.toString() === _.#variantId.toString();\n\t\t});\n\t}\n\n\t#recheckIfPending() {\n\t\tconst _ = this;\n\t\tif (_.#pendingCart) {\n\t\t\tconst cart = _.#pendingCart;\n\t\t\t_.#pendingCart = null;\n\t\t\t_.#checkGiftInCart(cart);\n\t\t\t_.#updateState(cart);\n\t\t}\n\t}\n\n\t#updateState(cart) {\n\t\tconst _ = this;\n\n\t\t// If mutation in progress, queue this cart for recheck later\n\t\tif (_.#isMutating) {\n\t\t\t_.#pendingCart = cart;\n\t\t\treturn;\n\t\t}\n\n\t\tconst wasActive = _.#isActive;\n\t\tconst convertedThreshold = _.#getConvertedThreshold();\n\t\t_.#isDisabled = _.#promoEnded || !_.#productAvailable;\n\t\t_.#isActive = _.#currentAmount >= convertedThreshold && !_.#isDisabled;\n\n\t\tif (_.#isDisabled) _.#removeAllGiftsFromCart(cart);\n\t\telse if (_.#isActive && !wasActive && !_.#isAdded && _.#variantId) _.#addGiftToCart();\n\t\telse if (!_.#isActive && _.#isAdded && _.#variantId) _.#removeGiftFromCart(cart);\n\n\t\t_.#updateVisualState();\n\t\t_.#updateMessages();\n\t}\n\n\t#updateVisualState() {\n\t\tconst _ = this;\n\t\tif (_.#promoEnded) {\n\t\t\t_.setAttribute('state', 'ended');\n\t\t\t_.style.display = 'none';\n\t\t\treturn;\n\t\t}\n\n\t\tif (!_.#productAvailable) {\n\t\t\t_.setAttribute('state', 'disabled');\n\t\t\t_.style.display = 'none';\n\t\t\treturn;\n\t\t}\n\n\t\t_.style.display = '';\n\t\tif (_.#isAdded) _.setAttribute('state', 'added');\n\t\telse if (_.#isActive) _.setAttribute('state', 'active');\n\t\telse _.setAttribute('state', 'inactive');\n\t}\n\n\tasync #addGiftToCart() {\n\t\tconst _ = this;\n\t\t_.#isMutating = true;\n\t\ttry {\n\t\t\tconst res = await fetch('/cart/add.js', {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tcredentials: 'same-origin',\n\t\t\t\theaders: { 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest' },\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\titems: [{ id: _.#variantId, quantity: 1, properties: { _gwp_item: 'true', _hide_in_cart: 'true', _ignore_price_in_subtotal: 'true' } }],\n\t\t\t\t}),\n\t\t\t});\n\t\t\tif (!res.ok) throw new Error(`http ${res.status}`);\n\t\t\tawait res.json();\n\t\t\t_.#isAdded = true;\n\t\t\t_.dispatchEvent(new CustomEvent('gwp:added', { detail: { variantId: _.#variantId }, bubbles: true }));\n\t\t\t_.#cartPanel?.getCartAndRefresh();\n\t\t} catch (err) {\n\t\t\tconsole.error('giftwithpurchase: add error', err);\n\t\t\t_.dispatchEvent(new CustomEvent('gwp:error', { detail: { action: 'add', error: err.message }, bubbles: true }));\n\t\t} finally {\n\t\t\t_.#isMutating = false;\n\t\t\t_.#recheckIfPending();\n\t\t}\n\t}\n\n\tasync #removeGiftFromCart(cart) {\n\t\tconst _ = this;\n\t\tif (!cart?.items) return;\n\n\t\tconst giftLines = _.#getGiftLines(cart, true);\n\t\tif (!giftLines.length) {\n\t\t\t_.#isAdded = false;\n\t\t\treturn;\n\t\t}\n\n\t\t_.#isMutating = true;\n\t\ttry {\n\t\t\tawait _.#removeAllGiftItems(giftLines);\n\t\t} finally {\n\t\t\t_.#isMutating = false;\n\t\t\t_.#recheckIfPending();\n\t\t}\n\t}\n\n\tasync #removeAllGiftsFromCart(cart) {\n\t\tconst _ = this;\n\t\tif (!cart?.items) return;\n\n\t\tconst giftLines = _.#getGiftLines(cart, false);\n\t\tif (!giftLines.length) {\n\t\t\t_.#isAdded = false;\n\t\t\treturn;\n\t\t}\n\n\t\t_.#isMutating = true;\n\t\ttry {\n\t\t\tawait _.#removeAllGiftItems(giftLines);\n\t\t} finally {\n\t\t\t_.#isMutating = false;\n\t\t\t_.#recheckIfPending();\n\t\t}\n\t}\n\n\tasync #removeAllGiftItems(giftLines) {\n\t\tconst _ = this;\n\t\ttry {\n\t\t\tawait Promise.all(\n\t\t\t\tgiftLines.map(async (item) => {\n\t\t\t\t\tconst res = await fetch('/cart/change.js', {\n\t\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\t\tcredentials: 'same-origin',\n\t\t\t\t\t\theaders: { 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest' },\n\t\t\t\t\t\tbody: JSON.stringify({ id: item.key, quantity: 0 }),\n\t\t\t\t\t});\n\t\t\t\t\tif (!res.ok) throw new Error(`http ${res.status}`);\n\t\t\t\t})\n\t\t\t);\n\t\t\t_.#isAdded = false;\n\t\t\t_.dispatchEvent(new CustomEvent('gwp:removed', { detail: { variantId: _.#variantId }, bubbles: true }));\n\t\t\t_.#cartPanel?.getCartAndRefresh();\n\t\t} catch (err) {\n\t\t\tconsole.error('giftwithpurchase: bulk remove error', err);\n\t\t\t_.dispatchEvent(new CustomEvent('gwp:error', { detail: { action: 'remove', error: err.message }, bubbles: true }));\n\t\t}\n\t}\n\n\tgetState() {\n\t\tconst _ = this;\n\t\tconst convertedThreshold = _.#getConvertedThreshold();\n\t\treturn {\n\t\t\tcurrentAmount: _.#currentAmount,\n\t\t\tthreshold: _.#threshold,\n\t\t\tconvertedThreshold,\n\t\t\tvariantId: _.#variantId,\n\t\t\tisActive: _.#isActive,\n\t\t\tisAdded: _.#isAdded,\n\t\t\tpromoEnded: _.#promoEnded,\n\t\t\tproductAvailable: _.#productAvailable,\n\t\t\tisDisabled: _.#isDisabled,\n\t\t\tremainingAmount: Math.max(0, convertedThreshold - _.#currentAmount),\n\t\t\tcurrencyRate: parseFloat(window.Shopify?.currency?.rate) || 1,\n\t\t};\n\t}\n\n\tget currentAmount() {\n\t\treturn this.#currentAmount;\n\t}\n\tget threshold() {\n\t\treturn this.#threshold;\n\t}\n\tget variantId() {\n\t\treturn this.#variantId;\n\t}\n\tget isActive() {\n\t\treturn this.#isActive;\n\t}\n\tget isAdded() {\n\t\treturn this.#isAdded;\n\t}\n\tget promoEnded() {\n\t\treturn this.#promoEnded;\n\t}\n\tget productAvailable() {\n\t\treturn this.#productAvailable;\n\t}\n\tget isDisabled() {\n\t\treturn this.#isDisabled;\n\t}\n\n\tsetCurrentAmount(amount) {\n\t\tconst _ = this;\n\t\t_.#currentAmount = parseFloat(amount) || 0;\n\t\t_.#updateState({ items: [] });\n\t\t_.#updateMessages();\n\t}\n\n\tsetThreshold(threshold) {\n\t\tconst _ = this;\n\t\t_.#threshold = parseFloat(threshold) || 0;\n\t\t_.#updateState({ items: [] });\n\t\t_.#updateMessages();\n\t}\n\n\tsetVariantId(variantId) {\n\t\tthis.#variantId = variantId;\n\t}\n}\n\nif (!customElements.get('gift-with-purchase')) {\n\tcustomElements.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B,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;AACjB,EAAE,CAAC,CAAC,UAAU,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC5C,EAAE,CAAC,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;AAChC,EAAE,CAAC,CAAC,eAAe,EAAE,CAAC;AACtB,EAAE;AACF;AACA,CAAC,YAAY,CAAC,SAAS,EAAE;AACzB,EAAE,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;AAC9B,EAAE;AACF,CAAC;AACD;AACA,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE;AAC/C,CAAC,cAAc,CAAC,MAAM,CAAC,oBAAoB,EAAE,gBAAgB,CAAC,CAAC;AAC/D;;;;"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
gift-with-purchase {
|
|
2
|
-
--gwp-border-radius: 8px;
|
|
3
|
-
--gwp-padding: 1rem;
|
|
4
|
-
--gwp-gap: 1rem;
|
|
5
|
-
--gwp-bg-active: #e8f5e8;
|
|
6
|
-
--gwp-bg-added: #d4edda;
|
|
7
|
-
--gwp-border-active: #28a745;
|
|
8
|
-
--gwp-border-added: #155724;
|
|
9
|
-
--gwp-text-active: #155724;
|
|
10
|
-
--gwp-text-added: #155724;
|
|
11
|
-
display: block;
|
|
12
|
-
border: 2px solid var(--gwp-border-active);
|
|
13
|
-
border-radius: var(--gwp-border-radius);
|
|
14
|
-
padding: var(--gwp-padding);
|
|
15
|
-
background-color: var(--gwp-bg-active);
|
|
16
|
-
color: var(--gwp-text-active);
|
|
17
|
-
}
|
|
18
|
-
gift-with-purchase .gwp-product {
|
|
19
|
-
display: flex;
|
|
20
|
-
align-items: flex-start;
|
|
21
|
-
gap: var(--gwp-gap);
|
|
22
|
-
}
|
|
23
|
-
gift-with-purchase [data-gwp-image] {
|
|
24
|
-
flex-shrink: 0;
|
|
25
|
-
}
|
|
26
|
-
gift-with-purchase .gwp-content {
|
|
27
|
-
flex: 1;
|
|
28
|
-
min-width: 0;
|
|
29
|
-
}
|
|
30
|
-
gift-with-purchase[state=active] {
|
|
31
|
-
background-color: var(--gwp-bg-active);
|
|
32
|
-
border-color: var(--gwp-border-active);
|
|
33
|
-
color: var(--gwp-text-active);
|
|
34
|
-
}
|
|
35
|
-
gift-with-purchase[state=added] {
|
|
36
|
-
background-color: var(--gwp-bg-added);
|
|
37
|
-
border-color: var(--gwp-border-added);
|
|
38
|
-
color: var(--gwp-text-added);
|
|
39
|
-
}
|
|
40
|
-
gift-with-purchase[state=ended] {
|
|
41
|
-
display: none;
|
|
42
|
-
}
|
|
43
|
-
gift-with-purchase[state=disabled] {
|
|
44
|
-
display: none;
|
|
45
|
-
}
|
|
46
|
-
/*# sourceMappingURL=gift-with-purchase.esm.css.map */
|