shopoflex-types 1.0.185 → 1.0.186
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/samples.d.ts +12 -2
- package/dist/samples.js +46 -1
- package/package.json +1 -1
package/dist/samples.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Address, Discount, IZone, TaxConfig } from "./common";
|
|
2
|
-
import { CartItem } from "./productCart";
|
|
1
|
+
import { Address, Discount, FileType, IZone, TaxConfig } from "./common";
|
|
2
|
+
import { CartItem, ProductType, sModifier, VariantType } from "./productCart";
|
|
3
3
|
export declare const calculateCartTotalsWithDiscounts: (items: CartItem[], deliveryFee: number, allDiscounts: Discount[], manualDiscount?: Discount, vendorTaxConfig?: TaxConfig, customerAddress?: Address | any, deliveryFeeOverride?: number, discountOverride?: number) => {
|
|
4
4
|
items: CartItem[];
|
|
5
5
|
subtotal: number;
|
|
@@ -23,3 +23,13 @@ export declare const calculateDeliveryFeeForZones: (zones: IZone[], location: {
|
|
|
23
23
|
fee: number;
|
|
24
24
|
isValid: boolean;
|
|
25
25
|
}>;
|
|
26
|
+
export declare const getImageUrl: (imageId?: string, vendorId?: string, params?: string) => string;
|
|
27
|
+
export declare const getImageZero: (files?: FileType[], vendorId?: string, params?: string) => string;
|
|
28
|
+
export declare const getAvailableStock: (product: ProductType, branchId?: string, variant?: null) => number;
|
|
29
|
+
export declare const calculateModifiersTotal: (selectedModifiers?: sModifier[]) => number;
|
|
30
|
+
export declare const calculateItemPrices: (vartiant: VariantType, selectedModifiers?: sModifier[], quantity?: number) => {
|
|
31
|
+
unitPrice: number;
|
|
32
|
+
totalPrice: number;
|
|
33
|
+
basePrice: number;
|
|
34
|
+
modifiersPrice: number;
|
|
35
|
+
};
|
package/dist/samples.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateDeliveryFeeForZones = exports.calculateCartTotalsWithDiscounts = void 0;
|
|
3
|
+
exports.calculateItemPrices = exports.calculateModifiersTotal = exports.getAvailableStock = exports.getImageZero = exports.getImageUrl = exports.calculateDeliveryFeeForZones = exports.calculateCartTotalsWithDiscounts = void 0;
|
|
4
|
+
const defaultImage = "https://firebasestorage.googleapis.com/v0/b/navori-s.firebasestorage.app/o/picture.png?alt=media";
|
|
4
5
|
const calculateCartTotalsWithDiscounts = (items, deliveryFee, allDiscounts, manualDiscount, vendorTaxConfig, customerAddress, deliveryFeeOverride, discountOverride) => {
|
|
5
6
|
// Calculate initial totals for each item
|
|
6
7
|
const itemsWithTotals = items.map((item) => {
|
|
@@ -435,3 +436,47 @@ const calculateDeliveryFeeForZones = async (zones, location, mapkey) => {
|
|
|
435
436
|
return { fee: totalFee, isValid };
|
|
436
437
|
};
|
|
437
438
|
exports.calculateDeliveryFeeForZones = calculateDeliveryFeeForZones;
|
|
439
|
+
const getImageUrl = (imageId = '', vendorId = '', params = "w=400") => {
|
|
440
|
+
if (!vendorId || !imageId)
|
|
441
|
+
return defaultImage;
|
|
442
|
+
const baseurl = "https://shopoflex.imgix.net/files/";
|
|
443
|
+
return baseurl + vendorId + "/" + imageId + "?" + params;
|
|
444
|
+
};
|
|
445
|
+
exports.getImageUrl = getImageUrl;
|
|
446
|
+
const getImageZero = (files = [], vendorId = '', params = "w=400") => {
|
|
447
|
+
if (files && files.length > 0) {
|
|
448
|
+
return (0, exports.getImageUrl)(files[0]?.name, vendorId, params);
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
return defaultImage;
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
exports.getImageZero = getImageZero;
|
|
455
|
+
const getAvailableStock = (product, branchId, variant = null) => {
|
|
456
|
+
const v = variant || product.variants[0];
|
|
457
|
+
if (!v.stockHandle?.active || !branchId) {
|
|
458
|
+
return Infinity;
|
|
459
|
+
}
|
|
460
|
+
const branchStock = v.stockHandle.stockByBranch[branchId];
|
|
461
|
+
return branchStock?.stockQuantity || 0;
|
|
462
|
+
};
|
|
463
|
+
exports.getAvailableStock = getAvailableStock;
|
|
464
|
+
const calculateModifiersTotal = (selectedModifiers = []) => {
|
|
465
|
+
return selectedModifiers.reduce((total, modifier) => {
|
|
466
|
+
const modifierTotal = modifier.options?.reduce((optionSum, option) => {
|
|
467
|
+
const price = option.price || 0;
|
|
468
|
+
const quantity = option.quantity || 0;
|
|
469
|
+
return optionSum + (price * quantity);
|
|
470
|
+
}, 0) || 0;
|
|
471
|
+
return total + modifierTotal;
|
|
472
|
+
}, 0);
|
|
473
|
+
};
|
|
474
|
+
exports.calculateModifiersTotal = calculateModifiersTotal;
|
|
475
|
+
const calculateItemPrices = (vartiant, selectedModifiers = [], quantity = 1) => {
|
|
476
|
+
const basePrice = vartiant.priceModel.price || 0;
|
|
477
|
+
const modifiersPrice = (0, exports.calculateModifiersTotal)(selectedModifiers || []);
|
|
478
|
+
const unitPrice = basePrice + modifiersPrice;
|
|
479
|
+
const totalPrice = unitPrice * quantity;
|
|
480
|
+
return { unitPrice, totalPrice, basePrice, modifiersPrice };
|
|
481
|
+
};
|
|
482
|
+
exports.calculateItemPrices = calculateItemPrices;
|