@magic-spells/gift-with-purchase 0.2.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 +177 -40
- package/dist/{gift-with-purchase.cjs.css → gift-with-purchase.css} +12 -6
- package/dist/gift-with-purchase.esm.js +353 -242
- package/dist/gift-with-purchase.min.css +2 -2
- package/dist/gift-with-purchase.min.js +1 -2
- package/package.json +19 -26
- package/dist/gift-with-purchase.cjs.css.map +0 -1
- package/dist/gift-with-purchase.cjs.js +0 -339
- package/dist/gift-with-purchase.cjs.js.map +0 -1
- package/dist/gift-with-purchase.esm.css +0 -43
- 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 -70
- package/src/gift-with-purchase.js +0 -338
- package/src/gift-with-purchase.scss +0 -70
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
gift-with-purchase{--gwp-border-radius:8px;--gwp-padding:1rem;--gwp-gap:1rem;--gwp-bg-active:#e8f5e8;--gwp-bg-added:#d4edda;--gwp-border-active:#28a745;--gwp-border-added:#155724;--gwp-text-active:#155724;--gwp-text-added:#155724;
|
|
2
|
-
|
|
1
|
+
gift-with-purchase{--gwp-border-radius:8px;--gwp-padding:1rem;--gwp-gap:1rem;--gwp-bg-active:#e8f5e8;--gwp-bg-added:#d4edda;--gwp-border-active:#28a745;--gwp-border-added:#155724;--gwp-text-active:#155724;--gwp-text-added:#155724;border:2px solid var(--gwp-border-active);border-radius:var(--gwp-border-radius);padding:var(--gwp-padding);background-color:var(--gwp-bg-active);color:var(--gwp-text-active);display:block}gift-with-purchase .gwp-product{align-items:flex-start;gap:var(--gwp-gap);display:flex}gift-with-purchase [data-gwp-image]{flex-shrink:0}gift-with-purchase .gwp-content{flex:1;min-width:0}gift-with-purchase[state=active]{background-color:var(--gwp-bg-active);border-color:var(--gwp-border-active);color:var(--gwp-text-active)}gift-with-purchase[state=added]{background-color:var(--gwp-bg-added);border-color:var(--gwp-border-added);color:var(--gwp-text-added)}gift-with-purchase[state=ended],gift-with-purchase[state=disabled]{display:none}
|
|
2
|
+
/*$vite$:1*/
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
!function(t
|
|
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",
|
|
@@ -60,16 +56,13 @@
|
|
|
60
56
|
"not ie <= 11"
|
|
61
57
|
],
|
|
62
58
|
"devDependencies": {
|
|
63
|
-
"@eslint/js": "^
|
|
64
|
-
"@
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
59
|
+
"@eslint/js": "^9.38.0",
|
|
60
|
+
"@magic-spells/vite-plugin-live-reload": "^0.1.0",
|
|
61
|
+
"eslint": "^9.38.0",
|
|
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","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}"]}
|
|
@@ -1,339 +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
|
-
// private fields
|
|
9
|
-
#threshold = 0;
|
|
10
|
-
#currentAmount = 0;
|
|
11
|
-
#variantId = null;
|
|
12
|
-
#isActive = false;
|
|
13
|
-
#isAdded = false;
|
|
14
|
-
#promoEnded = false;
|
|
15
|
-
#cartDialog = null;
|
|
16
|
-
#boundHandleCartDataChange = null; // pre-bound listener ref for clean-up
|
|
17
|
-
#debounceTimer = null; // debouncing cart updates
|
|
18
|
-
#messageAbove = null; // message when threshold is met
|
|
19
|
-
#messageBelow = null; // message when below threshold
|
|
20
|
-
|
|
21
|
-
static get observedAttributes() {
|
|
22
|
-
return ['threshold', 'current', 'variant-id', 'promo-ended', 'message-above', 'message-below'];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
constructor() {
|
|
26
|
-
super();
|
|
27
|
-
// read initial attributes once
|
|
28
|
-
this.#threshold = parseFloat(this.getAttribute('threshold')) || 0;
|
|
29
|
-
this.#currentAmount = parseFloat(this.getAttribute('current')) || 0;
|
|
30
|
-
this.#variantId = this.getAttribute('variant-id');
|
|
31
|
-
this.#promoEnded = this.hasAttribute('promo-ended');
|
|
32
|
-
this.#messageAbove = this.getAttribute('message-above');
|
|
33
|
-
this.#messageBelow = this.getAttribute('message-below');
|
|
34
|
-
this.#boundHandleCartDataChange = this.#handleCartDataChange.bind(this);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
connectedCallback() {
|
|
38
|
-
this.#render();
|
|
39
|
-
this.#attachListeners();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
disconnectedCallback() {
|
|
43
|
-
if (this.#debounceTimer) clearTimeout(this.#debounceTimer);
|
|
44
|
-
if (this.#cartDialog)
|
|
45
|
-
this.#cartDialog.removeEventListener(
|
|
46
|
-
'cart-dialog:data-changed',
|
|
47
|
-
this.#boundHandleCartDataChange
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
#render() {
|
|
52
|
-
this.classList.add('gift-with-purchase');
|
|
53
|
-
this.#renderMessages();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
#renderMessages() {
|
|
57
|
-
// Look for existing message element with data-content-gwp-message
|
|
58
|
-
this.#updateMessages();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
#updateMessages() {
|
|
62
|
-
const messageEl = this.querySelector('[data-content-gwp-message]');
|
|
63
|
-
if (!messageEl) return;
|
|
64
|
-
|
|
65
|
-
let message = '';
|
|
66
|
-
|
|
67
|
-
// console.log('updateMessages - this.#isActive', this.#isActive);
|
|
68
|
-
|
|
69
|
-
if (this.#isActive && this.#messageAbove) {
|
|
70
|
-
// set message to above threshold message
|
|
71
|
-
message = this.#messageAbove;
|
|
72
|
-
} else if (!this.#isActive && this.#messageBelow) {
|
|
73
|
-
// set message to below threshold message
|
|
74
|
-
const remaining = this.#threshold - this.#currentAmount;
|
|
75
|
-
const formattedAmount = remaining.toFixed(2).replace(/\.00$/, '');
|
|
76
|
-
message = this.#messageBelow
|
|
77
|
-
.replace(/\{\s*amount\s*\}/g, formattedAmount)
|
|
78
|
-
.replace(/\{amount\}/g, formattedAmount);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
messageEl.textContent = message;
|
|
82
|
-
messageEl.style.display = message ? 'block' : 'none';
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
#attachListeners() {
|
|
86
|
-
// Look for cart-dialog element when attaching listeners (more reliable timing)
|
|
87
|
-
this.#cartDialog = this.closest('cart-dialog');
|
|
88
|
-
|
|
89
|
-
if (this.#cartDialog) {
|
|
90
|
-
// console.log('cartDialog exists and is attaching events');
|
|
91
|
-
this.#cartDialog.addEventListener(
|
|
92
|
-
'cart-dialog:data-changed',
|
|
93
|
-
this.#boundHandleCartDataChange
|
|
94
|
-
);
|
|
95
|
-
} else {
|
|
96
|
-
// Try again after a short delay in case the DOM isn't fully ready
|
|
97
|
-
setTimeout(() => {
|
|
98
|
-
// console.log('cartDialog DIDNT exist and we waited to attach events');
|
|
99
|
-
this.#cartDialog = this.closest('cart-dialog');
|
|
100
|
-
if (this.#cartDialog) {
|
|
101
|
-
this.#cartDialog.addEventListener(
|
|
102
|
-
'cart-dialog:data-changed',
|
|
103
|
-
this.#boundHandleCartDataChange
|
|
104
|
-
);
|
|
105
|
-
} else {
|
|
106
|
-
console.error('GWP - cart-dialog still not found after delay');
|
|
107
|
-
}
|
|
108
|
-
}, 100);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
#handleCartDataChange(event) {
|
|
113
|
-
const cart = event.detail;
|
|
114
|
-
// console.log('GWP - handleCartDataChange cart: ', cart.calculated_subtotal, cart);
|
|
115
|
-
|
|
116
|
-
if (!cart || typeof cart.calculated_subtotal === 'undefined') return;
|
|
117
|
-
if (this.#debounceTimer) clearTimeout(this.#debounceTimer);
|
|
118
|
-
|
|
119
|
-
this.#debounceTimer = setTimeout(() => {
|
|
120
|
-
this.#debounceTimer = null;
|
|
121
|
-
this.#currentAmount = parseFloat(cart.calculated_subtotal / 100) || 0;
|
|
122
|
-
this.#checkGiftInCart(cart);
|
|
123
|
-
this.#updateState(cart);
|
|
124
|
-
}, 300);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// checks to see if the gift is already in the cart
|
|
128
|
-
#checkGiftInCart(cart) {
|
|
129
|
-
if (!cart.items || !this.#variantId) {
|
|
130
|
-
this.#isAdded = false;
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
const giftLines = cart.items.filter(
|
|
134
|
-
(lineItem) =>
|
|
135
|
-
lineItem.variant_id.toString() === this.#variantId.toString() &&
|
|
136
|
-
lineItem.properties?._gwp_item === 'true'
|
|
137
|
-
);
|
|
138
|
-
this.#isAdded = giftLines.length > 0;
|
|
139
|
-
if (this.#promoEnded && giftLines.length) this.#removeAllGiftItems(giftLines);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
#updateState(cart) {
|
|
143
|
-
// console.log('********** ---------- Updating state....');
|
|
144
|
-
const wasActive = this.#isActive;
|
|
145
|
-
this.#isActive = this.#currentAmount >= this.#threshold && !this.#promoEnded;
|
|
146
|
-
|
|
147
|
-
// console.log('********** ---------- this.#isActive', this.#isActive);
|
|
148
|
-
|
|
149
|
-
if (this.#promoEnded) {
|
|
150
|
-
// remove GWP from cart
|
|
151
|
-
this.#removeGiftFromCart(cart);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (this.#isActive && !wasActive && !this.#isAdded && this.#variantId) {
|
|
155
|
-
this.#addGiftToCart();
|
|
156
|
-
} else if (!this.#isActive && wasActive && this.#isAdded && this.#variantId) {
|
|
157
|
-
this.#removeGiftFromCart(cart);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
this.#updateVisualState();
|
|
161
|
-
this.#updateMessages();
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
#updateVisualState() {
|
|
165
|
-
if (this.#promoEnded) {
|
|
166
|
-
this.setAttribute('state', 'ended');
|
|
167
|
-
this.style.display = 'none';
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
this.style.display = '';
|
|
172
|
-
if (this.#isAdded) {
|
|
173
|
-
this.setAttribute('state', 'added');
|
|
174
|
-
} else if (this.#isActive) {
|
|
175
|
-
this.setAttribute('state', 'active');
|
|
176
|
-
}
|
|
177
|
-
// Note: no 'inactive' state since component wouldn't be loaded if inactive
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
async #addGiftToCart() {
|
|
181
|
-
try {
|
|
182
|
-
const res = await fetch('/cart/add.js', {
|
|
183
|
-
method: 'POST',
|
|
184
|
-
credentials: 'same-origin',
|
|
185
|
-
headers: {
|
|
186
|
-
'Content-Type': 'application/json',
|
|
187
|
-
'X-Requested-With': 'XMLHttpRequest',
|
|
188
|
-
},
|
|
189
|
-
body: JSON.stringify({
|
|
190
|
-
items: [
|
|
191
|
-
{
|
|
192
|
-
id: this.#variantId,
|
|
193
|
-
quantity: 1,
|
|
194
|
-
properties: {
|
|
195
|
-
_gwp_item: 'true',
|
|
196
|
-
_hide_in_cart: 'true',
|
|
197
|
-
_ignore_price_in_subtotal: 'true',
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
],
|
|
201
|
-
}),
|
|
202
|
-
});
|
|
203
|
-
if (!res.ok) throw new Error(`http ${res.status}`);
|
|
204
|
-
await res.json();
|
|
205
|
-
this.#isAdded = true;
|
|
206
|
-
this.dispatchEvent(
|
|
207
|
-
new CustomEvent('gwp:added', {
|
|
208
|
-
detail: { variantId: this.#variantId },
|
|
209
|
-
bubbles: true,
|
|
210
|
-
})
|
|
211
|
-
);
|
|
212
|
-
} catch (err) {
|
|
213
|
-
console.error('giftwithpurchase: add error', err);
|
|
214
|
-
this.dispatchEvent(
|
|
215
|
-
new CustomEvent('gwp:error', {
|
|
216
|
-
detail: { action: 'add', error: err.message },
|
|
217
|
-
bubbles: true,
|
|
218
|
-
})
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
async #removeGiftFromCart(cart) {
|
|
224
|
-
try {
|
|
225
|
-
// get all GWP items in the cart
|
|
226
|
-
const giftLines = cart.items.filter(
|
|
227
|
-
(lineItem) =>
|
|
228
|
-
lineItem.variant_id.toString() === this.#variantId.toString() &&
|
|
229
|
-
lineItem.properties?._gwp_item === 'true'
|
|
230
|
-
);
|
|
231
|
-
|
|
232
|
-
// exit if no items in the cart
|
|
233
|
-
if (!giftLines.length) {
|
|
234
|
-
this.#isAdded = false;
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// remove all GWP items from the cart
|
|
239
|
-
await this.#removeAllGiftItems(giftLines);
|
|
240
|
-
} catch (err) {
|
|
241
|
-
console.error('giftwithpurchase: remove error', err);
|
|
242
|
-
this.dispatchEvent(
|
|
243
|
-
new CustomEvent('gwp:error', {
|
|
244
|
-
detail: { action: 'remove', error: err.message },
|
|
245
|
-
bubbles: true,
|
|
246
|
-
})
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
async #removeAllGiftItems(giftLines) {
|
|
252
|
-
try {
|
|
253
|
-
await Promise.all(
|
|
254
|
-
giftLines.map((giftItem) =>
|
|
255
|
-
fetch('/cart/change.js', {
|
|
256
|
-
method: 'POST',
|
|
257
|
-
credentials: 'same-origin',
|
|
258
|
-
headers: {
|
|
259
|
-
'Content-Type': 'application/json',
|
|
260
|
-
'X-Requested-With': 'XMLHttpRequest',
|
|
261
|
-
},
|
|
262
|
-
body: JSON.stringify({ id: giftItem.key, quantity: 0 }),
|
|
263
|
-
})
|
|
264
|
-
)
|
|
265
|
-
);
|
|
266
|
-
this.#isAdded = false;
|
|
267
|
-
// note: you can broadcast cart again here if you want real-time re-render after remove
|
|
268
|
-
this.dispatchEvent(
|
|
269
|
-
new CustomEvent('gwp:removed', {
|
|
270
|
-
detail: { variantId: this.#variantId },
|
|
271
|
-
bubbles: true,
|
|
272
|
-
})
|
|
273
|
-
);
|
|
274
|
-
} catch (err) {
|
|
275
|
-
console.error('giftwithpurchase: bulk remove error', err);
|
|
276
|
-
this.dispatchEvent(
|
|
277
|
-
new CustomEvent('gwp:error', {
|
|
278
|
-
detail: { action: 'remove', error: err.message },
|
|
279
|
-
bubbles: true,
|
|
280
|
-
})
|
|
281
|
-
);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
getState() {
|
|
286
|
-
return {
|
|
287
|
-
currentAmount: this.#currentAmount,
|
|
288
|
-
threshold: this.#threshold,
|
|
289
|
-
variantId: this.#variantId,
|
|
290
|
-
isActive: this.#isActive,
|
|
291
|
-
isAdded: this.#isAdded,
|
|
292
|
-
promoEnded: this.#promoEnded,
|
|
293
|
-
remainingAmount: Math.max(0, this.#threshold - this.#currentAmount),
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
get currentAmount() {
|
|
298
|
-
return this.#currentAmount;
|
|
299
|
-
}
|
|
300
|
-
get threshold() {
|
|
301
|
-
return this.#threshold;
|
|
302
|
-
}
|
|
303
|
-
get variantId() {
|
|
304
|
-
return this.#variantId;
|
|
305
|
-
}
|
|
306
|
-
get isActive() {
|
|
307
|
-
return this.#isActive;
|
|
308
|
-
}
|
|
309
|
-
get isAdded() {
|
|
310
|
-
return this.#isAdded;
|
|
311
|
-
}
|
|
312
|
-
get promoEnded() {
|
|
313
|
-
return this.#promoEnded;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// Public setter methods for programmatic control
|
|
317
|
-
setCurrentAmount(amount) {
|
|
318
|
-
this.#currentAmount = parseFloat(amount) || 0;
|
|
319
|
-
this.#updateState({ items: [] }); // Pass empty cart to avoid cart operations
|
|
320
|
-
this.#updateMessages();
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
setThreshold(threshold) {
|
|
324
|
-
this.#threshold = parseFloat(threshold) || 0;
|
|
325
|
-
this.#updateState({ items: [] }); // Pass empty cart to avoid cart operations
|
|
326
|
-
this.#updateMessages();
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
setVariantId(variantId) {
|
|
330
|
-
this.#variantId = variantId;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
if (!customElements.get('gift-with-purchase')) {
|
|
335
|
-
customElements.define('gift-with-purchase', GiftWithPurchase);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
exports.GiftWithPurchase = GiftWithPurchase;
|
|
339
|
-
//# 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// private fields\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#cartDialog = null;\n\t#boundHandleCartDataChange = null; // pre-bound listener ref for clean-up\n\t#debounceTimer = null; // debouncing cart updates\n\t#messageAbove = null; // message when threshold is met\n\t#messageBelow = null; // message when below threshold\n\n\tstatic get observedAttributes() {\n\t\treturn ['threshold', 'current', 'variant-id', 'promo-ended', 'message-above', 'message-below'];\n\t}\n\n\tconstructor() {\n\t\tsuper();\n\t\t// read initial attributes once\n\t\tthis.#threshold = parseFloat(this.getAttribute('threshold')) || 0;\n\t\tthis.#currentAmount = parseFloat(this.getAttribute('current')) || 0;\n\t\tthis.#variantId = this.getAttribute('variant-id');\n\t\tthis.#promoEnded = this.hasAttribute('promo-ended');\n\t\tthis.#messageAbove = this.getAttribute('message-above');\n\t\tthis.#messageBelow = this.getAttribute('message-below');\n\t\tthis.#boundHandleCartDataChange = this.#handleCartDataChange.bind(this);\n\t}\n\n\tconnectedCallback() {\n\t\tthis.#render();\n\t\tthis.#attachListeners();\n\t}\n\n\tdisconnectedCallback() {\n\t\tif (this.#debounceTimer) clearTimeout(this.#debounceTimer);\n\t\tif (this.#cartDialog)\n\t\t\tthis.#cartDialog.removeEventListener(\n\t\t\t\t'cart-dialog:data-changed',\n\t\t\t\tthis.#boundHandleCartDataChange\n\t\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#updateMessages() {\n\t\tconst messageEl = this.querySelector('[data-content-gwp-message]');\n\t\tif (!messageEl) return;\n\n\t\tlet message = '';\n\n\t\t// console.log('updateMessages - this.#isActive', this.#isActive);\n\n\t\tif (this.#isActive && this.#messageAbove) {\n\t\t\t// set message to above threshold message\n\t\t\tmessage = this.#messageAbove;\n\t\t} else if (!this.#isActive && this.#messageBelow) {\n\t\t\t// set message to below threshold message\n\t\t\tconst remaining = this.#threshold - this.#currentAmount;\n\t\t\tconst formattedAmount = remaining.toFixed(2).replace(/\\.00$/, '');\n\t\t\tmessage = this.#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\t// Look for cart-dialog element when attaching listeners (more reliable timing)\n\t\tthis.#cartDialog = this.closest('cart-dialog');\n\n\t\tif (this.#cartDialog) {\n\t\t\t// console.log('cartDialog exists and is attaching events');\n\t\t\tthis.#cartDialog.addEventListener(\n\t\t\t\t'cart-dialog:data-changed',\n\t\t\t\tthis.#boundHandleCartDataChange\n\t\t\t);\n\t\t} else {\n\t\t\t// Try again after a short delay in case the DOM isn't fully ready\n\t\t\tsetTimeout(() => {\n\t\t\t\t// console.log('cartDialog DIDNT exist and we waited to attach events');\n\t\t\t\tthis.#cartDialog = this.closest('cart-dialog');\n\t\t\t\tif (this.#cartDialog) {\n\t\t\t\t\tthis.#cartDialog.addEventListener(\n\t\t\t\t\t\t'cart-dialog:data-changed',\n\t\t\t\t\t\tthis.#boundHandleCartDataChange\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tconsole.error('GWP - cart-dialog still not found after delay');\n\t\t\t\t}\n\t\t\t}, 100);\n\t\t}\n\t}\n\n\t#handleCartDataChange(event) {\n\t\tconst cart = event.detail;\n\t\t// console.log('GWP - handleCartDataChange cart: ', cart.calculated_subtotal, cart);\n\n\t\tif (!cart || typeof cart.calculated_subtotal === 'undefined') return;\n\t\tif (this.#debounceTimer) clearTimeout(this.#debounceTimer);\n\n\t\tthis.#debounceTimer = setTimeout(() => {\n\t\t\tthis.#debounceTimer = null;\n\t\t\tthis.#currentAmount = parseFloat(cart.calculated_subtotal / 100) || 0;\n\t\t\tthis.#checkGiftInCart(cart);\n\t\t\tthis.#updateState(cart);\n\t\t}, 300);\n\t}\n\n\t// checks to see if the gift is already in the cart\n\t#checkGiftInCart(cart) {\n\t\tif (!cart.items || !this.#variantId) {\n\t\t\tthis.#isAdded = false;\n\t\t\treturn;\n\t\t}\n\t\tconst giftLines = cart.items.filter(\n\t\t\t(lineItem) =>\n\t\t\t\tlineItem.variant_id.toString() === this.#variantId.toString() &&\n\t\t\t\tlineItem.properties?._gwp_item === 'true'\n\t\t);\n\t\tthis.#isAdded = giftLines.length > 0;\n\t\tif (this.#promoEnded && giftLines.length) this.#removeAllGiftItems(giftLines);\n\t}\n\n\t#updateState(cart) {\n\t\t// console.log('********** ---------- Updating state....');\n\t\tconst wasActive = this.#isActive;\n\t\tthis.#isActive = this.#currentAmount >= this.#threshold && !this.#promoEnded;\n\n\t\t// console.log('********** ---------- this.#isActive', this.#isActive);\n\n\t\tif (this.#promoEnded) {\n\t\t\t// remove GWP from cart\n\t\t\tthis.#removeGiftFromCart(cart);\n\t\t}\n\n\t\tif (this.#isActive && !wasActive && !this.#isAdded && this.#variantId) {\n\t\t\tthis.#addGiftToCart();\n\t\t} else if (!this.#isActive && wasActive && this.#isAdded && this.#variantId) {\n\t\t\tthis.#removeGiftFromCart(cart);\n\t\t}\n\n\t\tthis.#updateVisualState();\n\t\tthis.#updateMessages();\n\t}\n\n\t#updateVisualState() {\n\t\tif (this.#promoEnded) {\n\t\t\tthis.setAttribute('state', 'ended');\n\t\t\tthis.style.display = 'none';\n\t\t\treturn;\n\t\t}\n\n\t\tthis.style.display = '';\n\t\tif (this.#isAdded) {\n\t\t\tthis.setAttribute('state', 'added');\n\t\t} else if (this.#isActive) {\n\t\t\tthis.setAttribute('state', 'active');\n\t\t}\n\t\t// Note: no 'inactive' state since component wouldn't be loaded if inactive\n\t}\n\n\tasync #addGiftToCart() {\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: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t'X-Requested-With': 'XMLHttpRequest',\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\titems: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: this.#variantId,\n\t\t\t\t\t\t\tquantity: 1,\n\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t_gwp_item: 'true',\n\t\t\t\t\t\t\t\t_hide_in_cart: 'true',\n\t\t\t\t\t\t\t\t_ignore_price_in_subtotal: 'true',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t],\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\tthis.#isAdded = true;\n\t\t\tthis.dispatchEvent(\n\t\t\t\tnew CustomEvent('gwp:added', {\n\t\t\t\t\tdetail: { variantId: this.#variantId },\n\t\t\t\t\tbubbles: true,\n\t\t\t\t})\n\t\t\t);\n\t\t} catch (err) {\n\t\t\tconsole.error('giftwithpurchase: add error', err);\n\t\t\tthis.dispatchEvent(\n\t\t\t\tnew CustomEvent('gwp:error', {\n\t\t\t\t\tdetail: { action: 'add', error: err.message },\n\t\t\t\t\tbubbles: true,\n\t\t\t\t})\n\t\t\t);\n\t\t}\n\t}\n\n\tasync #removeGiftFromCart(cart) {\n\t\ttry {\n\t\t\t// get all GWP items in the cart\n\t\t\tconst giftLines = cart.items.filter(\n\t\t\t\t(lineItem) =>\n\t\t\t\t\tlineItem.variant_id.toString() === this.#variantId.toString() &&\n\t\t\t\t\tlineItem.properties?._gwp_item === 'true'\n\t\t\t);\n\n\t\t\t// exit if no items in the cart\n\t\t\tif (!giftLines.length) {\n\t\t\t\tthis.#isAdded = false;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// remove all GWP items from the cart\n\t\t\tawait this.#removeAllGiftItems(giftLines);\n\t\t} catch (err) {\n\t\t\tconsole.error('giftwithpurchase: remove error', err);\n\t\t\tthis.dispatchEvent(\n\t\t\t\tnew CustomEvent('gwp:error', {\n\t\t\t\t\tdetail: { action: 'remove', error: err.message },\n\t\t\t\t\tbubbles: true,\n\t\t\t\t})\n\t\t\t);\n\t\t}\n\t}\n\n\tasync #removeAllGiftItems(giftLines) {\n\t\ttry {\n\t\t\tawait Promise.all(\n\t\t\t\tgiftLines.map((giftItem) =>\n\t\t\t\t\tfetch('/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: {\n\t\t\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t\t\t'X-Requested-With': 'XMLHttpRequest',\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: JSON.stringify({ id: giftItem.key, quantity: 0 }),\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t);\n\t\t\tthis.#isAdded = false;\n\t\t\t// note: you can broadcast cart again here if you want real-time re-render after remove\n\t\t\tthis.dispatchEvent(\n\t\t\t\tnew CustomEvent('gwp:removed', {\n\t\t\t\t\tdetail: { variantId: this.#variantId },\n\t\t\t\t\tbubbles: true,\n\t\t\t\t})\n\t\t\t);\n\t\t} catch (err) {\n\t\t\tconsole.error('giftwithpurchase: bulk remove error', err);\n\t\t\tthis.dispatchEvent(\n\t\t\t\tnew CustomEvent('gwp:error', {\n\t\t\t\t\tdetail: { action: 'remove', error: err.message },\n\t\t\t\t\tbubbles: true,\n\t\t\t\t})\n\t\t\t);\n\t\t}\n\t}\n\n\tgetState() {\n\t\treturn {\n\t\t\tcurrentAmount: this.#currentAmount,\n\t\t\tthreshold: this.#threshold,\n\t\t\tvariantId: this.#variantId,\n\t\t\tisActive: this.#isActive,\n\t\t\tisAdded: this.#isAdded,\n\t\t\tpromoEnded: this.#promoEnded,\n\t\t\tremainingAmount: Math.max(0, this.#threshold - this.#currentAmount),\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\n\t// Public setter methods for programmatic control\n\tsetCurrentAmount(amount) {\n\t\tthis.#currentAmount = parseFloat(amount) || 0;\n\t\tthis.#updateState({ items: [] }); // Pass empty cart to avoid cart operations\n\t\tthis.#updateMessages();\n\t}\n\n\tsetThreshold(threshold) {\n\t\tthis.#threshold = parseFloat(threshold) || 0;\n\t\tthis.#updateState({ items: [] }); // Pass empty cart to avoid cart operations\n\t\tthis.#updateMessages();\n\t}\n\n\tsetVariantId(variantId) {\n\t\tthis.#variantId = variantId;\n\t}\n}\n\nif (!customElements.get('gift-with-purchase')) {\n\tcustomElements.define('gift-with-purchase', GiftWithPurchase);\n}\n\nexport { GiftWithPurchase };\n"],"names":[],"mappings":";;AAEA;AACA;AACA;AACA;AACA,MAAM,gBAAgB,SAAS,WAAW,CAAC;AAC3C;AACA,CAAC,UAAU,GAAG,CAAC,CAAC;AAChB,CAAC,cAAc,GAAG,CAAC,CAAC;AACpB,CAAC,UAAU,GAAG,IAAI,CAAC;AACnB,CAAC,SAAS,GAAG,KAAK,CAAC;AACnB,CAAC,QAAQ,GAAG,KAAK,CAAC;AAClB,CAAC,WAAW,GAAG,KAAK,CAAC;AACrB,CAAC,WAAW,GAAG,IAAI,CAAC;AACpB,CAAC,0BAA0B,GAAG,IAAI,CAAC;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chase {
|
|
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
|
-
/*# sourceMappingURL=gift-with-purchase.esm.css.map */
|
|
@@ -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","file":"gift-with-purchase.esm.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}"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gift-with-purchase.esm.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// private fields\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#cartDialog = null;\n\t#boundHandleCartDataChange = null; // pre-bound listener ref for clean-up\n\t#debounceTimer = null; // debouncing cart updates\n\t#messageAbove = null; // message when threshold is met\n\t#messageBelow = null; // message when below threshold\n\n\tstatic get observedAttributes() {\n\t\treturn ['threshold', 'current', 'variant-id', 'promo-ended', 'message-above', 'message-below'];\n\t}\n\n\tconstructor() {\n\t\tsuper();\n\t\t// read initial attributes once\n\t\tthis.#threshold = parseFloat(this.getAttribute('threshold')) || 0;\n\t\tthis.#currentAmount = parseFloat(this.getAttribute('current')) || 0;\n\t\tthis.#variantId = this.getAttribute('variant-id');\n\t\tthis.#promoEnded = this.hasAttribute('promo-ended');\n\t\tthis.#messageAbove = this.getAttribute('message-above');\n\t\tthis.#messageBelow = this.getAttribute('message-below');\n\t\tthis.#boundHandleCartDataChange = this.#handleCartDataChange.bind(this);\n\t}\n\n\tconnectedCallback() {\n\t\tthis.#render();\n\t\tthis.#attachListeners();\n\t}\n\n\tdisconnectedCallback() {\n\t\tif (this.#debounceTimer) clearTimeout(this.#debounceTimer);\n\t\tif (this.#cartDialog)\n\t\t\tthis.#cartDialog.removeEventListener(\n\t\t\t\t'cart-dialog:data-changed',\n\t\t\t\tthis.#boundHandleCartDataChange\n\t\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#updateMessages() {\n\t\tconst messageEl = this.querySelector('[data-content-gwp-message]');\n\t\tif (!messageEl) return;\n\n\t\tlet message = '';\n\n\t\t// console.log('updateMessages - this.#isActive', this.#isActive);\n\n\t\tif (this.#isActive && this.#messageAbove) {\n\t\t\t// set message to above threshold message\n\t\t\tmessage = this.#messageAbove;\n\t\t} else if (!this.#isActive && this.#messageBelow) {\n\t\t\t// set message to below threshold message\n\t\t\tconst remaining = this.#threshold - this.#currentAmount;\n\t\t\tconst formattedAmount = remaining.toFixed(2).replace(/\\.00$/, '');\n\t\t\tmessage = this.#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\t// Look for cart-dialog element when attaching listeners (more reliable timing)\n\t\tthis.#cartDialog = this.closest('cart-dialog');\n\n\t\tif (this.#cartDialog) {\n\t\t\t// console.log('cartDialog exists and is attaching events');\n\t\t\tthis.#cartDialog.addEventListener(\n\t\t\t\t'cart-dialog:data-changed',\n\t\t\t\tthis.#boundHandleCartDataChange\n\t\t\t);\n\t\t} else {\n\t\t\t// Try again after a short delay in case the DOM isn't fully ready\n\t\t\tsetTimeout(() => {\n\t\t\t\t// console.log('cartDialog DIDNT exist and we waited to attach events');\n\t\t\t\tthis.#cartDialog = this.closest('cart-dialog');\n\t\t\t\tif (this.#cartDialog) {\n\t\t\t\t\tthis.#cartDialog.addEventListener(\n\t\t\t\t\t\t'cart-dialog:data-changed',\n\t\t\t\t\t\tthis.#boundHandleCartDataChange\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tconsole.error('GWP - cart-dialog still not found after delay');\n\t\t\t\t}\n\t\t\t}, 100);\n\t\t}\n\t}\n\n\t#handleCartDataChange(event) {\n\t\tconst cart = event.detail;\n\t\t// console.log('GWP - handleCartDataChange cart: ', cart.calculated_subtotal, cart);\n\n\t\tif (!cart || typeof cart.calculated_subtotal === 'undefined') return;\n\t\tif (this.#debounceTimer) clearTimeout(this.#debounceTimer);\n\n\t\tthis.#debounceTimer = setTimeout(() => {\n\t\t\tthis.#debounceTimer = null;\n\t\t\tthis.#currentAmount = parseFloat(cart.calculated_subtotal / 100) || 0;\n\t\t\tthis.#checkGiftInCart(cart);\n\t\t\tthis.#updateState(cart);\n\t\t}, 300);\n\t}\n\n\t// checks to see if the gift is already in the cart\n\t#checkGiftInCart(cart) {\n\t\tif (!cart.items || !this.#variantId) {\n\t\t\tthis.#isAdded = false;\n\t\t\treturn;\n\t\t}\n\t\tconst giftLines = cart.items.filter(\n\t\t\t(lineItem) =>\n\t\t\t\tlineItem.variant_id.toString() === this.#variantId.toString() &&\n\t\t\t\tlineItem.properties?._gwp_item === 'true'\n\t\t);\n\t\tthis.#isAdded = giftLines.length > 0;\n\t\tif (this.#promoEnded && giftLines.length) this.#removeAllGiftItems(giftLines);\n\t}\n\n\t#updateState(cart) {\n\t\t// console.log('********** ---------- Updating state....');\n\t\tconst wasActive = this.#isActive;\n\t\tthis.#isActive = this.#currentAmount >= this.#threshold && !this.#promoEnded;\n\n\t\t// console.log('********** ---------- this.#isActive', this.#isActive);\n\n\t\tif (this.#promoEnded) {\n\t\t\t// remove GWP from cart\n\t\t\tthis.#removeGiftFromCart(cart);\n\t\t}\n\n\t\tif (this.#isActive && !wasActive && !this.#isAdded && this.#variantId) {\n\t\t\tthis.#addGiftToCart();\n\t\t} else if (!this.#isActive && wasActive && this.#isAdded && this.#variantId) {\n\t\t\tthis.#removeGiftFromCart(cart);\n\t\t}\n\n\t\tthis.#updateVisualState();\n\t\tthis.#updateMessages();\n\t}\n\n\t#updateVisualState() {\n\t\tif (this.#promoEnded) {\n\t\t\tthis.setAttribute('state', 'ended');\n\t\t\tthis.style.display = 'none';\n\t\t\treturn;\n\t\t}\n\n\t\tthis.style.display = '';\n\t\tif (this.#isAdded) {\n\t\t\tthis.setAttribute('state', 'added');\n\t\t} else if (this.#isActive) {\n\t\t\tthis.setAttribute('state', 'active');\n\t\t}\n\t\t// Note: no 'inactive' state since component wouldn't be loaded if inactive\n\t}\n\n\tasync #addGiftToCart() {\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: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t'X-Requested-With': 'XMLHttpRequest',\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\titems: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: this.#variantId,\n\t\t\t\t\t\t\tquantity: 1,\n\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t_gwp_item: 'true',\n\t\t\t\t\t\t\t\t_hide_in_cart: 'true',\n\t\t\t\t\t\t\t\t_ignore_price_in_subtotal: 'true',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t],\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\tthis.#isAdded = true;\n\t\t\tthis.dispatchEvent(\n\t\t\t\tnew CustomEvent('gwp:added', {\n\t\t\t\t\tdetail: { variantId: this.#variantId },\n\t\t\t\t\tbubbles: true,\n\t\t\t\t})\n\t\t\t);\n\t\t} catch (err) {\n\t\t\tconsole.error('giftwithpurchase: add error', err);\n\t\t\tthis.dispatchEvent(\n\t\t\t\tnew CustomEvent('gwp:error', {\n\t\t\t\t\tdetail: { action: 'add', error: err.message },\n\t\t\t\t\tbubbles: true,\n\t\t\t\t})\n\t\t\t);\n\t\t}\n\t}\n\n\tasync #removeGiftFromCart(cart) {\n\t\ttry {\n\t\t\t// get all GWP items in the cart\n\t\t\tconst giftLines = cart.items.filter(\n\t\t\t\t(lineItem) =>\n\t\t\t\t\tlineItem.variant_id.toString() === this.#variantId.toString() &&\n\t\t\t\t\tlineItem.properties?._gwp_item === 'true'\n\t\t\t);\n\n\t\t\t// exit if no items in the cart\n\t\t\tif (!giftLines.length) {\n\t\t\t\tthis.#isAdded = false;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// remove all GWP items from the cart\n\t\t\tawait this.#removeAllGiftItems(giftLines);\n\t\t} catch (err) {\n\t\t\tconsole.error('giftwithpurchase: remove error', err);\n\t\t\tthis.dispatchEvent(\n\t\t\t\tnew CustomEvent('gwp:error', {\n\t\t\t\t\tdetail: { action: 'remove', error: err.message },\n\t\t\t\t\tbubbles: true,\n\t\t\t\t})\n\t\t\t);\n\t\t}\n\t}\n\n\tasync #removeAllGiftItems(giftLines) {\n\t\ttry {\n\t\t\tawait Promise.all(\n\t\t\t\tgiftLines.map((giftItem) =>\n\t\t\t\t\tfetch('/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: {\n\t\t\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t\t\t'X-Requested-With': 'XMLHttpRequest',\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: JSON.stringify({ id: giftItem.key, quantity: 0 }),\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t);\n\t\t\tthis.#isAdded = false;\n\t\t\t// note: you can broadcast cart again here if you want real-time re-render after remove\n\t\t\tthis.dispatchEvent(\n\t\t\t\tnew CustomEvent('gwp:removed', {\n\t\t\t\t\tdetail: { variantId: this.#variantId },\n\t\t\t\t\tbubbles: true,\n\t\t\t\t})\n\t\t\t);\n\t\t} catch (err) {\n\t\t\tconsole.error('giftwithpurchase: bulk remove error', err);\n\t\t\tthis.dispatchEvent(\n\t\t\t\tnew CustomEvent('gwp:error', {\n\t\t\t\t\tdetail: { action: 'remove', error: err.message },\n\t\t\t\t\tbubbles: true,\n\t\t\t\t})\n\t\t\t);\n\t\t}\n\t}\n\n\tgetState() {\n\t\treturn {\n\t\t\tcurrentAmount: this.#currentAmount,\n\t\t\tthreshold: this.#threshold,\n\t\t\tvariantId: this.#variantId,\n\t\t\tisActive: this.#isActive,\n\t\t\tisAdded: this.#isAdded,\n\t\t\tpromoEnded: this.#promoEnded,\n\t\t\tremainingAmount: Math.max(0, this.#threshold - this.#currentAmount),\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\n\t// Public setter methods for programmatic control\n\tsetCurrentAmount(amount) {\n\t\tthis.#currentAmount = parseFloat(amount) || 0;\n\t\tthis.#updateState({ items: [] }); // Pass empty cart to avoid cart operations\n\t\tthis.#updateMessages();\n\t}\n\n\tsetThreshold(threshold) {\n\t\tthis.#threshold = parseFloat(threshold) || 0;\n\t\tthis.#updateState({ items: [] }); // Pass empty cart to avoid cart operations\n\t\tthis.#updateMessages();\n\t}\n\n\tsetVariantId(variantId) {\n\t\tthis.#variantId = variantId;\n\t}\n}\n\nif (!customElements.get('gift-with-purchase')) {\n\tcustomElements.define('gift-with-purchase', GiftWithPurchase);\n}\n\nexport { GiftWithPurchase };\n"],"names":[],"mappings":"AAEA;AACA;AACA;AACA;AACA,MAAM,gBAAgB,SAAS,WAAW,CAAC;AAC3C;AACA,CAAC,UAAU,GAAG,CAAC,CAAC;AAChB,CAAC,cAAc,GAAG,CAAC,CAAC;AACpB,CAAC,UAAU,GAAG,IAAI,CAAC;AACnB,CAAC,SAAS,GAAG,KAAK,CAAC;AACnB,CAAC,QAAQ,GAAG,KAAK,CAAC;AAClB,CAAC,WAAW,GAAG,KAAK,CAAC;AACrB,CAAC,WAAW,GAAG,IAAI,CAAC;AACpB,CAAC,0BAA0B,GAAG,IAAI,CAAC;AACnC,CAAC,cAAc,GAAG,IAAI,CAAC;AACvB,CAAC,aAAa,GAAG,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BAAmB,CACnB,cAAe,CACf,uBAAwB,CACxB,sBAAuB,CACvB,2BAA4B,CAC5B,0BAA2B,CAC3B,yBAA0B,CAC1B,wBAAyB,CAKzB,qCAAsC,CAHtC,yCAA0C,CAC1C,sCAAuC,CAGvC,4BAA6B,CAL7B,aAAc,CAGd,0BAGF,CACA,gCAEE,sBAAuB,CADvB,YAAa,CAEb,kBACF,CACA,oCACE,aACF,CACA,gCACE,MAAO,CACP,WACF,CACA,iCACE,qCAAsC,CACtC,qCAAsC,CACtC,4BACF,CACA,gCACE,oCAAqC,CACrC,oCAAqC,CACrC,2BACF,CACA,gCACE,YACF","file":"gift-with-purchase.min.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}"]}
|