@ikas/storefront-model-functions 4.0.0-alpha.10
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/package.json +39 -0
- package/src/functions/blog/category/index.ts +6 -0
- package/src/functions/blog/index.ts +6 -0
- package/src/functions/brand/index.ts +6 -0
- package/src/functions/category/index.ts +6 -0
- package/src/functions/category/path-item/index.ts +15 -0
- package/src/functions/checkout/index.ts +35 -0
- package/src/functions/customer/address/index.ts +90 -0
- package/src/functions/customer/attribute/index.ts +18 -0
- package/src/functions/customer/index.ts +23 -0
- package/src/functions/filter-category/index.ts +6 -0
- package/src/functions/image/index.ts +27 -0
- package/src/functions/order/address/index.ts +110 -0
- package/src/functions/order/index.ts +92 -0
- package/src/functions/order/line-item/index.ts +30 -0
- package/src/functions/order/line-item/variant/index.ts +15 -0
- package/src/functions/order/line-item/variant/value/index.ts +18 -0
- package/src/functions/payment-gateway/index.ts +44 -0
- package/src/functions/product/attribute-value/index.ts +5 -0
- package/src/functions/product/filter/index.ts +197 -0
- package/src/functions/product/index.ts +145 -0
- package/src/functions/product/option-set/index.ts +19 -0
- package/src/functions/product/option-set/option/index.ts +189 -0
- package/src/functions/product/variant/index.ts +9 -0
- package/src/functions/product/variant/price/index.ts +20 -0
- package/src/functions/raffle/index.ts +14 -0
- package/src/functions/variant-type/index.ts +13 -0
- package/src/functions/variant-type/variant-value/index.ts +13 -0
- package/src/index.ts +107 -0
- package/src/utils/helper.ts +59 -0
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ikas/storefront-model-functions",
|
|
3
|
+
"version": "4.0.0-alpha.10",
|
|
4
|
+
"description": "Functions for ikas storefront models.",
|
|
5
|
+
"author": "Umut Ozan Yıldırım",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"main": "./src/index.ts",
|
|
8
|
+
"module": "./src/index.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"./src"
|
|
11
|
+
],
|
|
12
|
+
"type": "module",
|
|
13
|
+
"scripts": {
|
|
14
|
+
"pack": "npm pack",
|
|
15
|
+
"release": "npm publish",
|
|
16
|
+
"build": "rm -rf build && rollup -c"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@ikas/storefront-config": "^4.0.0-alpha.10",
|
|
20
|
+
"@ikas/storefront-models": "^4.0.0-alpha.10",
|
|
21
|
+
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
22
|
+
"@rollup/plugin-commonjs": "^22.0.0",
|
|
23
|
+
"@types/lodash": "^4.14.182",
|
|
24
|
+
"prettier": "^2.2.1",
|
|
25
|
+
"rollup": "^2.75.6",
|
|
26
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
27
|
+
"rollup-plugin-typescript2": "^0.32.1",
|
|
28
|
+
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
29
|
+
"typescript": "^4.7.2",
|
|
30
|
+
"ttypescript": "^1.5.12",
|
|
31
|
+
"typescript-transform-paths": "^2.2.2",
|
|
32
|
+
"lodash": "^4.17.21"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@ikas/storefront-config": "^4.0.0-alpha.10",
|
|
36
|
+
"@ikas/storefront-models": "^4.0.0-alpha.10",
|
|
37
|
+
"lodash": "^4.17.21"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IkasCategoryPathItem } from "@ikas/storefront-models";
|
|
2
|
+
|
|
3
|
+
export function getIkasCategoryPathItemSlug(
|
|
4
|
+
categoryPathItem: IkasCategoryPathItem
|
|
5
|
+
) {
|
|
6
|
+
return categoryPathItem.metaData?.slug;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function getIkasCategoryPathItemHref(
|
|
10
|
+
categoryPathItem: IkasCategoryPathItem
|
|
11
|
+
) {
|
|
12
|
+
const slug = getIkasCategoryPathItemSlug(categoryPathItem);
|
|
13
|
+
if (!slug) return "";
|
|
14
|
+
return `/${slug}`;
|
|
15
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IkasCheckout,
|
|
3
|
+
IkasPaymentGateway,
|
|
4
|
+
IkasPaymentGatewayAdditionalPriceType,
|
|
5
|
+
} from "@ikas/storefront-models";
|
|
6
|
+
import { getCalculatedAdditionalPrices } from "../payment-gateway";
|
|
7
|
+
|
|
8
|
+
export function isComplete(checkout: IkasCheckout) {
|
|
9
|
+
return !!checkout.orderNumber;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getTotalFinalPrice(
|
|
13
|
+
checkout: IkasCheckout,
|
|
14
|
+
selectedPaymentGateway: IkasPaymentGateway
|
|
15
|
+
) {
|
|
16
|
+
const calculatedAdditionalPrices = selectedPaymentGateway
|
|
17
|
+
? getCalculatedAdditionalPrices(
|
|
18
|
+
selectedPaymentGateway,
|
|
19
|
+
checkout.totalFinalPrice || 0,
|
|
20
|
+
checkout.shippingLines || null
|
|
21
|
+
)
|
|
22
|
+
: undefined;
|
|
23
|
+
|
|
24
|
+
let total = checkout.totalFinalPrice || 0;
|
|
25
|
+
|
|
26
|
+
calculatedAdditionalPrices?.forEach((additionalPrice) => {
|
|
27
|
+
if (
|
|
28
|
+
additionalPrice.type === IkasPaymentGatewayAdditionalPriceType.DECREMENT
|
|
29
|
+
)
|
|
30
|
+
total -= additionalPrice.amount;
|
|
31
|
+
else total += additionalPrice.amount;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return total;
|
|
35
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IkasCheckoutRequirement,
|
|
3
|
+
IkasCheckoutSettings,
|
|
4
|
+
IkasCustomerAddress,
|
|
5
|
+
} from "@ikas/storefront-models";
|
|
6
|
+
import { validatePhoneNumber } from "../../../utils/helper";
|
|
7
|
+
|
|
8
|
+
export function getAddressText(address: IkasCustomerAddress) {
|
|
9
|
+
const strings: string[] = [];
|
|
10
|
+
|
|
11
|
+
if (address.addressLine1) strings.push(address.addressLine1);
|
|
12
|
+
if (address.addressLine2) strings.push(address.addressLine2);
|
|
13
|
+
if (address.postalCode) strings.push(address.postalCode);
|
|
14
|
+
if (address.district && address.district.name)
|
|
15
|
+
strings.push(address.district.name);
|
|
16
|
+
if (address.city && address.city.name) strings.push(address.city.name);
|
|
17
|
+
if (address.state && address.state.name && address.state.name !== "Default")
|
|
18
|
+
strings.push(address.state.name);
|
|
19
|
+
if (address.country && address.country.name)
|
|
20
|
+
strings.push(address.country.name);
|
|
21
|
+
|
|
22
|
+
return strings.join(", ");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function getValidationResult(
|
|
26
|
+
address: IkasCustomerAddress,
|
|
27
|
+
checkoutSettings: IkasCheckoutSettings,
|
|
28
|
+
isDistrictRequired: boolean
|
|
29
|
+
): IkasCustomerAddressValidationResult {
|
|
30
|
+
const isValidPhone =
|
|
31
|
+
!!address.phone &&
|
|
32
|
+
address.phone.length >= 10 &&
|
|
33
|
+
validatePhoneNumber(address.phone);
|
|
34
|
+
|
|
35
|
+
const results = {
|
|
36
|
+
firstName: !!address.firstName,
|
|
37
|
+
lastName: !!address.lastName,
|
|
38
|
+
addressLine1: !!address.addressLine1,
|
|
39
|
+
country: !!address.country?.name,
|
|
40
|
+
state: !!address.state,
|
|
41
|
+
city: !!address.city?.name,
|
|
42
|
+
district: isDistrictRequired ? !!address.district?.id : true,
|
|
43
|
+
phone:
|
|
44
|
+
checkoutSettings.phoneRequirement === IkasCheckoutRequirement.MANDATORY ||
|
|
45
|
+
(checkoutSettings.phoneRequirement === IkasCheckoutRequirement.OPTIONAL &&
|
|
46
|
+
address.phone)
|
|
47
|
+
? isValidPhone
|
|
48
|
+
: true,
|
|
49
|
+
postalCode:
|
|
50
|
+
checkoutSettings.postalCodeRequirement ===
|
|
51
|
+
IkasCheckoutRequirement.MANDATORY
|
|
52
|
+
? !!address.postalCode
|
|
53
|
+
: true,
|
|
54
|
+
identityNumber:
|
|
55
|
+
checkoutSettings.identityNumberRequirement ===
|
|
56
|
+
IkasCheckoutRequirement.MANDATORY
|
|
57
|
+
? !!address.identityNumber
|
|
58
|
+
: true,
|
|
59
|
+
title: !!address.title,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return results;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function isValidAddress(
|
|
66
|
+
address: IkasCustomerAddress,
|
|
67
|
+
checkoutSettings: IkasCheckoutSettings,
|
|
68
|
+
isDistrictRequired: boolean
|
|
69
|
+
) {
|
|
70
|
+
const validationResult = getValidationResult(
|
|
71
|
+
address,
|
|
72
|
+
checkoutSettings,
|
|
73
|
+
isDistrictRequired
|
|
74
|
+
);
|
|
75
|
+
return Object.values(validationResult).every((result) => result);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type IkasCustomerAddressValidationResult = {
|
|
79
|
+
firstName: boolean;
|
|
80
|
+
lastName: boolean;
|
|
81
|
+
addressLine1: boolean;
|
|
82
|
+
country: boolean;
|
|
83
|
+
state: boolean;
|
|
84
|
+
city: boolean;
|
|
85
|
+
district: boolean;
|
|
86
|
+
phone: boolean;
|
|
87
|
+
postalCode: boolean;
|
|
88
|
+
identityNumber: boolean;
|
|
89
|
+
title: boolean;
|
|
90
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IkasStorefrontConfig } from "@ikas/storefront-config";
|
|
2
|
+
import { IkasCustomerAttribute } from "@ikas/storefront-models";
|
|
3
|
+
|
|
4
|
+
export function getAccountPagePermission(attribute: IkasCustomerAttribute) {
|
|
5
|
+
const salesChannelId = IkasStorefrontConfig.getSalesChannelId();
|
|
6
|
+
|
|
7
|
+
return attribute.salesChannels?.find(
|
|
8
|
+
(sc) => sc.salesChannelId === salesChannelId
|
|
9
|
+
)?.permission;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getRegisterPageRequirement(attribute: IkasCustomerAttribute) {
|
|
13
|
+
const salesChannelId = IkasStorefrontConfig.getSalesChannelId();
|
|
14
|
+
|
|
15
|
+
return attribute.salesChannels?.find(
|
|
16
|
+
(sc) => sc.salesChannelId === salesChannelId
|
|
17
|
+
)?.registerPageRequirement;
|
|
18
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IkasCustomer,
|
|
3
|
+
IkasCustomerEmailSubscriptionStatus,
|
|
4
|
+
} from "@ikas/storefront-models";
|
|
5
|
+
|
|
6
|
+
export function isSubscribed(customer: IkasCustomer) {
|
|
7
|
+
return (
|
|
8
|
+
customer.subscriptionStatus ===
|
|
9
|
+
IkasCustomerEmailSubscriptionStatus.SUBSCRIBED ||
|
|
10
|
+
customer.subscriptionStatus ===
|
|
11
|
+
IkasCustomerEmailSubscriptionStatus.PENDING_CONFIRMATION
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getBasicInfo(customer: IkasCustomer) {
|
|
16
|
+
return {
|
|
17
|
+
id: customer.id,
|
|
18
|
+
firstName: customer.firstName,
|
|
19
|
+
lastName: customer.lastName,
|
|
20
|
+
email: customer.email,
|
|
21
|
+
phone: customer.phone,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { IkasStorefrontConfig } from "@ikas/storefront-config";
|
|
2
|
+
import { IkasImage } from "@ikas/storefront-models";
|
|
3
|
+
|
|
4
|
+
export function getDefaultSrc(image: IkasImage) {
|
|
5
|
+
return getSrc(image, 1080);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getThumbnailSrc(image: IkasImage) {
|
|
9
|
+
return getSrc(image, 180);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getSrc(image: IkasImage, size: number) {
|
|
13
|
+
const cdnUrl = IkasStorefrontConfig.getCdnUrl();
|
|
14
|
+
if (image.id.includes("/")) {
|
|
15
|
+
if (image.isVideo) {
|
|
16
|
+
return `${cdnUrl}videos/${image.id}/original.mp4`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return `${cdnUrl}images/${image.id}/image_${size}.webp`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const merchantId = IkasStorefrontConfig.getMerchantSettings()?.merchantId;
|
|
23
|
+
|
|
24
|
+
if (image.isVideo)
|
|
25
|
+
return `${cdnUrl}videos/${merchantId}/${image.id}/original.mp4`;
|
|
26
|
+
return `${cdnUrl}images/${merchantId}/${image.id}/image_${size}.webp`;
|
|
27
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IkasCheckoutRequirement,
|
|
3
|
+
IkasCheckoutSettings,
|
|
4
|
+
IkasOrderAddress,
|
|
5
|
+
} from "@ikas/storefront-models";
|
|
6
|
+
import { validatePhoneNumber } from "../../../utils/helper";
|
|
7
|
+
|
|
8
|
+
export function createOrderAddress(): IkasOrderAddress {
|
|
9
|
+
return {
|
|
10
|
+
addressLine1: "",
|
|
11
|
+
addressLine2: null,
|
|
12
|
+
company: null,
|
|
13
|
+
firstName: "",
|
|
14
|
+
id: null,
|
|
15
|
+
identityNumber: null,
|
|
16
|
+
isDefault: false,
|
|
17
|
+
lastName: "",
|
|
18
|
+
phone: null,
|
|
19
|
+
postalCode: null,
|
|
20
|
+
taxNumber: null,
|
|
21
|
+
taxOffice: null,
|
|
22
|
+
|
|
23
|
+
country: null,
|
|
24
|
+
state: null,
|
|
25
|
+
city: null,
|
|
26
|
+
district: null,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function getAddressText(address: IkasOrderAddress) {
|
|
31
|
+
const strings: string[] = [];
|
|
32
|
+
|
|
33
|
+
if (address.addressLine1) strings.push(address.addressLine1);
|
|
34
|
+
if (address.addressLine2) strings.push(address.addressLine2);
|
|
35
|
+
if (address.postalCode) strings.push(address.postalCode);
|
|
36
|
+
if (address.district && address.district.name)
|
|
37
|
+
strings.push(address.district.name);
|
|
38
|
+
if (address.city && address.city.name) strings.push(address.city.name);
|
|
39
|
+
if (address.state && address.state.name && address.state.name !== "Default")
|
|
40
|
+
strings.push(address.state.name);
|
|
41
|
+
if (address.country && address.country.name)
|
|
42
|
+
strings.push(address.country.name);
|
|
43
|
+
|
|
44
|
+
return strings.join(", ");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function getValidationResult(
|
|
48
|
+
address: IkasOrderAddress,
|
|
49
|
+
checkoutSettings: IkasCheckoutSettings,
|
|
50
|
+
isDistrictRequired: boolean
|
|
51
|
+
): IkasOrderAddressValidationResult {
|
|
52
|
+
const isValidPhone =
|
|
53
|
+
!!address.phone &&
|
|
54
|
+
address.phone.length >= 10 &&
|
|
55
|
+
validatePhoneNumber(address.phone);
|
|
56
|
+
|
|
57
|
+
const results = {
|
|
58
|
+
firstName: !!address.firstName,
|
|
59
|
+
lastName: !!address.lastName,
|
|
60
|
+
addressLine1: !!address.addressLine1,
|
|
61
|
+
country: !!address.country?.name,
|
|
62
|
+
state: !!address.state,
|
|
63
|
+
city: !!address.city?.name,
|
|
64
|
+
district: isDistrictRequired ? !!address.district?.id : true,
|
|
65
|
+
phone:
|
|
66
|
+
checkoutSettings.phoneRequirement === IkasCheckoutRequirement.MANDATORY ||
|
|
67
|
+
(checkoutSettings.phoneRequirement === IkasCheckoutRequirement.OPTIONAL &&
|
|
68
|
+
address.phone)
|
|
69
|
+
? isValidPhone
|
|
70
|
+
: true,
|
|
71
|
+
postalCode:
|
|
72
|
+
checkoutSettings.postalCodeRequirement ===
|
|
73
|
+
IkasCheckoutRequirement.MANDATORY
|
|
74
|
+
? !!address.postalCode
|
|
75
|
+
: true,
|
|
76
|
+
identityNumber:
|
|
77
|
+
checkoutSettings.identityNumberRequirement ===
|
|
78
|
+
IkasCheckoutRequirement.MANDATORY
|
|
79
|
+
? !!address.identityNumber
|
|
80
|
+
: true,
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
return results;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function isValidAddress(
|
|
87
|
+
address: IkasOrderAddress,
|
|
88
|
+
checkoutSettings: IkasCheckoutSettings,
|
|
89
|
+
isDistrictRequired: boolean
|
|
90
|
+
) {
|
|
91
|
+
const validationResult = getValidationResult(
|
|
92
|
+
address,
|
|
93
|
+
checkoutSettings,
|
|
94
|
+
isDistrictRequired
|
|
95
|
+
);
|
|
96
|
+
return Object.values(validationResult).every((result) => result);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export type IkasOrderAddressValidationResult = {
|
|
100
|
+
firstName: boolean;
|
|
101
|
+
lastName: boolean;
|
|
102
|
+
addressLine1: boolean;
|
|
103
|
+
country: boolean;
|
|
104
|
+
state: boolean;
|
|
105
|
+
city: boolean;
|
|
106
|
+
district: boolean;
|
|
107
|
+
phone: boolean;
|
|
108
|
+
postalCode: boolean;
|
|
109
|
+
identityNumber: boolean;
|
|
110
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IkasOrder,
|
|
3
|
+
IkasOrderLineItem,
|
|
4
|
+
IkasOrderLineItemStatus,
|
|
5
|
+
IkasOrderRefundSettings,
|
|
6
|
+
} from "@ikas/storefront-models";
|
|
7
|
+
import { formatDate, validateEmail } from "../../utils/helper";
|
|
8
|
+
|
|
9
|
+
export function getRefundableItems(
|
|
10
|
+
order: IkasOrder,
|
|
11
|
+
refundSettings: IkasOrderRefundSettings
|
|
12
|
+
) {
|
|
13
|
+
if (refundSettings && !refundSettings.isActiveRefundSection) return [];
|
|
14
|
+
|
|
15
|
+
return order.orderLineItems.filter(
|
|
16
|
+
(item) =>
|
|
17
|
+
[
|
|
18
|
+
IkasOrderLineItemStatus.FULFILLED,
|
|
19
|
+
IkasOrderLineItemStatus.UNFULFILLED,
|
|
20
|
+
IkasOrderLineItemStatus.DELIVERED,
|
|
21
|
+
].includes(item.status) &&
|
|
22
|
+
(refundSettings.orderRefundDayLimit
|
|
23
|
+
? refundSettings.orderRefundDayLimit >= getItemOrderedAtDays(item)
|
|
24
|
+
: true)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getUnfullfilledItems(order: IkasOrder) {
|
|
29
|
+
return order.orderLineItems.filter((item) => {
|
|
30
|
+
const isInAPackage = order.orderPackages?.some((op) =>
|
|
31
|
+
op.orderLineItemIds.includes(item.id)
|
|
32
|
+
);
|
|
33
|
+
return !isInAPackage;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getRefundedItems(order: IkasOrder) {
|
|
38
|
+
return order.orderLineItems.filter(
|
|
39
|
+
(item) =>
|
|
40
|
+
item.status === IkasOrderLineItemStatus.REFUNDED ||
|
|
41
|
+
item.status === IkasOrderLineItemStatus.REFUND_REQUESTED ||
|
|
42
|
+
item.status === IkasOrderLineItemStatus.REFUND_REQUEST_ACCEPTED ||
|
|
43
|
+
item.status === IkasOrderLineItemStatus.REFUND_REJECTED
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function getTotalTax(order: IkasOrder) {
|
|
48
|
+
return (
|
|
49
|
+
order.taxLines?.reduce((total, current) => total + current.price, 0) || 0
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function getShippingTotal(order: IkasOrder) {
|
|
54
|
+
return (
|
|
55
|
+
order.shippingLines?.reduce((total, current) => total + current.price, 0) ||
|
|
56
|
+
0
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function hasCustomer(order: IkasOrder) {
|
|
61
|
+
return !!order.customer?.id;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function hasValidCustomerEmail(order: IkasOrder) {
|
|
65
|
+
return !!order.customer?.email && validateEmail(order.customer.email);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function getCustomerFullName(order: IkasOrder) {
|
|
69
|
+
return `${order.customer?.firstName || ""} ${order.customer?.lastName || ""}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function getFormattedDate(order: IkasOrder) {
|
|
73
|
+
const newDate = new Date();
|
|
74
|
+
newDate.setTime(order.updatedAt);
|
|
75
|
+
return formatDate(newDate);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function getCouponAdjustment(order: IkasOrder) {
|
|
79
|
+
return order.orderAdjustments?.find((a) => !!a.couponId);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function getNonCouponAdjustments(order: IkasOrder) {
|
|
83
|
+
return order.orderAdjustments?.filter((a) => !a.couponId);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function getItemOrderedAtDays(item: IkasOrderLineItem) {
|
|
87
|
+
const orderedAt = item.orderedAt;
|
|
88
|
+
const now = Date.now();
|
|
89
|
+
const diffTime = Math.abs(now - orderedAt);
|
|
90
|
+
|
|
91
|
+
return diffTime / (1000 * 60 * 60 * 24);
|
|
92
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IkasOrderLineItem } from "@ikas/storefront-models";
|
|
2
|
+
|
|
3
|
+
export function getPriceWithQuantity(item: IkasOrderLineItem) {
|
|
4
|
+
return item.price * item.quantity;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function getOverridenPriceWithQuantity(item: IkasOrderLineItem) {
|
|
8
|
+
const price =
|
|
9
|
+
item.discountPrice !== undefined && item.discountPrice !== null
|
|
10
|
+
? item.price * item.quantity
|
|
11
|
+
: null;
|
|
12
|
+
|
|
13
|
+
return price !== null && price < 0 ? 0 : price;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getFinalPriceWithQuantity(item: IkasOrderLineItem) {
|
|
17
|
+
const price =
|
|
18
|
+
(item.discountPrice !== undefined && item.discountPrice !== null
|
|
19
|
+
? item.discountPrice
|
|
20
|
+
: item.price) * item.quantity;
|
|
21
|
+
|
|
22
|
+
return price < 0 ? 0 : price;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function getTax(item: IkasOrderLineItem) {
|
|
26
|
+
const taxValue = item.taxValue || 0;
|
|
27
|
+
return (
|
|
28
|
+
(((item.finalPrice || 0) * item.quantity) / (100 + taxValue)) * taxValue
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IkasOrderLineVariant } from "@ikas/storefront-models";
|
|
2
|
+
import { getIkasVariantNameSlug, getIkasVariantTypeSlug } from "./value";
|
|
3
|
+
|
|
4
|
+
export function getIkasOrderLineVariantHref(variant: IkasOrderLineVariant) {
|
|
5
|
+
if (!variant.slug) return;
|
|
6
|
+
|
|
7
|
+
const variantParams = variant.variantValues
|
|
8
|
+
?.map((vv) => {
|
|
9
|
+
return `${getIkasVariantTypeSlug(vv)}=${getIkasVariantNameSlug(vv)}`;
|
|
10
|
+
})
|
|
11
|
+
.join("&");
|
|
12
|
+
|
|
13
|
+
if (variantParams) return `/${variant.slug}?${variantParams}`;
|
|
14
|
+
else return `/${variant.slug}`;
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IkasOrderLineVariantVariantValue } from "@ikas/storefront-models";
|
|
2
|
+
import { stringToSlug } from "../../../../../utils/helper";
|
|
3
|
+
|
|
4
|
+
export function getIkasVariantTypeSlug(
|
|
5
|
+
variantValue: IkasOrderLineVariantVariantValue
|
|
6
|
+
) {
|
|
7
|
+
return variantValue.variantTypeName
|
|
8
|
+
? stringToSlug(variantValue.variantTypeName)
|
|
9
|
+
: "";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getIkasVariantNameSlug(
|
|
13
|
+
variantValue: IkasOrderLineVariantVariantValue
|
|
14
|
+
) {
|
|
15
|
+
return variantValue.variantValueName
|
|
16
|
+
? stringToSlug(variantValue.variantValueName)
|
|
17
|
+
: "";
|
|
18
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IkasOrderShippingLine,
|
|
3
|
+
IkasPaymentGateway,
|
|
4
|
+
IkasPaymentGatewayAdditionalPriceType,
|
|
5
|
+
IkasPaymentGatewayTransactionFeeType,
|
|
6
|
+
} from "@ikas/storefront-models";
|
|
7
|
+
|
|
8
|
+
export function getCalculatedAdditionalPrices(
|
|
9
|
+
paymentGateway: IkasPaymentGateway,
|
|
10
|
+
totalFinalPrice: number,
|
|
11
|
+
shippingLines: IkasOrderShippingLine[] | null
|
|
12
|
+
) {
|
|
13
|
+
if (paymentGateway.additionalPrices) {
|
|
14
|
+
const shippingPrice =
|
|
15
|
+
shippingLines?.reduce((sum, item) => sum + item.price, 0) || 0;
|
|
16
|
+
|
|
17
|
+
totalFinalPrice -= shippingPrice;
|
|
18
|
+
|
|
19
|
+
return paymentGateway.additionalPrices.map((additionalPrice) => {
|
|
20
|
+
let amount = 0;
|
|
21
|
+
|
|
22
|
+
if (
|
|
23
|
+
additionalPrice.amountType ===
|
|
24
|
+
IkasPaymentGatewayTransactionFeeType.RATIO
|
|
25
|
+
) {
|
|
26
|
+
amount = ((totalFinalPrice || 0) * additionalPrice.amount) / 100;
|
|
27
|
+
} else {
|
|
28
|
+
amount = additionalPrice.amount;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (
|
|
32
|
+
additionalPrice.type === IkasPaymentGatewayAdditionalPriceType.DECREMENT
|
|
33
|
+
)
|
|
34
|
+
totalFinalPrice -= amount;
|
|
35
|
+
else totalFinalPrice += amount;
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
name: additionalPrice.name || paymentGateway.name,
|
|
39
|
+
amount: amount,
|
|
40
|
+
type: additionalPrice.type,
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|