ui.shipaid.com 0.3.95 → 0.3.97
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 +53 -38
- package/dist/widget.iife.js +83 -79
- package/dist/widget.umd.js +83 -79
- package/dist-types/widget/src/shipaid-widget.d.ts +3 -1
- package/package.json +1 -1
package/dist/widget.es.js
CHANGED
|
@@ -2392,6 +2392,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
2392
2392
|
this.fetchInterceptorCleanup = () => {
|
|
2393
2393
|
};
|
|
2394
2394
|
this.intervalId = null;
|
|
2395
|
+
this._sellingPlanId = null;
|
|
2395
2396
|
this._state = {
|
|
2396
2397
|
loading: false,
|
|
2397
2398
|
success: null,
|
|
@@ -2758,28 +2759,17 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
2758
2759
|
this._cart = cart;
|
|
2759
2760
|
}
|
|
2760
2761
|
async addCartProtectionVariant() {
|
|
2761
|
-
var _a, _b
|
|
2762
|
+
var _a, _b;
|
|
2762
2763
|
let cart;
|
|
2763
|
-
let sellingPlanId;
|
|
2764
|
-
if (this.supportSubscriptions) {
|
|
2765
|
-
const itemWithSubscription = (_b = (_a = this._cart) == null ? void 0 : _a.items) == null ? void 0 : _b.find((item) => {
|
|
2766
|
-
var _a2;
|
|
2767
|
-
return item.id !== ((_a2 = this._protectionVariant) == null ? void 0 : _a2.id) && !!(item == null ? void 0 : item.selling_plan_allocation);
|
|
2768
|
-
});
|
|
2769
|
-
if (itemWithSubscription) {
|
|
2770
|
-
const protectionSellingPlan = await this._fetchSellingPlanFromVariant(itemWithSubscription.selling_plan_allocation.selling_plan);
|
|
2771
|
-
sellingPlanId = protectionSellingPlan ? getIdFromShopifyGid(protectionSellingPlan.id) : null;
|
|
2772
|
-
}
|
|
2773
|
-
}
|
|
2774
2764
|
if (this.useCustomStoreFront) {
|
|
2775
2765
|
const cartItemAdded = await this.runStoreFrontQuery(
|
|
2776
2766
|
"mutation AddItemToCart($cartId: ID!, $lines: [CartLineInput!]!) { cartLinesAdd(cartId: $cartId, lines: $lines) { cart { id lines(first: 10) { edges { node { id quantity merchandise { ... on ProductVariant { id sku } } cost{ totalAmount{ amount currencyCode } } } } } cost { totalAmount { amount currencyCode } subtotalAmount { amount currencyCode } } } } }",
|
|
2777
2767
|
{
|
|
2778
2768
|
cartId: this.cartId,
|
|
2779
2769
|
lines: [{
|
|
2780
|
-
merchandiseId: String((
|
|
2770
|
+
merchandiseId: String((_a = this._protectionVariant) == null ? void 0 : _a.id),
|
|
2781
2771
|
quantity: 1,
|
|
2782
|
-
sellingPlanId
|
|
2772
|
+
sellingPlanId: this._sellingPlanId
|
|
2783
2773
|
}]
|
|
2784
2774
|
}
|
|
2785
2775
|
);
|
|
@@ -2787,8 +2777,8 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
2787
2777
|
} else {
|
|
2788
2778
|
const payload = {
|
|
2789
2779
|
quantity: 1,
|
|
2790
|
-
id: String((
|
|
2791
|
-
selling_plan:
|
|
2780
|
+
id: String((_b = this._protectionVariant) == null ? void 0 : _b.id),
|
|
2781
|
+
selling_plan: this._sellingPlanId
|
|
2792
2782
|
};
|
|
2793
2783
|
cart = await this._fetch.post(
|
|
2794
2784
|
"/cart/add.js",
|
|
@@ -2797,7 +2787,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
2797
2787
|
}
|
|
2798
2788
|
return cart;
|
|
2799
2789
|
}
|
|
2800
|
-
async updateCartProtectionVariant(qty, protectionCartItem = null
|
|
2790
|
+
async updateCartProtectionVariant(qty, protectionCartItem = null) {
|
|
2801
2791
|
var _a, _b;
|
|
2802
2792
|
let cart;
|
|
2803
2793
|
if (this.useCustomStoreFront) {
|
|
@@ -2809,7 +2799,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
2809
2799
|
{
|
|
2810
2800
|
id: String(protectionCartItem ? protectionCartItem.key : (_a = this._protectionCartItem) == null ? void 0 : _a.key),
|
|
2811
2801
|
quantity: qty,
|
|
2812
|
-
sellingPlanId
|
|
2802
|
+
sellingPlanId: this._sellingPlanId
|
|
2813
2803
|
}
|
|
2814
2804
|
]
|
|
2815
2805
|
}
|
|
@@ -2819,7 +2809,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
2819
2809
|
const payload = {
|
|
2820
2810
|
quantity: qty,
|
|
2821
2811
|
id: String(protectionCartItem ? protectionCartItem.key : (_b = this._protectionCartItem) == null ? void 0 : _b.key),
|
|
2822
|
-
selling_plan:
|
|
2812
|
+
selling_plan: this._sellingPlanId
|
|
2823
2813
|
};
|
|
2824
2814
|
cart = await this._fetch.post(
|
|
2825
2815
|
"/cart/change.js",
|
|
@@ -3080,8 +3070,21 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
3080
3070
|
createRenderRoot() {
|
|
3081
3071
|
return this.useShipAidCheckout ? this : super.createRenderRoot();
|
|
3082
3072
|
}
|
|
3073
|
+
async getSubscription(_cart) {
|
|
3074
|
+
var _a;
|
|
3075
|
+
if (!(_cart == null ? void 0 : _cart.items) || !(_cart == null ? void 0 : _cart.item_count)) return;
|
|
3076
|
+
const itemWithSubscription = (_a = _cart == null ? void 0 : _cart.items) == null ? void 0 : _a.find((item) => {
|
|
3077
|
+
var _a2;
|
|
3078
|
+
return item.id !== ((_a2 = this._protectionVariant) == null ? void 0 : _a2.id) && !!(item == null ? void 0 : item.selling_plan_allocation);
|
|
3079
|
+
});
|
|
3080
|
+
if (itemWithSubscription) {
|
|
3081
|
+
const protectionSellingPlan = await this._fetchSellingPlanFromVariant(itemWithSubscription.selling_plan_allocation.selling_plan);
|
|
3082
|
+
return protectionSellingPlan ? getIdFromShopifyGid(protectionSellingPlan.id) : null;
|
|
3083
|
+
}
|
|
3084
|
+
return null;
|
|
3085
|
+
}
|
|
3083
3086
|
checkoutButtonTemplate() {
|
|
3084
|
-
var _a, _b, _c, _d, _e;
|
|
3087
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
3085
3088
|
if (!document.getElementById("shipaid-styles")) {
|
|
3086
3089
|
const style = document.createElement("style");
|
|
3087
3090
|
style.id = "shipaid-styles";
|
|
@@ -3244,19 +3247,25 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
3244
3247
|
</svg>
|
|
3245
3248
|
</div>
|
|
3246
3249
|
</div>
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
var _a2;
|
|
3250
|
+
${this._sellingPlanId ? x`
|
|
3251
|
+
<button id="shipaid-checkout-button" class="${originalClasses}" @click=${async () => {
|
|
3252
|
+
var _a2, _b2;
|
|
3250
3253
|
sessionStorage.setItem("shipaid_variant", JSON.stringify((_a2 = this._protectionVariant) == null ? void 0 : _a2.id));
|
|
3254
|
+
await this.addCartProtectionVariant();
|
|
3255
|
+
window.location.href = `/checkout?attributes[_shipaid-internal]=1&updates[${(_b2 = this._protectionVariant) == null ? void 0 : _b2.id}]=1`;
|
|
3251
3256
|
}}>
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
window.location.href = "/checkout";
|
|
3257
|
+
<slot name="checkout-button-text">CHECKOUT+</slot> ${cartTotal ? this._currencyFormat(cartTotal) : loading2}
|
|
3258
|
+
</button>
|
|
3259
|
+
` : x`
|
|
3260
|
+
<a href="/checkout${((_d = this._protectionVariant) == null ? void 0 : _d.id) ? `?attributes[_shipaid-internal]=1&updates[${(_e = this._protectionVariant) == null ? void 0 : _e.id}]=1` : ""}" id="shipaid-checkout-button" class="${originalClasses}" @click=${() => {
|
|
3261
|
+
var _a2;
|
|
3262
|
+
sessionStorage.setItem("shipaid_variant", JSON.stringify((_a2 = this._protectionVariant) == null ? void 0 : _a2.id));
|
|
3259
3263
|
}}>
|
|
3264
|
+
<span class="shipaid-checkout-text">${translate("checkout-plus.checkout")}+</span>
|
|
3265
|
+
<span class="shipaid-checkout-amount">${cartTotal ? this._currencyFormat(cartTotal) : loading2}</span>
|
|
3266
|
+
</a>
|
|
3267
|
+
`}
|
|
3268
|
+
<a href="/checkout${((_f = this._protectionVariant) == null ? void 0 : _f.id) ? `?attributes[_shipaid-internal]=1&updates[${(_g = this._protectionVariant) == null ? void 0 : _g.id}]=0` : ""}" class="continue-link">
|
|
3260
3269
|
<slot name="link-continue">${translate("checkout-plus.continue")}</slot>
|
|
3261
3270
|
</a>
|
|
3262
3271
|
</div>
|
|
@@ -3440,22 +3449,25 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
3440
3449
|
this._shouldShowWidget = false;
|
|
3441
3450
|
return;
|
|
3442
3451
|
}
|
|
3452
|
+
if (this.useShipAidCheckout && this.supportSubscriptions) {
|
|
3453
|
+
this._sellingPlanId = await this.getSubscription(this._cart);
|
|
3454
|
+
}
|
|
3443
3455
|
if (!protectionCartItem) return;
|
|
3444
|
-
if (this.supportSubscriptions) {
|
|
3456
|
+
if (this.supportSubscriptions && !this.useShipAidCheckout) {
|
|
3445
3457
|
const itemWithSubscription = this._cart.items.find((item) => {
|
|
3446
3458
|
var _a2;
|
|
3447
3459
|
return item.id !== ((_a2 = this._protectionVariant) == null ? void 0 : _a2.id) && !!(item == null ? void 0 : item.selling_plan_allocation);
|
|
3448
3460
|
});
|
|
3449
|
-
let
|
|
3461
|
+
let shouldUpdateSubscription = true;
|
|
3450
3462
|
if (!itemWithSubscription && (protectionCartItem == null ? void 0 : protectionCartItem.selling_plan_allocation)) {
|
|
3451
|
-
|
|
3463
|
+
this._sellingPlanId = null;
|
|
3452
3464
|
} else if (itemWithSubscription && !(protectionCartItem == null ? void 0 : protectionCartItem.selling_plan_allocation)) {
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3465
|
+
this._sellingPlanId = await this.getSubscription(this._cart);
|
|
3466
|
+
} else {
|
|
3467
|
+
shouldUpdateSubscription = false;
|
|
3456
3468
|
}
|
|
3457
|
-
if (
|
|
3458
|
-
const cart2 = await this.updateCartProtectionVariant(
|
|
3469
|
+
if (shouldUpdateSubscription) {
|
|
3470
|
+
const cart2 = await this.updateCartProtectionVariant(1, protectionCartItem);
|
|
3459
3471
|
await this._handleRefresh(cart2);
|
|
3460
3472
|
}
|
|
3461
3473
|
}
|
|
@@ -4014,6 +4026,9 @@ __decorateClass([
|
|
|
4014
4026
|
__decorateClass([
|
|
4015
4027
|
t$3()
|
|
4016
4028
|
], ShipAidWidget.prototype, "intervalId");
|
|
4029
|
+
__decorateClass([
|
|
4030
|
+
t$3()
|
|
4031
|
+
], ShipAidWidget.prototype, "_sellingPlanId");
|
|
4017
4032
|
__decorateClass([
|
|
4018
4033
|
t$3()
|
|
4019
4034
|
], ShipAidWidget.prototype, "_state");
|