1export class GuestCheckoutService { 2 constructor({ user = window.user, site = window.site } = {}) { 3 this.user = user; 4 this.site = site; 5 this._searchParams = new URLSearchParams(window.location.search); 6 this._enabled = this._resolveEnabledFlag(); 7 } 8 9 _resolveEnabledFlag() { 10 if (typeof window !== "undefined" && typeof window.__guestCheckoutEnabled !== "undefined") { 11 return Boolean(window.__guestCheckoutEnabled); 12 } 13 14 const sources = []; 15 if (this.site) { 16 sources.push(this.site); 17 if (this.site.Integrations) { 18 sources.push(this.site.Integrations); 19 } 20 } 21 22 for (const source of sources) { 23 if (!source) continue; 24 25 if (typeof source.IsGuestCheckoutEnabled !== "undefined") { 26 return String(source.IsGuestCheckoutEnabled).toLowerCase() === "true"; 27 } 28 29 if (typeof source.isGuestCheckoutEnabled !== "undefined") { 30 return String(source.isGuestCheckoutEnabled).toLowerCase() === "true"; 31 } 32 } 33 34 return true; 35 } 36 37 refreshSearchParams() { 38 this._searchParams = new URLSearchParams(window.location.search); 39 } 40 41 isGuestCheckoutEnabled() { 42 return this._enabled; 43 } 44 45 isGuestModeActive() { 46 if (!this._enabled) return false; 47 return this._searchParams.get("g") === "1"; 48 } 49 50 shouldShowGuestCta() { 51 if (!this._enabled) return false; 52 return !(this.user?.data && Number(this.user.data.memberId) > 0); 53 } 54 55 toggleCartCta({ guestAreaSelector = "#GuestArea" } = {}) { 56 const guestArea = document.querySelector(guestAreaSelector); 57 if (!guestArea) return; 58 59 const shouldShow = this.shouldShowGuestCta(); 60 guestArea.style.display = shouldShow ? "block" : "none"; 61 } 62 63 configureCheckoutEntryUI({ 64 guestAreaSelector = "#GuestArea", 65 createAreaSelector = "#CreateArea", 66 shippingInfoSelector = null, 67 sameAsBillingSelector = null 68 } = {}) { 69 const guestArea = document.querySelector(guestAreaSelector); 70 const createArea = document.querySelector(createAreaSelector); 71 const shippingInfo = shippingInfoSelector ? document.querySelector(shippingInfoSelector) : null; 72 const sameButton = sameAsBillingSelector ? document.querySelector(sameAsBillingSelector) : null; 73 74 if (!this._enabled) { 75 if (guestArea) guestArea.classList.remove("open"); 76 if (createArea) createArea.classList.add("open"); 77 if (shippingInfo) shippingInfo.style.display = ""; 78 if (sameButton) sameButton.classList.remove("checked"); 79 return; 80 } 81 82 if (this.isGuestModeActive()) { 83 if (guestArea) guestArea.classList.add("open"); 84 if (createArea) createArea.classList.remove("open"); 85 if (sameButton && !sameButton.classList.contains("checked")) { 86 sameButton.classList.add("checked"); 87 } 88 if (shippingInfo) { 89 setTimeout(() => { 90 shippingInfo.style.display = "none"; 91 }, 200); 92 } 93 } else { 94 if (createArea) createArea.classList.add("open"); 95 if (guestArea) guestArea.classList.remove("open"); 96 if (shippingInfo) shippingInfo.style.display = ""; 97 if (sameButton) sameButton.classList.remove("checked"); 98 } 99 } 100 101 submitGuestCheckout({ email, firstName, lastName, captcha }) { 102 if (!this._enabled) { 103 if (window.growler && typeof window.growler.error === "function") { 104 window.growler.error("Guest checkout is disabled."); 105 } 106 console.warn("[guestCheckout] submit blocked â feature disabled", { email }); 107 return; 108 } 109 110 if (typeof this.user?.guest === "function") { 111 this.user.guest(email, firstName, lastName, captcha); 112 } else { 113 console.warn("[guestCheckout] user.guest unavailable"); 114 } 115 } 116}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.