shopoflex-types 1.0.183 → 1.0.185
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/common.d.ts +14 -10
- package/dist/samples.d.ts +2 -17
- package/dist/samples.js +24 -5
- package/package.json +1 -1
package/dist/common.d.ts
CHANGED
|
@@ -356,7 +356,7 @@ export interface Vendor {
|
|
|
356
356
|
};
|
|
357
357
|
allowCustomPricing?: boolean;
|
|
358
358
|
pixelsOptions?: PixelsOptions;
|
|
359
|
-
taxManagement?:
|
|
359
|
+
taxManagement?: TaxConfig;
|
|
360
360
|
currentPlan?: {
|
|
361
361
|
planDiscount?: any;
|
|
362
362
|
planId?: IPlanPackage;
|
|
@@ -617,14 +617,18 @@ export interface successResponse {
|
|
|
617
617
|
}
|
|
618
618
|
export type Industry = "restaurant" | "grocery" | "retail" | "pharmacy" | "services";
|
|
619
619
|
export interface TaxConfig {
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
620
|
+
type: "fixed" | "perCountry";
|
|
621
|
+
fixed?: {
|
|
622
|
+
active: boolean;
|
|
623
|
+
show: boolean;
|
|
624
|
+
payer: "vendor" | "customer";
|
|
625
|
+
percentage: number;
|
|
626
|
+
};
|
|
627
|
+
perCountry?: Record<string, {
|
|
628
|
+
active: boolean;
|
|
629
|
+
show: boolean;
|
|
630
|
+
payer: "vendor" | "customer";
|
|
631
|
+
percentage: number;
|
|
632
|
+
}>;
|
|
629
633
|
}
|
|
630
634
|
export {};
|
package/dist/samples.d.ts
CHANGED
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
import { Address, Discount, IZone } from "./common";
|
|
1
|
+
import { Address, Discount, IZone, TaxConfig } from "./common";
|
|
2
2
|
import { CartItem } from "./productCart";
|
|
3
|
-
export
|
|
4
|
-
type: "fixed" | "perCountry";
|
|
5
|
-
fixed?: {
|
|
6
|
-
active: boolean;
|
|
7
|
-
show: boolean;
|
|
8
|
-
payer: "vendor" | "customer";
|
|
9
|
-
percentage: number;
|
|
10
|
-
};
|
|
11
|
-
perCountry?: Record<string, {
|
|
12
|
-
active: boolean;
|
|
13
|
-
show: boolean;
|
|
14
|
-
payer: "vendor" | "customer";
|
|
15
|
-
percentage: number;
|
|
16
|
-
}>;
|
|
17
|
-
}
|
|
18
|
-
export declare const calculateCartTotalsWithDiscounts: (items: CartItem[], deliveryFee: number, allDiscounts: Discount[], manualDiscount?: Discount, vendorTaxConfig?: SampleTaxConfig, customerAddress?: Address | any) => {
|
|
3
|
+
export declare const calculateCartTotalsWithDiscounts: (items: CartItem[], deliveryFee: number, allDiscounts: Discount[], manualDiscount?: Discount, vendorTaxConfig?: TaxConfig, customerAddress?: Address | any, deliveryFeeOverride?: number, discountOverride?: number) => {
|
|
19
4
|
items: CartItem[];
|
|
20
5
|
subtotal: number;
|
|
21
6
|
totalQuantity: number;
|
package/dist/samples.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculateDeliveryFeeForZones = exports.calculateCartTotalsWithDiscounts = void 0;
|
|
4
|
-
const calculateCartTotalsWithDiscounts = (items, deliveryFee, allDiscounts, manualDiscount, vendorTaxConfig, customerAddress) => {
|
|
4
|
+
const calculateCartTotalsWithDiscounts = (items, deliveryFee, allDiscounts, manualDiscount, vendorTaxConfig, customerAddress, deliveryFeeOverride, discountOverride) => {
|
|
5
5
|
// Calculate initial totals for each item
|
|
6
6
|
const itemsWithTotals = items.map((item) => {
|
|
7
7
|
const basePrice = item.selectedVariant?.priceModel?.price || 0;
|
|
@@ -18,14 +18,16 @@ const calculateCartTotalsWithDiscounts = (items, deliveryFee, allDiscounts, manu
|
|
|
18
18
|
});
|
|
19
19
|
const subtotal = itemsWithTotals.reduce((sum, item) => sum + (item.totalPrice ?? 0), 0);
|
|
20
20
|
const totalQuantity = itemsWithTotals.reduce((sum, item) => sum + item.quantity, 0);
|
|
21
|
+
// Use delivery fee override if provided, otherwise use normal delivery fee
|
|
22
|
+
const finalDeliveryFee = deliveryFeeOverride !== undefined ? deliveryFeeOverride : deliveryFee;
|
|
21
23
|
// Create base cart for discount calculations
|
|
22
24
|
const baseCart = {
|
|
23
25
|
items: itemsWithTotals,
|
|
24
26
|
subtotal,
|
|
25
27
|
totalQuantity,
|
|
26
|
-
delivery:
|
|
28
|
+
delivery: finalDeliveryFee,
|
|
27
29
|
discount: 0,
|
|
28
|
-
total: subtotal +
|
|
30
|
+
total: subtotal + finalDeliveryFee,
|
|
29
31
|
};
|
|
30
32
|
// Apply discounts and get updated cart
|
|
31
33
|
const applyDiscounts = (cart, allDiscounts, manualDiscount) => {
|
|
@@ -61,7 +63,6 @@ const calculateCartTotalsWithDiscounts = (items, deliveryFee, allDiscounts, manu
|
|
|
61
63
|
}, 0);
|
|
62
64
|
}
|
|
63
65
|
else if (discount.discountCategory === "product_discount") {
|
|
64
|
-
// Calculate total basePrice of applicable products (excludes modifiers)
|
|
65
66
|
applicableTotal = cart.items.reduce((total, item) => {
|
|
66
67
|
if (!item._id)
|
|
67
68
|
return total;
|
|
@@ -261,7 +262,25 @@ const calculateCartTotalsWithDiscounts = (items, deliveryFee, allDiscounts, manu
|
|
|
261
262
|
totalDiscount: cappedCartLevelDiscountAmount + deliveryDiscountAmount,
|
|
262
263
|
};
|
|
263
264
|
};
|
|
264
|
-
|
|
265
|
+
// Apply discount override if provided, otherwise calculate discounts normally
|
|
266
|
+
let updatedCart;
|
|
267
|
+
let totalDiscount;
|
|
268
|
+
if (discountOverride !== undefined) {
|
|
269
|
+
// Use discount override (percentage) - skip all discount calculations
|
|
270
|
+
const overrideDiscountAmount = (subtotal * discountOverride) / 100;
|
|
271
|
+
updatedCart = {
|
|
272
|
+
...baseCart,
|
|
273
|
+
discount: overrideDiscountAmount,
|
|
274
|
+
total: Math.max(0, subtotal - overrideDiscountAmount + finalDeliveryFee),
|
|
275
|
+
};
|
|
276
|
+
totalDiscount = overrideDiscountAmount;
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
// Apply normal discount calculations
|
|
280
|
+
const result = applyDiscounts(baseCart, allDiscounts, manualDiscount);
|
|
281
|
+
updatedCart = result.updatedCart;
|
|
282
|
+
totalDiscount = result.totalDiscount;
|
|
283
|
+
}
|
|
265
284
|
// Calculate vendor tax if configuration is provided
|
|
266
285
|
let taxInfo = {
|
|
267
286
|
taxAmount: 0,
|