ui.shipaid.com 0.3.148 → 0.3.150
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/dist/widget.es.js +404 -93
- package/dist/widget.iife.js +223 -60
- package/dist/widget.umd.js +222 -59
- package/dist-types/widget/src/widgets/shipaid-widget-element.d.ts +60 -1
- package/package.json +1 -1
package/dist/widget.es.js
CHANGED
|
@@ -3643,7 +3643,9 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
3643
3643
|
this._sellingPlanId = null;
|
|
3644
3644
|
this._isUpdatingShipAid = false;
|
|
3645
3645
|
this._lastCartEventAt = 0;
|
|
3646
|
-
this.
|
|
3646
|
+
this._checkoutButtonStylesInjected = false;
|
|
3647
|
+
this._cachedCheckoutButton = null;
|
|
3648
|
+
this._cachedCheckoutButtonClasses = "";
|
|
3647
3649
|
this._onShipAidCartEvent = (event) => {
|
|
3648
3650
|
var _a2, _b2;
|
|
3649
3651
|
if (((_b2 = (_a2 = event == null ? void 0 : event.detail) == null ? void 0 : _a2.data) == null ? void 0 : _b2.source) === "shipaid-widget") return;
|
|
@@ -3768,6 +3770,47 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
3768
3770
|
_toggleBenefits() {
|
|
3769
3771
|
this._isBenefitsOpen = !this._isBenefitsOpen;
|
|
3770
3772
|
}
|
|
3773
|
+
/**
|
|
3774
|
+
* Get the contactless checkout selector from DB or sessionStorage
|
|
3775
|
+
* @private
|
|
3776
|
+
*/
|
|
3777
|
+
_getContactlessCheckoutSelector() {
|
|
3778
|
+
var _a, _b, _c, _d;
|
|
3779
|
+
return ((_d = (_c = (_b = (_a = this._store) == null ? void 0 : _a.widgetConfigurations) == null ? void 0 : _b.widget) == null ? void 0 : _c.theme_checkout) == null ? void 0 : _d.checkoutButtonSelector) || null;
|
|
3780
|
+
}
|
|
3781
|
+
/**
|
|
3782
|
+
* Check if we should use contactless checkout template
|
|
3783
|
+
* @private
|
|
3784
|
+
*/
|
|
3785
|
+
_shouldUseContactlessCheckout() {
|
|
3786
|
+
const dbSelector = this._getContactlessCheckoutSelector();
|
|
3787
|
+
const sessionSelector = sessionStorage.getItem("shipaidWidgetTheme");
|
|
3788
|
+
if (this.useShipAidCheckout || !dbSelector) {
|
|
3789
|
+
return false;
|
|
3790
|
+
}
|
|
3791
|
+
return !!sessionSelector;
|
|
3792
|
+
}
|
|
3793
|
+
/**
|
|
3794
|
+
* Check if widget should be shown based on config
|
|
3795
|
+
* @private
|
|
3796
|
+
*/
|
|
3797
|
+
_shouldShowWidgetContent() {
|
|
3798
|
+
var _a;
|
|
3799
|
+
return !!(this._shouldShowWidget && this.planActive && ((_a = this._store) == null ? void 0 : _a.widgetShowCart));
|
|
3800
|
+
}
|
|
3801
|
+
/**
|
|
3802
|
+
* Determine which template to render
|
|
3803
|
+
* @private
|
|
3804
|
+
*/
|
|
3805
|
+
_getTemplateToRender() {
|
|
3806
|
+
if (!this._hasFinishedSetup) {
|
|
3807
|
+
return this._shouldUseContactlessCheckout() ? this.contactlessCheckoutButtonTemplate() : this.promptTemplate();
|
|
3808
|
+
}
|
|
3809
|
+
if (this._shouldShowWidgetContent()) {
|
|
3810
|
+
return this._shouldUseContactlessCheckout() ? this.contactlessCheckoutButtonTemplate() : this.promptTemplate();
|
|
3811
|
+
}
|
|
3812
|
+
return A;
|
|
3813
|
+
}
|
|
3771
3814
|
get nhost() {
|
|
3772
3815
|
const subdomain = this.env === "prod" ? "gjiyysyzjwuculcymsvb" : this.env === "staging" ? "xfnjpunvafvudwuzwjlm" : "local";
|
|
3773
3816
|
const region = "us-east-1";
|
|
@@ -4160,13 +4203,6 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
4160
4203
|
} catch {
|
|
4161
4204
|
}
|
|
4162
4205
|
}
|
|
4163
|
-
try {
|
|
4164
|
-
this._isReplacingCartSections = true;
|
|
4165
|
-
await refreshShopifyCartUI();
|
|
4166
|
-
} catch {
|
|
4167
|
-
} finally {
|
|
4168
|
-
this._isReplacingCartSections = false;
|
|
4169
|
-
}
|
|
4170
4206
|
}
|
|
4171
4207
|
async addCartProtectionVariant() {
|
|
4172
4208
|
var _a, _b;
|
|
@@ -4682,8 +4718,12 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
4682
4718
|
</div>
|
|
4683
4719
|
`;
|
|
4684
4720
|
}
|
|
4685
|
-
|
|
4686
|
-
|
|
4721
|
+
/**
|
|
4722
|
+
* Inject global styles for checkoutButtonTemplate (only once)
|
|
4723
|
+
* @private
|
|
4724
|
+
*/
|
|
4725
|
+
_injectCheckoutButtonGlobalStyles() {
|
|
4726
|
+
if (this._checkoutButtonStylesInjected) return;
|
|
4687
4727
|
if (!document.getElementById("shipaid-styles")) {
|
|
4688
4728
|
const style = document.createElement("style");
|
|
4689
4729
|
style.id = "shipaid-styles";
|
|
@@ -4698,70 +4738,284 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
4698
4738
|
`;
|
|
4699
4739
|
document.head.appendChild(style);
|
|
4700
4740
|
}
|
|
4741
|
+
this._checkoutButtonStylesInjected = true;
|
|
4742
|
+
}
|
|
4743
|
+
/**
|
|
4744
|
+
* Find and cache the original checkout button for checkoutButtonTemplate
|
|
4745
|
+
* @private
|
|
4746
|
+
*/
|
|
4747
|
+
_findAndCacheCheckoutButton() {
|
|
4748
|
+
var _a;
|
|
4749
|
+
if (this._cachedCheckoutButton && document.contains(this._cachedCheckoutButton)) {
|
|
4750
|
+
return this._cachedCheckoutButton;
|
|
4751
|
+
}
|
|
4701
4752
|
if (!this.dataSelector) {
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
);
|
|
4705
|
-
return;
|
|
4753
|
+
logger.warn("[shipaid-widget] Missing 'data-selector' attribute for checkout button");
|
|
4754
|
+
return null;
|
|
4706
4755
|
}
|
|
4707
|
-
let
|
|
4756
|
+
let button = null;
|
|
4708
4757
|
if (this.shadowRootSelector) {
|
|
4709
4758
|
const shadowHost = document.querySelector(this.shadowRootSelector);
|
|
4710
|
-
if (shadowHost
|
|
4711
|
-
|
|
4759
|
+
if (shadowHost == null ? void 0 : shadowHost.shadowRoot) {
|
|
4760
|
+
button = shadowHost.shadowRoot.querySelector(
|
|
4712
4761
|
`${this.dataSelector}:not(#${this.buttonId || "shipaid-checkout-button"})`
|
|
4713
4762
|
);
|
|
4714
4763
|
} else {
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
);
|
|
4718
|
-
return;
|
|
4764
|
+
logger.warn(`ShadowRoot not found for selector '${this.shadowRootSelector}'`);
|
|
4765
|
+
return null;
|
|
4719
4766
|
}
|
|
4720
4767
|
} else {
|
|
4721
|
-
|
|
4722
|
-
this.dataSelector
|
|
4723
|
-
)) == null ? void 0 : _a[0];
|
|
4768
|
+
button = (_a = this.getElementsBySelector(this.dataSelector)) == null ? void 0 : _a[0];
|
|
4724
4769
|
}
|
|
4725
|
-
if (!
|
|
4726
|
-
|
|
4727
|
-
return;
|
|
4770
|
+
if (!button) {
|
|
4771
|
+
logger.warn(`Checkout button not found with selector '${this.dataSelector}'`);
|
|
4772
|
+
return null;
|
|
4728
4773
|
}
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4774
|
+
this._cachedCheckoutButton = button;
|
|
4775
|
+
this._cachedCheckoutButtonClasses = button.className;
|
|
4776
|
+
return button;
|
|
4777
|
+
}
|
|
4778
|
+
/**
|
|
4779
|
+
* Restore the original checkout button styles/attributes if we modified them
|
|
4780
|
+
* @private
|
|
4781
|
+
*/
|
|
4782
|
+
_restoreCheckoutButtonState() {
|
|
4783
|
+
try {
|
|
4784
|
+
const buttons = [];
|
|
4785
|
+
if (this._cachedCheckoutButton && document.contains(this._cachedCheckoutButton)) {
|
|
4786
|
+
buttons.push(this._cachedCheckoutButton);
|
|
4787
|
+
} else if (this.dataSelector) {
|
|
4788
|
+
this.getElementsBySelector(this.dataSelector).forEach((button) => {
|
|
4789
|
+
buttons.push(button);
|
|
4790
|
+
});
|
|
4791
|
+
}
|
|
4792
|
+
buttons.forEach((button) => {
|
|
4793
|
+
button.removeAttribute("shipaid-hidden");
|
|
4794
|
+
if (button === this._cachedCheckoutButton && this._cachedCheckoutButtonClasses) {
|
|
4795
|
+
button.className = this._cachedCheckoutButtonClasses;
|
|
4796
|
+
}
|
|
4797
|
+
});
|
|
4798
|
+
} catch (error) {
|
|
4799
|
+
console.error("[ShipAid] Error restoring checkout button state:", error);
|
|
4800
|
+
} finally {
|
|
4801
|
+
this._cachedCheckoutButton = null;
|
|
4802
|
+
this._cachedCheckoutButtonClasses = "";
|
|
4803
|
+
}
|
|
4804
|
+
}
|
|
4805
|
+
/**
|
|
4806
|
+
* Calculate cart totals for checkoutButtonTemplate
|
|
4807
|
+
* @private
|
|
4808
|
+
*/
|
|
4809
|
+
_calculateCheckoutCartTotals() {
|
|
4810
|
+
var _a, _b;
|
|
4811
|
+
const protectionPrice = Number((_a = this._protectionVariant) == null ? void 0 : _a.price) || 0;
|
|
4812
|
+
const cartPrice = (Number((_b = this._cart) == null ? void 0 : _b.total_price) || 0) / 100;
|
|
4733
4813
|
const cartTotal = !this._hasProtectionInCart ? protectionPrice + cartPrice : cartPrice;
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4814
|
+
return { protectionPrice, cartPrice, cartTotal };
|
|
4815
|
+
}
|
|
4816
|
+
/**
|
|
4817
|
+
* Get impact features for checkoutButtonTemplate
|
|
4818
|
+
* @private
|
|
4819
|
+
*/
|
|
4820
|
+
_getCheckoutImpactFeatures() {
|
|
4821
|
+
var _a, _b, _c, _d;
|
|
4822
|
+
const isGreenProtectionEnabled = Boolean((_b = (_a = this._store) == null ? void 0 : _a.greenProtection) == null ? void 0 : _b.enabled);
|
|
4823
|
+
const isFreeGiftEnabled = Boolean((_d = (_c = this._store) == null ? void 0 : _c.freeGifts) == null ? void 0 : _d.enabled);
|
|
4740
4824
|
const impactActive = isGreenProtectionEnabled || isFreeGiftEnabled;
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
>
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4825
|
+
return { isGreenProtectionEnabled, isFreeGiftEnabled, impactActive };
|
|
4826
|
+
}
|
|
4827
|
+
/**
|
|
4828
|
+
* Render Get Mechanism theme checkout button
|
|
4829
|
+
* Modern UI based on the mechanism theme design
|
|
4830
|
+
* @private
|
|
4831
|
+
*/
|
|
4832
|
+
_renderGetMechanismCheckoutButton(originalClasses, protectionPrice, cartTotal, _isGreenProtectionEnabled, _isFreeGiftEnabled, loading2) {
|
|
4833
|
+
var _a, _b, _c, _d, _e, _f;
|
|
4834
|
+
return x`
|
|
4835
|
+
<style>
|
|
4836
|
+
:host {
|
|
4837
|
+
display: inline-block;
|
|
4838
|
+
font-family: Arial, sans-serif;
|
|
4839
|
+
width: 100%;
|
|
4840
|
+
}
|
|
4841
|
+
|
|
4842
|
+
.mechanism-container {
|
|
4843
|
+
width: 100%;
|
|
4844
|
+
display: flex;
|
|
4845
|
+
flex-direction: column;
|
|
4846
|
+
}
|
|
4847
|
+
|
|
4848
|
+
.mechanism-protection-card {
|
|
4849
|
+
display: flex;
|
|
4850
|
+
align-items: center;
|
|
4851
|
+
justify-content: space-between;
|
|
4852
|
+
padding: 12px 16px;
|
|
4853
|
+
background: #fff;
|
|
4854
|
+
}
|
|
4855
|
+
|
|
4856
|
+
.mechanism-left {
|
|
4857
|
+
display: flex;
|
|
4858
|
+
align-items: center;
|
|
4859
|
+
gap: 12px;
|
|
4860
|
+
}
|
|
4861
|
+
|
|
4862
|
+
.mechanism-icon {
|
|
4863
|
+
width: 40px;
|
|
4864
|
+
height: 40px;
|
|
4865
|
+
display: flex;
|
|
4866
|
+
align-items: center;
|
|
4867
|
+
justify-content: center;
|
|
4868
|
+
flex-shrink: 0;
|
|
4869
|
+
}
|
|
4870
|
+
|
|
4871
|
+
.mechanism-icon img {
|
|
4872
|
+
width: 100%;
|
|
4873
|
+
height: 100%;
|
|
4874
|
+
object-fit: contain;
|
|
4875
|
+
border-radius: 6px;
|
|
4876
|
+
}
|
|
4877
|
+
|
|
4878
|
+
.mechanism-info {
|
|
4879
|
+
display: flex;
|
|
4880
|
+
flex-direction: column;
|
|
4881
|
+
gap: 2px;
|
|
4882
|
+
}
|
|
4883
|
+
|
|
4884
|
+
.mechanism-title {
|
|
4885
|
+
display: flex;
|
|
4886
|
+
font-weight: 600;
|
|
4887
|
+
font-size: 14px;
|
|
4888
|
+
line-height: 1.2;
|
|
4889
|
+
margin: 0;
|
|
4890
|
+
}
|
|
4891
|
+
|
|
4892
|
+
.mechanism-subtitle {
|
|
4893
|
+
font-size: 12px;
|
|
4894
|
+
color: #6b7280;
|
|
4895
|
+
margin: 0;
|
|
4896
|
+
}
|
|
4897
|
+
|
|
4898
|
+
.mechanism-price {
|
|
4899
|
+
font-weight: 600;
|
|
4900
|
+
font-size: 14px;
|
|
4901
|
+
color: #000;
|
|
4902
|
+
}
|
|
4903
|
+
|
|
4904
|
+
.mechanism-info-icon {
|
|
4905
|
+
width: 16px;
|
|
4906
|
+
height: 16px;
|
|
4907
|
+
border-radius: 50%;
|
|
4908
|
+
border: 1.5px solid #9ca3af;
|
|
4909
|
+
display: flex;
|
|
4910
|
+
align-items: center;
|
|
4911
|
+
justify-content: center;
|
|
4912
|
+
font-size: 11px;
|
|
4913
|
+
color: #9ca3af;
|
|
4914
|
+
font-weight: 600;
|
|
4915
|
+
cursor: pointer;
|
|
4916
|
+
margin-left: 6px;
|
|
4917
|
+
}
|
|
4918
|
+
|
|
4919
|
+
.mechanism-checkout-button {
|
|
4920
|
+
width: 100%;
|
|
4921
|
+
padding: 14px;
|
|
4922
|
+
background: #000;
|
|
4923
|
+
color: #fff;
|
|
4924
|
+
border: none;
|
|
4925
|
+
border-radius: 6px;
|
|
4926
|
+
font-weight: 600;
|
|
4927
|
+
font-size: 15px;
|
|
4928
|
+
cursor: pointer;
|
|
4929
|
+
transition: opacity 0.2s;
|
|
4930
|
+
display: flex;
|
|
4931
|
+
align-items: center;
|
|
4932
|
+
justify-content: center;
|
|
4933
|
+
gap: 8px;
|
|
4934
|
+
}
|
|
4935
|
+
|
|
4936
|
+
.mechanism-checkout-button:hover {
|
|
4937
|
+
opacity: 0.9;
|
|
4938
|
+
}
|
|
4939
|
+
|
|
4940
|
+
.mechanism-continue-link {
|
|
4941
|
+
text-align: center;
|
|
4942
|
+
font-size: 13px;
|
|
4943
|
+
color: #6b7280;
|
|
4944
|
+
text-decoration: underline;
|
|
4945
|
+
cursor: pointer;
|
|
4946
|
+
padding: 8px;
|
|
4947
|
+
}
|
|
4948
|
+
|
|
4949
|
+
.mechanism-continue-link:hover {
|
|
4950
|
+
color: #000;
|
|
4951
|
+
}
|
|
4952
|
+
</style>
|
|
4953
|
+
|
|
4954
|
+
<div class="mechanism-container">
|
|
4955
|
+
<div class="mechanism-protection-card">
|
|
4956
|
+
<div class="mechanism-left">
|
|
4957
|
+
<div class="mechanism-icon">
|
|
4958
|
+
${((_b = (_a = this._store) == null ? void 0 : _a.widgetConfigurations) == null ? void 0 : _b.theme_logo) ? x`<img src="${this._store.widgetConfigurations.theme_logo}" alt="Logo" />` : x`<img src="${ShipAidBlueIcon}" alt="ShipAid" />`}
|
|
4959
|
+
</div>
|
|
4960
|
+
<div class="mechanism-info">
|
|
4961
|
+
<p class="mechanism-title">
|
|
4962
|
+
Checkout+
|
|
4963
|
+
<span class="mechanism-info-icon" @click=${this._openLearnMore}>i</span>
|
|
4964
|
+
</p>
|
|
4965
|
+
<p class="mechanism-subtitle">Free returns + package protection</p>
|
|
4966
|
+
</div>
|
|
4967
|
+
</div>
|
|
4968
|
+
<div class="mechanism-price">
|
|
4969
|
+
${protectionPrice ? this._currencyFormat(protectionPrice) : loading2}
|
|
4970
|
+
</div>
|
|
4971
|
+
</div>
|
|
4972
|
+
|
|
4973
|
+
${this._sellingPlanId ? x`
|
|
4974
|
+
<button
|
|
4975
|
+
class="mechanism-checkout-button ${originalClasses}"
|
|
4976
|
+
@click=${async () => {
|
|
4977
|
+
var _a2, _b2;
|
|
4978
|
+
sessionStorage.setItem(
|
|
4979
|
+
"shipaid_variant",
|
|
4980
|
+
JSON.stringify((_a2 = this._protectionVariant) == null ? void 0 : _a2.id)
|
|
4981
|
+
);
|
|
4982
|
+
await this.addCartProtectionVariant();
|
|
4983
|
+
window.location.href = `/checkout?attributes[_shipaid-internal]=1&updates[${(_b2 = this._protectionVariant) == null ? void 0 : _b2.id}]=1`;
|
|
4984
|
+
}}
|
|
4985
|
+
>
|
|
4986
|
+
Checkout+ | ${cartTotal ? this._currencyFormat(cartTotal) : loading2}
|
|
4987
|
+
</button>
|
|
4988
|
+
` : x`
|
|
4989
|
+
<a
|
|
4990
|
+
href="/checkout${((_c = this._protectionVariant) == null ? void 0 : _c.id) ? `?attributes[_shipaid-internal]=1&updates[${(_d = this._protectionVariant) == null ? void 0 : _d.id}]=1` : ""}"
|
|
4991
|
+
class="mechanism-checkout-button ${originalClasses}"
|
|
4992
|
+
@click=${() => {
|
|
4993
|
+
var _a2;
|
|
4994
|
+
sessionStorage.setItem(
|
|
4995
|
+
"shipaid_variant",
|
|
4996
|
+
JSON.stringify((_a2 = this._protectionVariant) == null ? void 0 : _a2.id)
|
|
4997
|
+
);
|
|
4998
|
+
}}
|
|
4999
|
+
>
|
|
5000
|
+
Checkout+ | ${cartTotal ? this._currencyFormat(cartTotal) : loading2}
|
|
5001
|
+
</a>
|
|
5002
|
+
`}
|
|
5003
|
+
|
|
5004
|
+
<a
|
|
5005
|
+
href="/checkout${((_e = this._protectionVariant) == null ? void 0 : _e.id) ? `?attributes[_shipaid-internal]=1&updates[${(_f = this._protectionVariant) == null ? void 0 : _f.id}]=0` : ""}"
|
|
5006
|
+
class="mechanism-continue-link"
|
|
5007
|
+
>
|
|
5008
|
+
Checkout without free returns & package protection
|
|
5009
|
+
</a>
|
|
5010
|
+
</div>
|
|
4764
5011
|
`;
|
|
5012
|
+
}
|
|
5013
|
+
/**
|
|
5014
|
+
* Render default/original checkout button UI
|
|
5015
|
+
* @private
|
|
5016
|
+
*/
|
|
5017
|
+
_renderDefaultCheckoutButton(originalClasses, protectionPrice, cartTotal, isGreenProtectionEnabled, isFreeGiftEnabled, impactActive, loading2) {
|
|
5018
|
+
var _a, _b, _c, _d, _e, _f;
|
|
4765
5019
|
return x`
|
|
4766
5020
|
<style>
|
|
4767
5021
|
:host {
|
|
@@ -4967,7 +5221,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
4967
5221
|
${this._sellingPlanId ? x`
|
|
4968
5222
|
<button
|
|
4969
5223
|
id="${this.buttonId || "shipaid-checkout-button"}"
|
|
4970
|
-
variant="${(
|
|
5224
|
+
variant="${(_a = this._protectionVariant) == null ? void 0 : _a.id}"
|
|
4971
5225
|
class="${this.buttonClasses || originalClasses}"
|
|
4972
5226
|
@click=${async () => {
|
|
4973
5227
|
var _a2, _b2;
|
|
@@ -4984,8 +5238,8 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
4984
5238
|
</button>
|
|
4985
5239
|
` : x`
|
|
4986
5240
|
<a
|
|
4987
|
-
variant="${(
|
|
4988
|
-
href="/checkout${((
|
|
5241
|
+
variant="${(_b = this._protectionVariant) == null ? void 0 : _b.id}"
|
|
5242
|
+
href="/checkout${((_c = this._protectionVariant) == null ? void 0 : _c.id) ? `?attributes[_shipaid-internal]=1&updates[${(_d = this._protectionVariant) == null ? void 0 : _d.id}]=1` : ""}"
|
|
4989
5243
|
id="${this.buttonId || "shipaid-checkout-button"}"
|
|
4990
5244
|
class="${this.buttonClasses || originalClasses}"
|
|
4991
5245
|
@click=${() => {
|
|
@@ -5007,7 +5261,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
5007
5261
|
</a>
|
|
5008
5262
|
`}
|
|
5009
5263
|
<a
|
|
5010
|
-
href="/checkout${((
|
|
5264
|
+
href="/checkout${((_e = this._protectionVariant) == null ? void 0 : _e.id) ? `?attributes[_shipaid-internal]=1&updates[${(_f = this._protectionVariant) == null ? void 0 : _f.id}]=0` : ""}"
|
|
5011
5265
|
class="continue-link"
|
|
5012
5266
|
>
|
|
5013
5267
|
<slot name="link-continue"
|
|
@@ -5017,6 +5271,60 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
5017
5271
|
</div>
|
|
5018
5272
|
`;
|
|
5019
5273
|
}
|
|
5274
|
+
checkoutButtonTemplate() {
|
|
5275
|
+
var _a, _b;
|
|
5276
|
+
this._injectCheckoutButtonGlobalStyles();
|
|
5277
|
+
const originalCheckoutButton = this._findAndCacheCheckoutButton();
|
|
5278
|
+
if (!originalCheckoutButton) return;
|
|
5279
|
+
originalCheckoutButton.setAttribute("shipaid-hidden", "");
|
|
5280
|
+
const originalClasses = this._cachedCheckoutButtonClasses || originalCheckoutButton.className;
|
|
5281
|
+
const { protectionPrice, cartTotal } = this._calculateCheckoutCartTotals();
|
|
5282
|
+
const { isGreenProtectionEnabled, isFreeGiftEnabled, impactActive } = this._getCheckoutImpactFeatures();
|
|
5283
|
+
const loading2 = x`
|
|
5284
|
+
<svg
|
|
5285
|
+
width="1.5rem"
|
|
5286
|
+
height="1.5rem"
|
|
5287
|
+
viewBox="0 0 50 50"
|
|
5288
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
5289
|
+
fill="none"
|
|
5290
|
+
stroke="currentColor"
|
|
5291
|
+
stroke-width="4"
|
|
5292
|
+
class="shipaid-loader"
|
|
5293
|
+
>
|
|
5294
|
+
<circle cx="25" cy="25" r="20" stroke-opacity="0.5" />
|
|
5295
|
+
<path d="M45 25a20 20 0 0 1-40 0" stroke="currentColor">
|
|
5296
|
+
<animateTransform
|
|
5297
|
+
attributeName="transform"
|
|
5298
|
+
type="rotate"
|
|
5299
|
+
from="0 25 25"
|
|
5300
|
+
to="360 25 25"
|
|
5301
|
+
dur="1s"
|
|
5302
|
+
repeatCount="indefinite"
|
|
5303
|
+
/>
|
|
5304
|
+
</path>
|
|
5305
|
+
</svg>
|
|
5306
|
+
`;
|
|
5307
|
+
const useGetMechanismTheme = ((_b = (_a = this._store) == null ? void 0 : _a.widgetConfigurations) == null ? void 0 : _b.theme) === "get_mechanism";
|
|
5308
|
+
if (useGetMechanismTheme) {
|
|
5309
|
+
return this._renderGetMechanismCheckoutButton(
|
|
5310
|
+
originalClasses,
|
|
5311
|
+
protectionPrice,
|
|
5312
|
+
cartTotal,
|
|
5313
|
+
isGreenProtectionEnabled,
|
|
5314
|
+
isFreeGiftEnabled,
|
|
5315
|
+
loading2
|
|
5316
|
+
);
|
|
5317
|
+
}
|
|
5318
|
+
return this._renderDefaultCheckoutButton(
|
|
5319
|
+
originalClasses,
|
|
5320
|
+
protectionPrice,
|
|
5321
|
+
cartTotal,
|
|
5322
|
+
isGreenProtectionEnabled,
|
|
5323
|
+
isFreeGiftEnabled,
|
|
5324
|
+
impactActive,
|
|
5325
|
+
loading2
|
|
5326
|
+
);
|
|
5327
|
+
}
|
|
5020
5328
|
renderPopups() {
|
|
5021
5329
|
if (this.persistPopup) {
|
|
5022
5330
|
this._popup = this.shouldPersistPopup();
|
|
@@ -5224,6 +5532,31 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
5224
5532
|
document.removeEventListener(SHIPAID_EVENTS.CART_UPDATED, this._onShipAidInternalCartUpdated);
|
|
5225
5533
|
} catch {
|
|
5226
5534
|
}
|
|
5535
|
+
this._restoreCheckoutButtonState();
|
|
5536
|
+
}
|
|
5537
|
+
updated(changedProperties) {
|
|
5538
|
+
super.updated(changedProperties);
|
|
5539
|
+
if (!this._hasFinishedSetup) return;
|
|
5540
|
+
const dbContactlessSelector = this._getContactlessCheckoutSelector();
|
|
5541
|
+
const sessionSelector = sessionStorage.getItem("shipaidWidgetTheme");
|
|
5542
|
+
if (!sessionSelector && dbContactlessSelector) {
|
|
5543
|
+
sessionStorage.setItem("shipaidWidgetTheme", dbContactlessSelector);
|
|
5544
|
+
}
|
|
5545
|
+
if (this.useShipAidCheckout || !dbContactlessSelector) {
|
|
5546
|
+
sessionStorage.removeItem("shipaidWidgetTheme");
|
|
5547
|
+
}
|
|
5548
|
+
if (!this.useShipAidCheckout) {
|
|
5549
|
+
document.querySelectorAll('[id*="shipaid-checkout-container"]').forEach((container) => container.remove());
|
|
5550
|
+
}
|
|
5551
|
+
if (!this._shouldShowWidgetContent()) {
|
|
5552
|
+
const selector = sessionStorage.getItem("shipaidWidgetTheme") || this.dataSelector;
|
|
5553
|
+
if (selector) {
|
|
5554
|
+
this.getElementsBySelector(selector).forEach((button) => {
|
|
5555
|
+
button.removeAttribute("shipaid-hidden");
|
|
5556
|
+
});
|
|
5557
|
+
}
|
|
5558
|
+
this._restoreCheckoutButtonState();
|
|
5559
|
+
}
|
|
5227
5560
|
}
|
|
5228
5561
|
async updateProtection(force = false) {
|
|
5229
5562
|
var _a, _b, _c;
|
|
@@ -5282,11 +5615,13 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
5282
5615
|
}
|
|
5283
5616
|
if (!(protectionVariant == null ? void 0 : protectionVariant.id)) {
|
|
5284
5617
|
this._shouldShowWidget = false;
|
|
5618
|
+
this._restoreCheckoutButtonState();
|
|
5285
5619
|
logger.error("No matching protection variant found.");
|
|
5286
5620
|
return;
|
|
5287
5621
|
}
|
|
5288
5622
|
if (!((_c = this._protectionVariant) == null ? void 0 : _c.id)) {
|
|
5289
5623
|
this._shouldShowWidget = false;
|
|
5624
|
+
this._restoreCheckoutButtonState();
|
|
5290
5625
|
return;
|
|
5291
5626
|
}
|
|
5292
5627
|
if (this.useShipAidCheckout && this.supportSubscriptions) {
|
|
@@ -5397,18 +5732,21 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
5397
5732
|
logger.error(error.message);
|
|
5398
5733
|
this._hasFinishedSetup = true;
|
|
5399
5734
|
this._shouldShowWidget = false;
|
|
5735
|
+
this._restoreCheckoutButtonState();
|
|
5400
5736
|
return;
|
|
5401
5737
|
}
|
|
5402
5738
|
if (!this.planActive) {
|
|
5403
5739
|
logger.warn("No plan is active for this store - skipping setup.");
|
|
5404
5740
|
this._hasFinishedSetup = true;
|
|
5405
5741
|
this._shouldShowWidget = false;
|
|
5742
|
+
this._restoreCheckoutButtonState();
|
|
5406
5743
|
return;
|
|
5407
5744
|
}
|
|
5408
5745
|
if (!((_b = (_a = this._store) == null ? void 0 : _a.protectionSettings) == null ? void 0 : _b.protectionType)) {
|
|
5409
5746
|
logger.warn("No protection settings for this store - skipping setup.");
|
|
5410
5747
|
this._hasFinishedSetup = true;
|
|
5411
5748
|
this._shouldShowWidget = false;
|
|
5749
|
+
this._restoreCheckoutButtonState();
|
|
5412
5750
|
return;
|
|
5413
5751
|
}
|
|
5414
5752
|
if (!this._protectionProduct) {
|
|
@@ -5417,6 +5755,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
5417
5755
|
);
|
|
5418
5756
|
this._hasFinishedSetup = true;
|
|
5419
5757
|
this._shouldShowWidget = false;
|
|
5758
|
+
this._restoreCheckoutButtonState();
|
|
5420
5759
|
return;
|
|
5421
5760
|
}
|
|
5422
5761
|
this._hasFinishedSetup = true;
|
|
@@ -5842,35 +6181,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
5842
6181
|
}
|
|
5843
6182
|
</style>
|
|
5844
6183
|
<div class="shipaid">
|
|
5845
|
-
${
|
|
5846
|
-
this._hasFinishedSetup,
|
|
5847
|
-
() => {
|
|
5848
|
-
var _a, _b, _c, _d, _e;
|
|
5849
|
-
const dbContactlessCheckoutSelector = (_d = (_c = (_b = (_a = this._store) == null ? void 0 : _a.widgetConfigurations) == null ? void 0 : _b.widget) == null ? void 0 : _c.theme_checkout) == null ? void 0 : _d.checkoutButtonSelector;
|
|
5850
|
-
const inSessionStorageCheckoutButtonSelector = sessionStorage.getItem("shipaidWidgetTheme");
|
|
5851
|
-
if (!inSessionStorageCheckoutButtonSelector && dbContactlessCheckoutSelector) {
|
|
5852
|
-
sessionStorage.setItem(
|
|
5853
|
-
"shipaidWidgetTheme",
|
|
5854
|
-
dbContactlessCheckoutSelector
|
|
5855
|
-
);
|
|
5856
|
-
}
|
|
5857
|
-
if (this.useShipAidCheckout || !dbContactlessCheckoutSelector) {
|
|
5858
|
-
sessionStorage.removeItem("shipaidWidgetTheme");
|
|
5859
|
-
}
|
|
5860
|
-
const configOk = this._shouldShowWidget && this.planActive && ((_e = this._store) == null ? void 0 : _e.widgetShowCart);
|
|
5861
|
-
if (configOk) {
|
|
5862
|
-
return inSessionStorageCheckoutButtonSelector ? this.contactlessCheckoutButtonTemplate() : this.promptTemplate();
|
|
5863
|
-
}
|
|
5864
|
-
if (!this.useShipAidCheckout) {
|
|
5865
|
-
document.querySelectorAll('[id*="shipaid-checkout-container"]').forEach((container) => container.remove());
|
|
5866
|
-
}
|
|
5867
|
-
this.getElementsBySelector(
|
|
5868
|
-
sessionStorage.getItem("shipaidWidgetTheme") || this.dataSelector
|
|
5869
|
-
).forEach((button) => button.removeAttribute("shipaid-hidden"));
|
|
5870
|
-
return A;
|
|
5871
|
-
},
|
|
5872
|
-
() => sessionStorage.getItem("shipaidWidgetTheme") ? this.contactlessCheckoutButtonTemplate() : this.promptTemplate()
|
|
5873
|
-
)}
|
|
6184
|
+
${this._getTemplateToRender()}
|
|
5874
6185
|
</div>
|
|
5875
6186
|
`;
|
|
5876
6187
|
}
|