b23-lib 1.6.2 → 1.7.1
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/Auth/index.cjs +2 -0
- package/dist/Auth/index.cjs.map +1 -0
- package/dist/Auth/index.d.cts +130 -0
- package/dist/Auth/index.d.ts +130 -0
- package/dist/Auth/index.js +2 -0
- package/dist/Auth/index.js.map +1 -0
- package/dist/Classes/Address.cjs +2 -0
- package/dist/Classes/Address.cjs.map +1 -0
- package/dist/Classes/Address.d.cts +142 -0
- package/dist/Classes/Address.d.ts +142 -0
- package/dist/Classes/Address.js +2 -0
- package/dist/Classes/Address.js.map +1 -0
- package/dist/Classes/Base.cjs +2 -0
- package/dist/Classes/Base.cjs.map +1 -0
- package/dist/Classes/Base.d.cts +98 -0
- package/dist/Classes/Base.d.ts +98 -0
- package/dist/Classes/Base.js +2 -0
- package/dist/Classes/Base.js.map +1 -0
- package/dist/Classes/Cart.cjs +2 -0
- package/dist/Classes/Cart.cjs.map +1 -0
- package/dist/Classes/Cart.d.cts +68 -0
- package/dist/Classes/Cart.d.ts +68 -0
- package/dist/Classes/Cart.js +2 -0
- package/dist/Classes/Cart.js.map +1 -0
- package/dist/Classes/Common.cjs +2 -0
- package/dist/Classes/Common.cjs.map +1 -0
- package/dist/Classes/Common.d.cts +75 -0
- package/dist/Classes/Common.d.ts +75 -0
- package/dist/Classes/Common.js +2 -0
- package/dist/Classes/Common.js.map +1 -0
- package/dist/Classes/Coupon.cjs +2 -0
- package/dist/Classes/Coupon.cjs.map +1 -0
- package/dist/Classes/Coupon.d.cts +142 -0
- package/dist/Classes/Coupon.d.ts +142 -0
- package/dist/Classes/Coupon.js +2 -0
- package/dist/Classes/Coupon.js.map +1 -0
- package/dist/Classes/Customer.cjs +2 -0
- package/dist/Classes/Customer.cjs.map +1 -0
- package/dist/Classes/Customer.d.cts +97 -0
- package/dist/Classes/Customer.d.ts +97 -0
- package/dist/Classes/Customer.js +2 -0
- package/dist/Classes/Customer.js.map +1 -0
- package/dist/Classes/CustomerAddress.cjs +2 -0
- package/dist/Classes/CustomerAddress.cjs.map +1 -0
- package/dist/Classes/CustomerAddress.d.cts +71 -0
- package/dist/Classes/CustomerAddress.d.ts +71 -0
- package/dist/Classes/CustomerAddress.js +2 -0
- package/dist/Classes/CustomerAddress.js.map +1 -0
- package/dist/Classes/Enum.cjs +2 -0
- package/dist/Classes/Enum.cjs.map +1 -0
- package/dist/Classes/Enum.d.cts +34 -0
- package/dist/Classes/Enum.d.ts +34 -0
- package/dist/Classes/Enum.js +2 -0
- package/dist/Classes/Enum.js.map +1 -0
- package/dist/Classes/ImageInfo.cjs +2 -0
- package/dist/Classes/ImageInfo.cjs.map +1 -0
- package/dist/Classes/ImageInfo.d.cts +92 -0
- package/dist/Classes/ImageInfo.d.ts +92 -0
- package/dist/Classes/ImageInfo.js +2 -0
- package/dist/Classes/ImageInfo.js.map +1 -0
- package/dist/Classes/LineItem.cjs +2 -0
- package/dist/Classes/LineItem.cjs.map +1 -0
- package/dist/Classes/LineItem.d.cts +124 -0
- package/dist/Classes/LineItem.d.ts +124 -0
- package/dist/Classes/LineItem.js +2 -0
- package/dist/Classes/LineItem.js.map +1 -0
- package/dist/Classes/Order.cjs +2 -0
- package/dist/Classes/Order.cjs.map +1 -0
- package/dist/Classes/Order.d.cts +83 -0
- package/dist/Classes/Order.d.ts +83 -0
- package/dist/Classes/Order.js +2 -0
- package/dist/Classes/Order.js.map +1 -0
- package/dist/Classes/Payment.cjs +2 -0
- package/dist/Classes/Payment.cjs.map +1 -0
- package/dist/Classes/Payment.d.cts +161 -0
- package/dist/Classes/Payment.d.ts +161 -0
- package/dist/Classes/Payment.js +2 -0
- package/dist/Classes/Payment.js.map +1 -0
- package/dist/Classes/Price.cjs +2 -0
- package/dist/Classes/Price.cjs.map +1 -0
- package/dist/Classes/Price.d.cts +70 -0
- package/dist/Classes/Price.d.ts +70 -0
- package/dist/Classes/Price.js +2 -0
- package/dist/Classes/Price.js.map +1 -0
- package/dist/Classes/Product.cjs +2 -0
- package/dist/Classes/Product.cjs.map +1 -0
- package/dist/Classes/Product.d.cts +209 -0
- package/dist/Classes/Product.d.ts +209 -0
- package/dist/Classes/Product.js +2 -0
- package/dist/Classes/Product.js.map +1 -0
- package/dist/Classes/ShoppingContainer.cjs +2 -0
- package/dist/Classes/ShoppingContainer.cjs.map +1 -0
- package/dist/Classes/ShoppingContainer.d.cts +194 -0
- package/dist/Classes/ShoppingContainer.d.ts +194 -0
- package/dist/Classes/ShoppingContainer.js +2 -0
- package/dist/Classes/ShoppingContainer.js.map +1 -0
- package/dist/Dynamodb/index.cjs +2 -0
- package/dist/Dynamodb/index.cjs.map +1 -0
- package/dist/Dynamodb/index.d.cts +58 -0
- package/dist/Dynamodb/index.d.ts +58 -0
- package/dist/Dynamodb/index.js +2 -0
- package/dist/Dynamodb/index.js.map +1 -0
- package/dist/chunk-2ESSIPYR.js +2 -0
- package/dist/chunk-2ESSIPYR.js.map +1 -0
- package/dist/chunk-2IVRLXCO.js +2 -0
- package/dist/chunk-2IVRLXCO.js.map +1 -0
- package/dist/chunk-42S4IPCA.js +2 -0
- package/dist/chunk-42S4IPCA.js.map +1 -0
- package/dist/chunk-7UEGCYYY.js +2 -0
- package/dist/chunk-7UEGCYYY.js.map +1 -0
- package/dist/chunk-IYDPJQAK.js +2 -0
- package/dist/chunk-IYDPJQAK.js.map +1 -0
- package/dist/chunk-P5BGQ3PJ.js +2 -0
- package/dist/chunk-P5BGQ3PJ.js.map +1 -0
- package/dist/chunk-PD6TDU7F.js +2 -0
- package/dist/chunk-PD6TDU7F.js.map +1 -0
- package/dist/chunk-Q2WQECY6.js +2 -0
- package/dist/chunk-Q2WQECY6.js.map +1 -0
- package/dist/chunk-XL3K64E6.js +2 -0
- package/dist/chunk-XL3K64E6.js.map +1 -0
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +240 -0
- package/dist/index.d.ts +1 -186
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +164 -1
- package/dist/index.d.mts +0 -425
- package/dist/index.mjs +0 -2
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import AddressModel, { AddressData } from './Address.cjs';
|
|
2
|
+
import BaseModel, { BaseAttributes } from './Base.cjs';
|
|
3
|
+
import './Common.cjs';
|
|
4
|
+
import './Enum.cjs';
|
|
5
|
+
|
|
6
|
+
type CustomerAddressAttributes = BaseAttributes & {
|
|
7
|
+
id: string;
|
|
8
|
+
addresses: AddressData[];
|
|
9
|
+
defaultBillingAddressId: string;
|
|
10
|
+
defaultShippingAddressId: string;
|
|
11
|
+
};
|
|
12
|
+
type CustomerAddressWithoutDefaultAddress = Omit<CustomerAddressAttributes, 'addresses' | 'defaultBillingAddressId' | 'defaultShippingAddressId'> & {
|
|
13
|
+
addresses: AddressData[];
|
|
14
|
+
defaultBillingAddressId: string | null;
|
|
15
|
+
defaultShippingAddressId: string | null;
|
|
16
|
+
};
|
|
17
|
+
type CustomerAddressDataWithOutId = Required<Omit<CustomerAddressWithoutDefaultAddress, 'id'>>;
|
|
18
|
+
type CustomerAddressData = Required<CustomerAddressWithoutDefaultAddress>;
|
|
19
|
+
declare class CustomerAddressModel extends BaseModel {
|
|
20
|
+
protected id: string;
|
|
21
|
+
protected addresses: AddressModel[];
|
|
22
|
+
protected defaultBillingAddressId: string;
|
|
23
|
+
protected defaultShippingAddressId: string;
|
|
24
|
+
/**
|
|
25
|
+
* Creates an instance of CustomerAddressModel.
|
|
26
|
+
* Initializes the address list, sorting them by modification date (most recent first).
|
|
27
|
+
* @param data - The initial attributes for the customer's addresses.
|
|
28
|
+
* @param date - Optional date object for setting creation/modification times (defaults to now).
|
|
29
|
+
*/
|
|
30
|
+
constructor(data: CustomerAddressAttributes, date?: Date);
|
|
31
|
+
/**
|
|
32
|
+
* Gets a plain data object representing the customer's addresses.
|
|
33
|
+
* Can optionally exclude the customer address collection ID. Includes base model details.
|
|
34
|
+
* @param withId - If true, includes the 'id' field of the CustomerAddressModel. Defaults to false.
|
|
35
|
+
* @returns CustomerAddressData or CustomerAddressDataWithOutId object suitable for serialization.
|
|
36
|
+
*/
|
|
37
|
+
getDetails(withId?: false): CustomerAddressDataWithOutId;
|
|
38
|
+
getDetails(withId: true): CustomerAddressData;
|
|
39
|
+
getId(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the list of all associated address models, sorted by modification date (most recent first).
|
|
42
|
+
* @returns An array of AddressModel instances.
|
|
43
|
+
*/
|
|
44
|
+
getAddresses(): AddressModel[];
|
|
45
|
+
/**
|
|
46
|
+
* Gets a filtered list of addresses designated as shipping addresses.
|
|
47
|
+
* @returns An array of AddressModel instances marked as shipping addresses.
|
|
48
|
+
*/
|
|
49
|
+
getShippingAddresses(): AddressModel[];
|
|
50
|
+
/**
|
|
51
|
+
* Gets a filtered list of addresses designated as billing addresses.
|
|
52
|
+
* @returns An array of AddressModel instances marked as billing addresses.
|
|
53
|
+
*/
|
|
54
|
+
getBillingAddresses(): AddressModel[];
|
|
55
|
+
/**
|
|
56
|
+
* Gets the ID of the default billing address.
|
|
57
|
+
* If the stored default ID is invalid or doesn't correspond to a billing address,
|
|
58
|
+
* it falls back to the most recently modified billing address.
|
|
59
|
+
* @returns The ID of the default billing address, or null if no valid billing address exists.
|
|
60
|
+
*/
|
|
61
|
+
getDefaultBillingAddressId(): string | null;
|
|
62
|
+
/**
|
|
63
|
+
* Gets the ID of the default shipping address.
|
|
64
|
+
* If the stored default ID is invalid or doesn't correspond to a shipping address,
|
|
65
|
+
* it falls back to the most recently modified shipping address.
|
|
66
|
+
* @returns The ID of the default shipping address, or null if no valid shipping address exists.
|
|
67
|
+
*/
|
|
68
|
+
getDefaultShippingAddressId(): string | null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { type CustomerAddressAttributes, type CustomerAddressData, type CustomerAddressDataWithOutId, CustomerAddressModel as default };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import AddressModel, { AddressData } from './Address.js';
|
|
2
|
+
import BaseModel, { BaseAttributes } from './Base.js';
|
|
3
|
+
import './Common.js';
|
|
4
|
+
import './Enum.js';
|
|
5
|
+
|
|
6
|
+
type CustomerAddressAttributes = BaseAttributes & {
|
|
7
|
+
id: string;
|
|
8
|
+
addresses: AddressData[];
|
|
9
|
+
defaultBillingAddressId: string;
|
|
10
|
+
defaultShippingAddressId: string;
|
|
11
|
+
};
|
|
12
|
+
type CustomerAddressWithoutDefaultAddress = Omit<CustomerAddressAttributes, 'addresses' | 'defaultBillingAddressId' | 'defaultShippingAddressId'> & {
|
|
13
|
+
addresses: AddressData[];
|
|
14
|
+
defaultBillingAddressId: string | null;
|
|
15
|
+
defaultShippingAddressId: string | null;
|
|
16
|
+
};
|
|
17
|
+
type CustomerAddressDataWithOutId = Required<Omit<CustomerAddressWithoutDefaultAddress, 'id'>>;
|
|
18
|
+
type CustomerAddressData = Required<CustomerAddressWithoutDefaultAddress>;
|
|
19
|
+
declare class CustomerAddressModel extends BaseModel {
|
|
20
|
+
protected id: string;
|
|
21
|
+
protected addresses: AddressModel[];
|
|
22
|
+
protected defaultBillingAddressId: string;
|
|
23
|
+
protected defaultShippingAddressId: string;
|
|
24
|
+
/**
|
|
25
|
+
* Creates an instance of CustomerAddressModel.
|
|
26
|
+
* Initializes the address list, sorting them by modification date (most recent first).
|
|
27
|
+
* @param data - The initial attributes for the customer's addresses.
|
|
28
|
+
* @param date - Optional date object for setting creation/modification times (defaults to now).
|
|
29
|
+
*/
|
|
30
|
+
constructor(data: CustomerAddressAttributes, date?: Date);
|
|
31
|
+
/**
|
|
32
|
+
* Gets a plain data object representing the customer's addresses.
|
|
33
|
+
* Can optionally exclude the customer address collection ID. Includes base model details.
|
|
34
|
+
* @param withId - If true, includes the 'id' field of the CustomerAddressModel. Defaults to false.
|
|
35
|
+
* @returns CustomerAddressData or CustomerAddressDataWithOutId object suitable for serialization.
|
|
36
|
+
*/
|
|
37
|
+
getDetails(withId?: false): CustomerAddressDataWithOutId;
|
|
38
|
+
getDetails(withId: true): CustomerAddressData;
|
|
39
|
+
getId(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the list of all associated address models, sorted by modification date (most recent first).
|
|
42
|
+
* @returns An array of AddressModel instances.
|
|
43
|
+
*/
|
|
44
|
+
getAddresses(): AddressModel[];
|
|
45
|
+
/**
|
|
46
|
+
* Gets a filtered list of addresses designated as shipping addresses.
|
|
47
|
+
* @returns An array of AddressModel instances marked as shipping addresses.
|
|
48
|
+
*/
|
|
49
|
+
getShippingAddresses(): AddressModel[];
|
|
50
|
+
/**
|
|
51
|
+
* Gets a filtered list of addresses designated as billing addresses.
|
|
52
|
+
* @returns An array of AddressModel instances marked as billing addresses.
|
|
53
|
+
*/
|
|
54
|
+
getBillingAddresses(): AddressModel[];
|
|
55
|
+
/**
|
|
56
|
+
* Gets the ID of the default billing address.
|
|
57
|
+
* If the stored default ID is invalid or doesn't correspond to a billing address,
|
|
58
|
+
* it falls back to the most recently modified billing address.
|
|
59
|
+
* @returns The ID of the default billing address, or null if no valid billing address exists.
|
|
60
|
+
*/
|
|
61
|
+
getDefaultBillingAddressId(): string | null;
|
|
62
|
+
/**
|
|
63
|
+
* Gets the ID of the default shipping address.
|
|
64
|
+
* If the stored default ID is invalid or doesn't correspond to a shipping address,
|
|
65
|
+
* it falls back to the most recently modified shipping address.
|
|
66
|
+
* @returns The ID of the default shipping address, or null if no valid shipping address exists.
|
|
67
|
+
*/
|
|
68
|
+
getDefaultShippingAddressId(): string | null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { type CustomerAddressAttributes, type CustomerAddressData, type CustomerAddressDataWithOutId, CustomerAddressModel as default };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {b}from'../chunk-PD6TDU7F.js';import {a}from'../chunk-Q2WQECY6.js';var t=class extends a{id;addresses;defaultBillingAddressId;defaultShippingAddressId;constructor(s,e=new Date){super(s,e),this.id=s.id,this.addresses=s.addresses.map(d=>new b(d,e)).sort((d,l)=>l.getModifiedAtTime()-d.getModifiedAtTime()),this.defaultBillingAddressId=s.defaultBillingAddressId,this.defaultShippingAddressId=s.defaultShippingAddressId;}getDetails(s=!1){return {...s?{id:this.getId()}:{},addresses:this.getAddresses().map(e=>e.getDetails()),defaultBillingAddressId:this.getDefaultBillingAddressId(),defaultShippingAddressId:this.getDefaultShippingAddressId(),...super.getDetails()}}getId(){return this.id}getAddresses(){return [...this.addresses]}getShippingAddresses(){return this.addresses.filter(s=>s.getIsShippingAddress())}getBillingAddresses(){return this.addresses.filter(s=>s.getIsBillingAddress())}getDefaultBillingAddressId(){let s=this.addresses.find(e=>e.getId()===this.defaultBillingAddressId&&e.getIsBillingAddress());return s?s.getId():this.addresses.find(e=>e.getIsBillingAddress())?.getId()||null}getDefaultShippingAddressId(){let s=this.addresses.find(e=>e.getId()===this.defaultShippingAddressId&&e.getIsShippingAddress());return s?s.getId():this.addresses.find(e=>e.getIsShippingAddress())?.getId()||null}};export{t as default};//# sourceMappingURL=CustomerAddress.js.map
|
|
2
|
+
//# sourceMappingURL=CustomerAddress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Classes/CustomerAddress.ts"],"names":["CustomerAddressModel","BaseModel","data","date","address","AddressModel","a","b","withId","explicitDefault"],"mappings":"0EAoBqBA,IAAAA,CAAAA,CAArB,cAAkDC,CAAU,CAChD,GACA,SACA,CAAA,uBAAA,CACA,yBAQV,WAAYC,CAAAA,CAAAA,CAAiCC,EAAa,IAAI,IAAA,CAAQ,CACpE,KAAMD,CAAAA,CAAAA,CAAMC,CAAI,CAChB,CAAA,IAAA,CAAK,EAAKD,CAAAA,CAAAA,CAAK,EACf,CAAA,IAAA,CAAK,UAAYA,CAAK,CAAA,SAAA,CACnB,IAAKE,CAAyB,EAAA,IAAIC,EAAaD,CAASD,CAAAA,CAAI,CAAC,CAAA,CAC7D,IAAK,CAAA,CA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AA,IAAA,CACpCL,CAAYA,EAAAA,CAAAA,CAAQ,OAAY,GAAA,IAAA,CAAK,0BAA4BA,CAAQ,CAAA,oBAAA,EAC5E,CACA,CAAA,OAAIK,CACKA,CAAAA,CAAAA,CAAgB,KAAM,EAAA,CAGxB,KAAK,SAAU,CAAA,IAAA,CAAML,GAAYA,CAAQ,CAAA,oBAAA,EAAsB,CAAG,EAAA,KAAA,EAAW,EAAA,IACtF,CACF","file":"CustomerAddress.js","sourcesContent":["import AddressModel, { AddressData } from \"./Address\";\r\nimport BaseModel, { BaseAttributes } from \"./Base\";\r\n\r\nexport type CustomerAddressAttributes = BaseAttributes & {\r\n id: string;\r\n addresses: AddressData[];\r\n defaultBillingAddressId: string;\r\n defaultShippingAddressId: string;\r\n}\r\n\r\ntype CustomerAddressWithoutDefaultAddress = Omit<CustomerAddressAttributes, \r\n'addresses' | 'defaultBillingAddressId' | 'defaultShippingAddressId'> & {\r\n addresses: AddressData[];\r\n defaultBillingAddressId: string | null;\r\n defaultShippingAddressId: string | null;\r\n};\r\nexport type CustomerAddressDataWithOutId = Required<Omit<CustomerAddressWithoutDefaultAddress, 'id'>>;\r\nexport type CustomerAddressData = Required<CustomerAddressWithoutDefaultAddress>;\r\n\r\n\r\nexport default class CustomerAddressModel extends BaseModel {\r\n protected id: string;\r\n protected addresses: AddressModel[];\r\n protected defaultBillingAddressId: string;\r\n protected defaultShippingAddressId: string;\r\n\r\n /**\r\n * Creates an instance of CustomerAddressModel.\r\n * Initializes the address list, sorting them by modification date (most recent first).\r\n * @param data - The initial attributes for the customer's addresses.\r\n * @param date - Optional date object for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: CustomerAddressAttributes, date: Date = new Date()) {\r\n super(data, date);\r\n this.id = data.id;\r\n this.addresses = data.addresses\r\n .map((address: AddressData) => new AddressModel(address, date))\r\n .sort((a, b) => b.getModifiedAtTime() - a.getModifiedAtTime());\r\n this.defaultBillingAddressId = data.defaultBillingAddressId;\r\n this.defaultShippingAddressId = data.defaultShippingAddressId;\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the customer's addresses.\r\n * Can optionally exclude the customer address collection ID. Includes base model details.\r\n * @param withId - If true, includes the 'id' field of the CustomerAddressModel. Defaults to false.\r\n * @returns CustomerAddressData or CustomerAddressDataWithOutId object suitable for serialization.\r\n */\r\n getDetails(withId?: false): CustomerAddressDataWithOutId;\r\n getDetails(withId: true): CustomerAddressData;\r\n getDetails(withId: boolean = false): CustomerAddressData | CustomerAddressDataWithOutId {\r\n return {\r\n ...(withId ? { id: this.getId() } : {}),\r\n addresses: this.getAddresses().map((address) => address.getDetails()),\r\n defaultBillingAddressId: this.getDefaultBillingAddressId(),\r\n defaultShippingAddressId: this.getDefaultShippingAddressId(),\r\n ...super.getDetails()\r\n }\r\n }\r\n \r\n getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the list of all associated address models, sorted by modification date (most recent first).\r\n * @returns An array of AddressModel instances.\r\n */\r\n getAddresses(): AddressModel[] {\r\n return [...this.addresses];\r\n }\r\n\r\n /**\r\n * Gets a filtered list of addresses designated as shipping addresses.\r\n * @returns An array of AddressModel instances marked as shipping addresses.\r\n */\r\n getShippingAddresses(): AddressModel[] {\r\n return this.addresses.filter((address) => address.getIsShippingAddress());\r\n }\r\n\r\n /**\r\n * Gets a filtered list of addresses designated as billing addresses.\r\n * @returns An array of AddressModel instances marked as billing addresses.\r\n */\r\n getBillingAddresses(): AddressModel[] {\r\n return this.addresses.filter((address) => address.getIsBillingAddress());\r\n }\r\n\r\n /**\r\n * Gets the ID of the default billing address.\r\n * If the stored default ID is invalid or doesn't correspond to a billing address,\r\n * it falls back to the most recently modified billing address.\r\n * @returns The ID of the default billing address, or null if no valid billing address exists.\r\n */\r\n getDefaultBillingAddressId(): string | null {\r\n const explicitDefault = this.addresses.find(\r\n (address) => address.getId() === this.defaultBillingAddressId && address.getIsBillingAddress()\r\n );\r\n if (explicitDefault) {\r\n return explicitDefault.getId();\r\n }\r\n // Fallback: Find the first address marked as billing (already sorted by most recent)\r\n return this.addresses.find((address) => address.getIsBillingAddress())?.getId() || null;\r\n }\r\n\r\n /**\r\n * Gets the ID of the default shipping address.\r\n * If the stored default ID is invalid or doesn't correspond to a shipping address,\r\n * it falls back to the most recently modified shipping address.\r\n * @returns The ID of the default shipping address, or null if no valid shipping address exists.\r\n */\r\n getDefaultShippingAddressId(): string | null {\r\n // Check if the explicitly set default exists, is valid, and is a shipping address\r\n const explicitDefault = this.addresses.find(\r\n (address) => address.getId() === this.defaultShippingAddressId && address.getIsShippingAddress()\r\n );\r\n if (explicitDefault) {\r\n return explicitDefault.getId();\r\n }\r\n // Fallback: Find the first address marked as shipping (already sorted by most recent)\r\n return this.addresses.find((address) => address.getIsShippingAddress())?.getId() || null;\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var n=(N=>(N.IN="IN",N))(n||{}),p=(N=>(N.INR="INR",N))(p||{}),x=(u=>(u["en-IN"]="en-IN",u))(x||{}),M={IN:"INR"},R={INR:"\u20B9"},m=(I=>(I.MALE="Male",I.FEMALE="Female",I.UNISEX="Unisex",I.KIDS="Kids",I.BOY="Boy",I.GIRL="Girl",I))(m||{});exports.CountryCurrencyMap=M;exports.CurrencySymbolMap=R;exports.GenderCategory=m;exports.OperationalCountry=n;exports.OperationalCountryCurrency=p;exports.OperationalLocale=x;//# sourceMappingURL=Enum.cjs.map
|
|
2
|
+
//# sourceMappingURL=Enum.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Classes/Enum.ts"],"names":["OperationalCountry","OperationalCountryCurrency","OperationalLocale","CountryCurrencyMap","CurrencySymbolMap","GenderCategory"],"mappings":"aAGYA,IAAAA,CAAAA,CAAAA,CAAAA,CAAAA,GACGA,EAAA,EAAK,CAAA,IAAA,CADRA,OAAA,EAIAC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,GACGA,EAAA,GAAM,CAAA,KAAA,CADTA,OAAA,EAIAC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,GACGA,EAAA,OAAU,CAAA,CAAA,OAAA,CADbA,OAAA,EAOCC,CAAAA,CAAAA,CAAAA,CAAqB,CAClB,EAAA,CAAwB,KACxC,CAAA,CAEaC,EAAoB,CAC9B,GAAA,CAAiC,QACpC,CAKYC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,GACVA,EAAA,IAAO,CAAA,MAAA,CACPA,CAAA,CAAA,MAAA,CAAS,QACTA,CAAAA,CAAAA,CAAA,OAAS,QACTA,CAAAA,CAAAA,CAAA,KAAO,MACPA,CAAAA,CAAAA,CAAA,IAAM,KACNA,CAAAA,CAAAA,CAAA,IAAO,CAAA,MAAA,CANGA,CAAA,CAAA,EAAA,CAAA,EAAA,EAAA","file":"Enum.cjs","sourcesContent":["/**\r\n * Represents the countries where the application operates or products are available.\r\n */\r\nexport enum OperationalCountry {\r\n /** India */ IN = 'IN',\r\n}\r\n \r\nexport enum OperationalCountryCurrency {\r\n /** India */ INR = 'INR',\r\n}\r\n\r\nexport enum OperationalLocale {\r\n /** India */ 'en-IN' = 'en-IN',\r\n}\r\n\r\n/**\r\n * Defines the supported ISO 4217 currency codes as an enumeration.\r\n */\r\nexport const CountryCurrencyMap = {\r\n /** India */ [OperationalCountry.IN]: OperationalCountryCurrency.INR,\r\n};\r\n\r\nexport const CurrencySymbolMap = {\r\n [OperationalCountryCurrency.INR]: '₹',\r\n}\r\n\r\n/**\r\n * Defines standard gender categories for product targeting.\r\n */\r\nexport enum GenderCategory {\r\n MALE = 'Male',\r\n FEMALE = 'Female',\r\n UNISEX = 'Unisex',\r\n KIDS = 'Kids',\r\n BOY = 'Boy',\r\n GIRL = 'Girl',\r\n}"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the countries where the application operates or products are available.
|
|
3
|
+
*/
|
|
4
|
+
declare enum OperationalCountry {
|
|
5
|
+
/** India */ IN = "IN"
|
|
6
|
+
}
|
|
7
|
+
declare enum OperationalCountryCurrency {
|
|
8
|
+
/** India */ INR = "INR"
|
|
9
|
+
}
|
|
10
|
+
declare enum OperationalLocale {
|
|
11
|
+
/** India */ 'en-IN' = "en-IN"
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Defines the supported ISO 4217 currency codes as an enumeration.
|
|
15
|
+
*/
|
|
16
|
+
declare const CountryCurrencyMap: {
|
|
17
|
+
/** India */ IN: OperationalCountryCurrency;
|
|
18
|
+
};
|
|
19
|
+
declare const CurrencySymbolMap: {
|
|
20
|
+
INR: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Defines standard gender categories for product targeting.
|
|
24
|
+
*/
|
|
25
|
+
declare enum GenderCategory {
|
|
26
|
+
MALE = "Male",
|
|
27
|
+
FEMALE = "Female",
|
|
28
|
+
UNISEX = "Unisex",
|
|
29
|
+
KIDS = "Kids",
|
|
30
|
+
BOY = "Boy",
|
|
31
|
+
GIRL = "Girl"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { CountryCurrencyMap, CurrencySymbolMap, GenderCategory, OperationalCountry, OperationalCountryCurrency, OperationalLocale };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the countries where the application operates or products are available.
|
|
3
|
+
*/
|
|
4
|
+
declare enum OperationalCountry {
|
|
5
|
+
/** India */ IN = "IN"
|
|
6
|
+
}
|
|
7
|
+
declare enum OperationalCountryCurrency {
|
|
8
|
+
/** India */ INR = "INR"
|
|
9
|
+
}
|
|
10
|
+
declare enum OperationalLocale {
|
|
11
|
+
/** India */ 'en-IN' = "en-IN"
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Defines the supported ISO 4217 currency codes as an enumeration.
|
|
15
|
+
*/
|
|
16
|
+
declare const CountryCurrencyMap: {
|
|
17
|
+
/** India */ IN: OperationalCountryCurrency;
|
|
18
|
+
};
|
|
19
|
+
declare const CurrencySymbolMap: {
|
|
20
|
+
INR: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Defines standard gender categories for product targeting.
|
|
24
|
+
*/
|
|
25
|
+
declare enum GenderCategory {
|
|
26
|
+
MALE = "Male",
|
|
27
|
+
FEMALE = "Female",
|
|
28
|
+
UNISEX = "Unisex",
|
|
29
|
+
KIDS = "Kids",
|
|
30
|
+
BOY = "Boy",
|
|
31
|
+
GIRL = "Girl"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { CountryCurrencyMap, CurrencySymbolMap, GenderCategory, OperationalCountry, OperationalCountryCurrency, OperationalLocale };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"Enum.js"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var s=(t=>(t.THUMBNAIL="thumbnail",t.SMALL="small",t.MEDIUM="medium",t.LARGE="large",t.ORIGINAL="original",t))(s||{}),r=class{sources;alt;order;label;constructor(e){if(this.sources={...e.sources},this.alt=e.alt,this.order=e.order,this.label=e.label,!this.sources.original)throw "ImageInfoModel cannot be created without an 'original' source URL."}getSources(){return {...this.sources}}getSource(e){return this.sources[e]||this.sources.original}getAlt(){return this.alt}getOrder(){return this.order}getLabel(){return this.label}setAlt(e){this.alt=e;}setOrder(e){this.order=e;}setLabel(e){this.label=e;}setSource(e,i){if(i===void 0){if(e==="original")throw "Cannot remove the 'original' image source.";delete this.sources[e];}else this.sources[e]=i;}getDetails(){return {sources:this.getSources(),alt:this.getAlt(),order:this.getOrder(),label:this.getLabel()}}};exports.ImageResolution=s;exports.default=r;//# sourceMappingURL=ImageInfo.cjs.map
|
|
2
|
+
//# sourceMappingURL=ImageInfo.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Classes/ImageInfo.ts"],"names":["ImageResolution","ImageInfoModel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J,CAAkB,GAAA,UAAA,CAClB,MAAO,4CAAA,CAGX,OAAO,IAAK,CAAA,OAAA,CAAQA,CAAa,EACrC,MACI,IAAK,CAAA,OAAA,CAAQA,CAAa,CAAII,CAAAA,EAEtC,CAKA,UAA4B,EAAA,CAC1B,OAAO,CACL,QAAS,IAAK,CAAA,UAAA,EACd,CAAA,GAAA,CAAK,KAAK,MAAO,EAAA,CACjB,KAAO,CAAA,IAAA,CAAK,UACZ,CAAA,KAAA,CAAO,KAAK,QAAS,EACvB,CACF,CACF","file":"ImageInfo.cjs","sourcesContent":["export enum ImageResolution {\r\n THUMBNAIL = 'thumbnail',\r\n SMALL = 'small',\r\n MEDIUM = 'medium',\r\n LARGE = 'large',\r\n ORIGINAL = 'original',\r\n}\r\n\r\nexport type ImageInfoAttribute = {\r\n sources: { [key in ImageResolution]?: string } & { original: string };\r\n alt?: string;\r\n order?: number;\r\n label?: string;\r\n};\r\n\r\nexport type ImageInfoData = ImageInfoAttribute;\r\n\r\n/**\r\n * Represents and manages structured image data, including multiple resolutions.\r\n */\r\nexport default class ImageInfoModel {\r\n protected sources: { [key in ImageResolution]?: string } & { original: string };\r\n protected alt?: string;\r\n protected order?: number;\r\n protected label?: string;\r\n\r\n /**\r\n * Creates an instance of ImageInfoModel.\r\n * @param data - The initial image data.\r\n */\r\n constructor(data: ImageInfoAttribute) {\r\n this.sources = { ...data.sources };\r\n this.alt = data.alt;\r\n this.order = data.order;\r\n this.label = data.label;\r\n\r\n if (!this.sources.original) {\r\n throw (\"ImageInfoModel cannot be created without an 'original' source URL.\");\r\n }\r\n }\r\n\r\n /**\r\n * Gets the sources object containing URLs for different resolutions.\r\n * Returns a copy to prevent external modification.\r\n */\r\n getSources() {\r\n return { ...this.sources };\r\n }\r\n\r\n /**\r\n * Gets the URL for a specific resolution key.\r\n * @param resolutionKey - The key of the desired resolution (e.g., 'thumbnail', 'medium').\r\n * @returns The URL string if the key doesn't exist, otherwise original image URL will be returned.\r\n */\r\n getSource(resolutionKey: ImageResolution): string{\r\n return this.sources[resolutionKey] || this.sources.original;\r\n }\r\n\r\n /**\r\n * Gets the alternative text for the image.\r\n */\r\n getAlt(): string | undefined {\r\n return this.alt;\r\n }\r\n\r\n /**\r\n * Gets the display order number for the image.\r\n */\r\n getOrder(): number | undefined {\r\n return this.order;\r\n }\r\n\r\n /**\r\n * Gets the display label or caption for the image.\r\n */\r\n getLabel(): string | undefined {\r\n return this.label;\r\n }\r\n\r\n /**\r\n * Sets the alternative text for the image.\r\n * @param altText - The new alt text.\r\n */\r\n setAlt(altText: string | undefined): void {\r\n this.alt = altText;\r\n // Potentially add logic here to trigger updates if needed\r\n }\r\n\r\n /**\r\n * Sets the display order for the image.\r\n * @param order - The new order number.\r\n */\r\n setOrder(order: number | undefined): void {\r\n this.order = order;\r\n }\r\n\r\n /**\r\n * Sets the display label for the image.\r\n * @param label - The new label text.\r\n */\r\n setLabel(label: string | undefined): void {\r\n this.label = label;\r\n }\r\n\r\n /**\r\n * Updates or adds a URL for a specific resolution.\r\n * @param resolutionKey - The key of the resolution to update/add.\r\n * @param url - The URL for the resolution. Set to undefined to remove.\r\n */\r\n setSource(resolutionKey: ImageResolution, url: string | undefined): void {\r\n if (url === undefined) {\r\n // Prevent deleting the 'original' key if it's required\r\n if (resolutionKey === 'original') {\r\n throw (\"Cannot remove the 'original' image source.\");\r\n return;\r\n }\r\n delete this.sources[resolutionKey];\r\n } else {\r\n this.sources[resolutionKey] = url;\r\n }\r\n }\r\n\r\n /**\r\n * Returns a plain JavaScript object representation of the image info.\r\n */\r\n getDetails(): ImageInfoData {\r\n return {\r\n sources: this.getSources(),\r\n alt: this.getAlt(),\r\n order: this.getOrder(),\r\n label: this.getLabel(),\r\n };\r\n }\r\n}"]}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
declare enum ImageResolution {
|
|
2
|
+
THUMBNAIL = "thumbnail",
|
|
3
|
+
SMALL = "small",
|
|
4
|
+
MEDIUM = "medium",
|
|
5
|
+
LARGE = "large",
|
|
6
|
+
ORIGINAL = "original"
|
|
7
|
+
}
|
|
8
|
+
type ImageInfoAttribute = {
|
|
9
|
+
sources: {
|
|
10
|
+
[key in ImageResolution]?: string;
|
|
11
|
+
} & {
|
|
12
|
+
original: string;
|
|
13
|
+
};
|
|
14
|
+
alt?: string;
|
|
15
|
+
order?: number;
|
|
16
|
+
label?: string;
|
|
17
|
+
};
|
|
18
|
+
type ImageInfoData = ImageInfoAttribute;
|
|
19
|
+
/**
|
|
20
|
+
* Represents and manages structured image data, including multiple resolutions.
|
|
21
|
+
*/
|
|
22
|
+
declare class ImageInfoModel {
|
|
23
|
+
protected sources: {
|
|
24
|
+
[key in ImageResolution]?: string;
|
|
25
|
+
} & {
|
|
26
|
+
original: string;
|
|
27
|
+
};
|
|
28
|
+
protected alt?: string;
|
|
29
|
+
protected order?: number;
|
|
30
|
+
protected label?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Creates an instance of ImageInfoModel.
|
|
33
|
+
* @param data - The initial image data.
|
|
34
|
+
*/
|
|
35
|
+
constructor(data: ImageInfoAttribute);
|
|
36
|
+
/**
|
|
37
|
+
* Gets the sources object containing URLs for different resolutions.
|
|
38
|
+
* Returns a copy to prevent external modification.
|
|
39
|
+
*/
|
|
40
|
+
getSources(): {
|
|
41
|
+
thumbnail?: string | undefined;
|
|
42
|
+
small?: string | undefined;
|
|
43
|
+
medium?: string | undefined;
|
|
44
|
+
large?: string | undefined;
|
|
45
|
+
original: string;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Gets the URL for a specific resolution key.
|
|
49
|
+
* @param resolutionKey - The key of the desired resolution (e.g., 'thumbnail', 'medium').
|
|
50
|
+
* @returns The URL string if the key doesn't exist, otherwise original image URL will be returned.
|
|
51
|
+
*/
|
|
52
|
+
getSource(resolutionKey: ImageResolution): string;
|
|
53
|
+
/**
|
|
54
|
+
* Gets the alternative text for the image.
|
|
55
|
+
*/
|
|
56
|
+
getAlt(): string | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Gets the display order number for the image.
|
|
59
|
+
*/
|
|
60
|
+
getOrder(): number | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Gets the display label or caption for the image.
|
|
63
|
+
*/
|
|
64
|
+
getLabel(): string | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Sets the alternative text for the image.
|
|
67
|
+
* @param altText - The new alt text.
|
|
68
|
+
*/
|
|
69
|
+
setAlt(altText: string | undefined): void;
|
|
70
|
+
/**
|
|
71
|
+
* Sets the display order for the image.
|
|
72
|
+
* @param order - The new order number.
|
|
73
|
+
*/
|
|
74
|
+
setOrder(order: number | undefined): void;
|
|
75
|
+
/**
|
|
76
|
+
* Sets the display label for the image.
|
|
77
|
+
* @param label - The new label text.
|
|
78
|
+
*/
|
|
79
|
+
setLabel(label: string | undefined): void;
|
|
80
|
+
/**
|
|
81
|
+
* Updates or adds a URL for a specific resolution.
|
|
82
|
+
* @param resolutionKey - The key of the resolution to update/add.
|
|
83
|
+
* @param url - The URL for the resolution. Set to undefined to remove.
|
|
84
|
+
*/
|
|
85
|
+
setSource(resolutionKey: ImageResolution, url: string | undefined): void;
|
|
86
|
+
/**
|
|
87
|
+
* Returns a plain JavaScript object representation of the image info.
|
|
88
|
+
*/
|
|
89
|
+
getDetails(): ImageInfoData;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { type ImageInfoAttribute, type ImageInfoData, ImageResolution, ImageInfoModel as default };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
declare enum ImageResolution {
|
|
2
|
+
THUMBNAIL = "thumbnail",
|
|
3
|
+
SMALL = "small",
|
|
4
|
+
MEDIUM = "medium",
|
|
5
|
+
LARGE = "large",
|
|
6
|
+
ORIGINAL = "original"
|
|
7
|
+
}
|
|
8
|
+
type ImageInfoAttribute = {
|
|
9
|
+
sources: {
|
|
10
|
+
[key in ImageResolution]?: string;
|
|
11
|
+
} & {
|
|
12
|
+
original: string;
|
|
13
|
+
};
|
|
14
|
+
alt?: string;
|
|
15
|
+
order?: number;
|
|
16
|
+
label?: string;
|
|
17
|
+
};
|
|
18
|
+
type ImageInfoData = ImageInfoAttribute;
|
|
19
|
+
/**
|
|
20
|
+
* Represents and manages structured image data, including multiple resolutions.
|
|
21
|
+
*/
|
|
22
|
+
declare class ImageInfoModel {
|
|
23
|
+
protected sources: {
|
|
24
|
+
[key in ImageResolution]?: string;
|
|
25
|
+
} & {
|
|
26
|
+
original: string;
|
|
27
|
+
};
|
|
28
|
+
protected alt?: string;
|
|
29
|
+
protected order?: number;
|
|
30
|
+
protected label?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Creates an instance of ImageInfoModel.
|
|
33
|
+
* @param data - The initial image data.
|
|
34
|
+
*/
|
|
35
|
+
constructor(data: ImageInfoAttribute);
|
|
36
|
+
/**
|
|
37
|
+
* Gets the sources object containing URLs for different resolutions.
|
|
38
|
+
* Returns a copy to prevent external modification.
|
|
39
|
+
*/
|
|
40
|
+
getSources(): {
|
|
41
|
+
thumbnail?: string | undefined;
|
|
42
|
+
small?: string | undefined;
|
|
43
|
+
medium?: string | undefined;
|
|
44
|
+
large?: string | undefined;
|
|
45
|
+
original: string;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Gets the URL for a specific resolution key.
|
|
49
|
+
* @param resolutionKey - The key of the desired resolution (e.g., 'thumbnail', 'medium').
|
|
50
|
+
* @returns The URL string if the key doesn't exist, otherwise original image URL will be returned.
|
|
51
|
+
*/
|
|
52
|
+
getSource(resolutionKey: ImageResolution): string;
|
|
53
|
+
/**
|
|
54
|
+
* Gets the alternative text for the image.
|
|
55
|
+
*/
|
|
56
|
+
getAlt(): string | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Gets the display order number for the image.
|
|
59
|
+
*/
|
|
60
|
+
getOrder(): number | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Gets the display label or caption for the image.
|
|
63
|
+
*/
|
|
64
|
+
getLabel(): string | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Sets the alternative text for the image.
|
|
67
|
+
* @param altText - The new alt text.
|
|
68
|
+
*/
|
|
69
|
+
setAlt(altText: string | undefined): void;
|
|
70
|
+
/**
|
|
71
|
+
* Sets the display order for the image.
|
|
72
|
+
* @param order - The new order number.
|
|
73
|
+
*/
|
|
74
|
+
setOrder(order: number | undefined): void;
|
|
75
|
+
/**
|
|
76
|
+
* Sets the display label for the image.
|
|
77
|
+
* @param label - The new label text.
|
|
78
|
+
*/
|
|
79
|
+
setLabel(label: string | undefined): void;
|
|
80
|
+
/**
|
|
81
|
+
* Updates or adds a URL for a specific resolution.
|
|
82
|
+
* @param resolutionKey - The key of the resolution to update/add.
|
|
83
|
+
* @param url - The URL for the resolution. Set to undefined to remove.
|
|
84
|
+
*/
|
|
85
|
+
setSource(resolutionKey: ImageResolution, url: string | undefined): void;
|
|
86
|
+
/**
|
|
87
|
+
* Returns a plain JavaScript object representation of the image info.
|
|
88
|
+
*/
|
|
89
|
+
getDetails(): ImageInfoData;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { type ImageInfoAttribute, type ImageInfoData, ImageResolution, ImageInfoModel as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"ImageInfo.js"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var s=class{sources;alt;order;label;constructor(t){if(this.sources={...t.sources},this.alt=t.alt,this.order=t.order,this.label=t.label,!this.sources.original)throw "ImageInfoModel cannot be created without an 'original' source URL."}getSources(){return {...this.sources}}getSource(t){return this.sources[t]||this.sources.original}getAlt(){return this.alt}getOrder(){return this.order}getLabel(){return this.label}setAlt(t){this.alt=t;}setOrder(t){this.order=t;}setLabel(t){this.label=t;}setSource(t,e){if(e===void 0){if(t==="original")throw "Cannot remove the 'original' image source.";delete this.sources[t];}else this.sources[t]=e;}getDetails(){return {sources:this.getSources(),alt:this.getAlt(),order:this.getOrder(),label:this.getLabel()}}};var n=class{id;productKey;variantId;name;attributes;primaryImage;subItems;totalQuantity;basePrice;priceTotals;priceTiers;constructor(t){this.id=t.id,this.productKey=t.productKey,this.variantId=t.variantId,this.name={...t.name},this.attributes={...t.attributes},this.primaryImage=new s(t.primaryImage),this.subItems=t.subItems.map(e=>({...e})),this.basePrice={...t.basePrice},this.priceTiers=t.priceTiers.map(e=>({...e})),this.totalQuantity=0,this.priceTotals={subtotal:0,mrpTotal:0},this.recalculateTotalQuantity(),this.recalculatePriceTotal();}getId(){return this.id}getProductKey(){return this.productKey}getVariantId(){return this.variantId}getName(t){return t?this.name[t]??this.name.en:{...this.name}}getAttributes(){return {...this.attributes}}getImage(){return this.primaryImage}getSubItems(){return this.subItems.map(t=>({...t}))}getTotalQuantity(){return this.totalQuantity}getBasePrice(){return {...this.basePrice}}getPriceTotals(){return {...this.priceTotals}}getPriceTiers(){return this.priceTiers.map(t=>({...t}))}recalculateTotalQuantity(){this.totalQuantity=this.subItems.reduce((t,e)=>t+e.quantity,0);}recalculatePriceTotal(){let t=this.totalQuantity,e=this.basePrice.unitPrice,i=null;for(let r of this.priceTiers.sort((a,u)=>u.minQuantity-a.minQuantity))if(t>=r.minQuantity){i=r;break}i&&(e=i.unitPrice),this.priceTotals.mrpTotal=this.basePrice.unitPrice*t,this.priceTotals.subtotal=e*t;}getDetails(){return {id:this.getId(),productKey:this.getProductKey(),variantId:this.getVariantId(),name:this.getName(),attributes:this.getAttributes(),primaryImage:this.getImage().getDetails(),subItems:this.getSubItems(),totalQuantity:this.getTotalQuantity(),basePrice:this.getBasePrice(),priceTotals:this.getPriceTotals(),priceTiers:this.getPriceTiers()}}addSubItems(t,e){t.forEach(i=>{let r=this.subItems.find(a=>a.size===i.size);r?r.quantity=e?r.quantity+i.quantity:i.quantity:this.subItems.push(i);}),this.subItems=this.subItems.filter(i=>i.quantity),this.recalculateTotalQuantity(),this.recalculatePriceTotal();}clearLineItem(){this.id="",this.productKey="",this.variantId="",this.name={en:""},this.attributes={color:{name:"",hex:""}},this.primaryImage=new s({sources:{original:""}}),this.subItems=[],this.recalculateTotalQuantity(),this.recalculatePriceTotal();}};module.exports=n;//# sourceMappingURL=LineItem.cjs.map
|
|
2
|
+
//# sourceMappingURL=LineItem.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Classes/ImageInfo.ts","../../src/Classes/LineItem.ts"],"names":["ImageInfoModel","data","resolutionKey","altText","order","label","url","LineItemModel","item","tier","locale","sum","quantity","unitPrice","applicableTier","b","subItems","addQuantity","subItem","existingSubItem","sub"],"mappings":"aAoBA,IAAqBA,CAArB,CAAA,KAAoC,CACxB,OAAA,CACA,GACA,CAAA,KAAA,CACA,KAMV,CAAA,WAAA,CAAYC,CAA0B,CAAA,CAMpC,GALA,IAAA,CAAK,QAAU,CAAE,GAAGA,CAAK,CAAA,OAAQ,CACjC,CAAA,IAAA,CAAK,GAAMA,CAAAA,CAAAA,CAAK,IAChB,IAAK,CAAA,KAAA,CAAQA,CAAK,CAAA,KAAA,CAClB,IAAK,CAAA,KAAA,CAAQA,CAAK,CAAA,KAAA,CAEd,CAAC,IAAK,CAAA,OAAA,CAAQ,QACd,CAAA,MAAO,oEAEb,CAMA,UAAa,EAAA,CACX,OAAO,CAAE,GAAG,IAAK,CAAA,OAAQ,CAC3B,CAOA,SAAUC,CAAAA,CAAAA,CAAuC,CAC/C,OAAO,IAAA,CAAK,OAAQA,CAAAA,CAAa,CAAK,EAAA,IAAA,CAAK,OAAQ,CAAA,QACrD,CAKA,MAA6B,EAAA,CAC3B,OAAO,IAAA,CAAK,GACd,CAKA,QAA+B,EAAA,CAC7B,OAAO,IAAK,CAAA,KACd,CAKA,QAAA,EAA+B,CAC7B,OAAO,IAAK,CAAA,KACd,CAMA,MAAA,CAAOC,CAAmC,CAAA,CACxC,IAAK,CAAA,GAAA,CAAMA,EAEb,CAMA,SAASC,CAAiC,CAAA,CACxC,IAAK,CAAA,KAAA,CAAQA,EACf,CAMA,Q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AAkB,CAAA,IAAA,CAAK,SAAS,IAAKX,CAAAA,CAAAA,EAAQA,CAAK,CAAA,IAAA,GAASU,CAAQ,CAAA,IAAI,CACzEC,CAAAA,CAAAA,CACAA,EAAgB,QAAWF,CAAAA,CAAAA,CAAcE,CAAgB,CAAA,QAAA,CAAWD,CAAQ,CAAA,QAAA,CAAWA,CAAQ,CAAA,QAAA,CAE/F,KAAK,QAAS,CAAA,IAAA,CAAKA,CAAO,EAEhC,CAAC,CAAA,CACD,IAAK,CAAA,QAAA,CAAW,KAAK,QAAS,CAAA,MAAA,CAAOE,CAAOA,EAAAA,CAAAA,CAAI,QAAQ,CAAA,CAExD,IAAK,CAAA,wBAAA,GACL,IAAK,CAAA,qBAAA,GACP,CAOA,aAAsB,EAAA,CACpB,IAAK,CAAA,EAAA,CAAK,GACV,IAAK,CAAA,UAAA,CAAa,EAClB,CAAA,IAAA,CAAK,SAAY,CAAA,EAAA,CACjB,IAAK,CAAA,IAAA,CAAO,CAAE,EAAI,CAAA,EAAG,CACrB,CAAA,IAAA,CAAK,UAAa,CAAA,CAAE,KAAO,CAAA,CAAE,KAAM,EAAI,CAAA,GAAA,CAAK,EAAG,CAAE,CACjD,CAAA,IAAA,CAAK,YAAe,CAAA,IAAIpB,EAAe,CAAE,OAAA,CAAS,CAAE,QAAA,CAAU,EAAG,CAAE,CAAC,CAAA,CACpE,KAAK,QAAW,CAAA,EAChB,CAAA,IAAA,CAAK,wBAAyB,EAAA,CAC9B,IAAK,CAAA,qBAAA,GACP,CACF","file":"LineItem.cjs","sourcesContent":["export enum ImageResolution {\r\n THUMBNAIL = 'thumbnail',\r\n SMALL = 'small',\r\n MEDIUM = 'medium',\r\n LARGE = 'large',\r\n ORIGINAL = 'original',\r\n}\r\n\r\nexport type ImageInfoAttribute = {\r\n sources: { [key in ImageResolution]?: string } & { original: string };\r\n alt?: string;\r\n order?: number;\r\n label?: string;\r\n};\r\n\r\nexport type ImageInfoData = ImageInfoAttribute;\r\n\r\n/**\r\n * Represents and manages structured image data, including multiple resolutions.\r\n */\r\nexport default class ImageInfoModel {\r\n protected sources: { [key in ImageResolution]?: string } & { original: string };\r\n protected alt?: string;\r\n protected order?: number;\r\n protected label?: string;\r\n\r\n /**\r\n * Creates an instance of ImageInfoModel.\r\n * @param data - The initial image data.\r\n */\r\n constructor(data: ImageInfoAttribute) {\r\n this.sources = { ...data.sources };\r\n this.alt = data.alt;\r\n this.order = data.order;\r\n this.label = data.label;\r\n\r\n if (!this.sources.original) {\r\n throw (\"ImageInfoModel cannot be created without an 'original' source URL.\");\r\n }\r\n }\r\n\r\n /**\r\n * Gets the sources object containing URLs for different resolutions.\r\n * Returns a copy to prevent external modification.\r\n */\r\n getSources() {\r\n return { ...this.sources };\r\n }\r\n\r\n /**\r\n * Gets the URL for a specific resolution key.\r\n * @param resolutionKey - The key of the desired resolution (e.g., 'thumbnail', 'medium').\r\n * @returns The URL string if the key doesn't exist, otherwise original image URL will be returned.\r\n */\r\n getSource(resolutionKey: ImageResolution): string{\r\n return this.sources[resolutionKey] || this.sources.original;\r\n }\r\n\r\n /**\r\n * Gets the alternative text for the image.\r\n */\r\n getAlt(): string | undefined {\r\n return this.alt;\r\n }\r\n\r\n /**\r\n * Gets the display order number for the image.\r\n */\r\n getOrder(): number | undefined {\r\n return this.order;\r\n }\r\n\r\n /**\r\n * Gets the display label or caption for the image.\r\n */\r\n getLabel(): string | undefined {\r\n return this.label;\r\n }\r\n\r\n /**\r\n * Sets the alternative text for the image.\r\n * @param altText - The new alt text.\r\n */\r\n setAlt(altText: string | undefined): void {\r\n this.alt = altText;\r\n // Potentially add logic here to trigger updates if needed\r\n }\r\n\r\n /**\r\n * Sets the display order for the image.\r\n * @param order - The new order number.\r\n */\r\n setOrder(order: number | undefined): void {\r\n this.order = order;\r\n }\r\n\r\n /**\r\n * Sets the display label for the image.\r\n * @param label - The new label text.\r\n */\r\n setLabel(label: string | undefined): void {\r\n this.label = label;\r\n }\r\n\r\n /**\r\n * Updates or adds a URL for a specific resolution.\r\n * @param resolutionKey - The key of the resolution to update/add.\r\n * @param url - The URL for the resolution. Set to undefined to remove.\r\n */\r\n setSource(resolutionKey: ImageResolution, url: string | undefined): void {\r\n if (url === undefined) {\r\n // Prevent deleting the 'original' key if it's required\r\n if (resolutionKey === 'original') {\r\n throw (\"Cannot remove the 'original' image source.\");\r\n return;\r\n }\r\n delete this.sources[resolutionKey];\r\n } else {\r\n this.sources[resolutionKey] = url;\r\n }\r\n }\r\n\r\n /**\r\n * Returns a plain JavaScript object representation of the image info.\r\n */\r\n getDetails(): ImageInfoData {\r\n return {\r\n sources: this.getSources(),\r\n alt: this.getAlt(),\r\n order: this.getOrder(),\r\n label: this.getLabel(),\r\n };\r\n }\r\n}","import { BasePrice, Color, LocaleCode, LocalizedString, PriceTier } from \"./Common\";\r\nimport ImageInfoModel, { ImageInfoData } from \"./ImageInfo\";\r\n\r\nexport type SubItem = {\r\n size: string;\r\n quantity: number;\r\n};\r\n\r\nexport type LineItemAttributes = {\r\n id: string;\r\n productKey: string;\r\n variantId: string;\r\n name: LocalizedString;\r\n attributes: {\r\n color: Color;\r\n };\r\n primaryImage: ImageInfoData;\r\n subItems: SubItem[];\r\n basePrice: BasePrice;\r\n priceTiers: PriceTier[];\r\n}\r\n\r\nexport type LineItemData = LineItemAttributes & {\r\n totalQuantity: number;\r\n priceTotals: {\r\n subtotal: number;\r\n mrpTotal: number;\r\n };\r\n}\r\n\r\n/**\r\n * Represents a line item within a shopping cart.\r\n */\r\nexport default class LineItemModel {\r\n protected id: string;\r\n protected productKey: string;\r\n protected variantId: string;\r\n protected name: LocalizedString;\r\n protected attributes: {\r\n color: Color;\r\n };\r\n protected primaryImage: ImageInfoModel;\r\n protected subItems: SubItem[];\r\n protected totalQuantity: number;\r\n protected basePrice: BasePrice;\r\n protected priceTotals: {\r\n subtotal: number;\r\n mrpTotal: number;\r\n };\r\n protected priceTiers: PriceTier[];\r\n\r\n /**\r\n * Creates an instance of LineItemModel.\r\n * @param data - The initial line item attributes.\r\n */\r\n constructor(data: LineItemAttributes) {\r\n this.id = data.id;\r\n this.productKey = data.productKey;\r\n this.variantId = data.variantId;\r\n\r\n this.name = { ...data.name };\r\n this.attributes = { ...data.attributes };\r\n this.primaryImage = new ImageInfoModel(data.primaryImage);\r\n this.subItems = data.subItems.map(item => ({ ...item }));\r\n this.basePrice = { ...data.basePrice };\r\n this.priceTiers = data.priceTiers.map(tier => ({ ...tier }));\r\n\r\n this.totalQuantity = 0;\r\n this.priceTotals = {\r\n subtotal: 0,\r\n mrpTotal: 0\r\n };\r\n\r\n this.recalculateTotalQuantity();\r\n this.recalculatePriceTotal();\r\n }\r\n\r\n /** Gets the unique identifier of the line item. */\r\n getId(): string {\r\n return this.id;\r\n }\r\n\r\n /** Gets the product key associated with this line item. */\r\n getProductKey(): string {\r\n return this.productKey;\r\n }\r\n\r\n /** Gets the product variant ID associated with this line item. */\r\n getVariantId(): string {\r\n return this.variantId;\r\n }\r\n\r\n /**\r\n * Gets the full localized product name object.\r\n * @returns A copy of the LocalizedString object for the name.\r\n */\r\n getName(): LocalizedString\r\n /**\r\n * Gets the product name for a specific locale, falling back to English ('en').\r\n * @param locale - The desired locale code.\r\n * @returns The name string for the specified locale.\r\n */\r\n getName(locale: LocaleCode): string\r\n getName(locale?: LocaleCode): LocalizedString | string {\r\n if(locale) {\r\n return this.name[locale] ?? this.name.en;\r\n } else {\r\n return { ...this.name };\r\n }\r\n }\r\n\r\n\r\n /** Gets the variant attributes. */\r\n getAttributes(): { color: Color } {\r\n return { ...this.attributes };\r\n }\r\n\r\n /** Gets the image information model for this line item. */\r\n getImage(): ImageInfoModel {\r\n return this.primaryImage;\r\n }\r\n\r\n /** Gets the sub-items (size/quantity breakdown). */\r\n getSubItems(): SubItem[] {\r\n return this.subItems.map(item => ({ ...item }));\r\n }\r\n\r\n /** Gets the total quantity for this line item across all sub-items. */\r\n getTotalQuantity(): number {\r\n return this.totalQuantity;\r\n }\r\n\r\n /** Gets the base price for a single unit. */\r\n getBasePrice(): BasePrice {\r\n return { ...this.basePrice };\r\n }\r\n\r\n /** Gets the calculated price details (subtotal, mrpTotal) for this line item. */\r\n getPriceTotals(): { subtotal: number; mrpTotal: number } {\r\n return { ...this.priceTotals };\r\n }\r\n\r\n /** Gets the applicable price tiers for this product variant. */\r\n getPriceTiers(): PriceTier[] {\r\n return this.priceTiers.map(tier => ({ ...tier }));\r\n }\r\n\r\n /**\r\n * Recalculates the total quantity based on the quantities in subItems.\r\n */\r\n protected recalculateTotalQuantity(): void {\r\n this.totalQuantity = this.subItems.reduce((sum, item) => sum + item.quantity, 0);\r\n }\r\n\r\n /**\r\n * Recalculates the line item's price (subtotal and mrpTotal)\r\n * based on total quantity, base price, and applicable price tiers.\r\n */\r\n protected recalculatePriceTotal(): void {\r\n const quantity = this.totalQuantity;\r\n let unitPrice = this.basePrice.unitPrice;\r\n\r\n let applicableTier = null;\r\n for (const tier of this.priceTiers.sort((a, b) => b.minQuantity - a.minQuantity)) { \r\n if (quantity >= tier.minQuantity) {\r\n applicableTier = tier;\r\n break;\r\n }\r\n }\r\n\r\n if (applicableTier) {\r\n unitPrice = applicableTier.unitPrice;\r\n }\r\n\r\n // Calculate totals\r\n this.priceTotals.mrpTotal = this.basePrice.unitPrice * quantity;\r\n this.priceTotals.subtotal = unitPrice * quantity;\r\n }\r\n\r\n\r\n /**\r\n * Gets a plain data object representing the line item's details.\r\n * @returns LineItemData.\r\n */\r\n getDetails(): LineItemData {\r\n return {\r\n id: this.getId(),\r\n productKey: this.getProductKey(),\r\n variantId: this.getVariantId(),\r\n name: this.getName(),\r\n attributes: this.getAttributes(),\r\n primaryImage: this.getImage().getDetails(),\r\n subItems: this.getSubItems(),\r\n totalQuantity: this.getTotalQuantity(),\r\n basePrice: this.getBasePrice(),\r\n priceTotals: this.getPriceTotals(),\r\n priceTiers: this.getPriceTiers(),\r\n };\r\n }\r\n \r\n /**\r\n * Adds or updates sub-items (e.g., sizes with quantities) to the line item.\r\n * If a sub-item with the same size already exists, its quantity is either\r\n * updated by adding the new quantity or replaced entirely, based on the `addQuantity` flag.\r\n * Sub-items with a resulting quantity of 0 are removed.\r\n * Recalculates total quantity and price totals afterwards.\r\n *\r\n * @param subItems - An array of `SubItem` objects to add or update.\r\n * @param addQuantity - If true, adds the quantity from `subItem` to the existing quantity.\r\n * If false, replaces the existing quantity with the one from `subItem`.\r\n */\r\n addSubItems(subItems: SubItem[], addQuantity: boolean): void {\r\n subItems.forEach(subItem => {\r\n const existingSubItem = this.subItems.find(item => item.size === subItem.size);\r\n if (existingSubItem) {\r\n existingSubItem.quantity = addQuantity ? existingSubItem.quantity + subItem.quantity : subItem.quantity;\r\n } else {\r\n this.subItems.push(subItem);\r\n }\r\n })\r\n this.subItems = this.subItems.filter(sub => sub.quantity);\r\n\r\n this.recalculateTotalQuantity();\r\n this.recalculatePriceTotal();\r\n }\r\n\r\n /**\r\n * Resets the line item's properties to their default empty or initial state.\r\n * Useful for clearing out line item data without creating a new instance.\r\n * Recalculates total quantity and price totals afterwards (which will be zero).\r\n */\r\n clearLineItem(): void {\r\n this.id = '';\r\n this.productKey = '';\r\n this.variantId = '';\r\n this.name = { en: '' };\r\n this.attributes = { color: { name: '', hex: '' } };\r\n this.primaryImage = new ImageInfoModel({ sources: { original: '' } });\r\n this.subItems = [];\r\n this.recalculateTotalQuantity();\r\n this.recalculatePriceTotal();\r\n }\r\n}"]}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { LocalizedString, Color, BasePrice, PriceTier, LocaleCode } from './Common.cjs';
|
|
2
|
+
import ImageInfoModel, { ImageInfoData } from './ImageInfo.cjs';
|
|
3
|
+
import './Enum.cjs';
|
|
4
|
+
|
|
5
|
+
type SubItem = {
|
|
6
|
+
size: string;
|
|
7
|
+
quantity: number;
|
|
8
|
+
};
|
|
9
|
+
type LineItemAttributes = {
|
|
10
|
+
id: string;
|
|
11
|
+
productKey: string;
|
|
12
|
+
variantId: string;
|
|
13
|
+
name: LocalizedString;
|
|
14
|
+
attributes: {
|
|
15
|
+
color: Color;
|
|
16
|
+
};
|
|
17
|
+
primaryImage: ImageInfoData;
|
|
18
|
+
subItems: SubItem[];
|
|
19
|
+
basePrice: BasePrice;
|
|
20
|
+
priceTiers: PriceTier[];
|
|
21
|
+
};
|
|
22
|
+
type LineItemData = LineItemAttributes & {
|
|
23
|
+
totalQuantity: number;
|
|
24
|
+
priceTotals: {
|
|
25
|
+
subtotal: number;
|
|
26
|
+
mrpTotal: number;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Represents a line item within a shopping cart.
|
|
31
|
+
*/
|
|
32
|
+
declare class LineItemModel {
|
|
33
|
+
protected id: string;
|
|
34
|
+
protected productKey: string;
|
|
35
|
+
protected variantId: string;
|
|
36
|
+
protected name: LocalizedString;
|
|
37
|
+
protected attributes: {
|
|
38
|
+
color: Color;
|
|
39
|
+
};
|
|
40
|
+
protected primaryImage: ImageInfoModel;
|
|
41
|
+
protected subItems: SubItem[];
|
|
42
|
+
protected totalQuantity: number;
|
|
43
|
+
protected basePrice: BasePrice;
|
|
44
|
+
protected priceTotals: {
|
|
45
|
+
subtotal: number;
|
|
46
|
+
mrpTotal: number;
|
|
47
|
+
};
|
|
48
|
+
protected priceTiers: PriceTier[];
|
|
49
|
+
/**
|
|
50
|
+
* Creates an instance of LineItemModel.
|
|
51
|
+
* @param data - The initial line item attributes.
|
|
52
|
+
*/
|
|
53
|
+
constructor(data: LineItemAttributes);
|
|
54
|
+
/** Gets the unique identifier of the line item. */
|
|
55
|
+
getId(): string;
|
|
56
|
+
/** Gets the product key associated with this line item. */
|
|
57
|
+
getProductKey(): string;
|
|
58
|
+
/** Gets the product variant ID associated with this line item. */
|
|
59
|
+
getVariantId(): string;
|
|
60
|
+
/**
|
|
61
|
+
* Gets the full localized product name object.
|
|
62
|
+
* @returns A copy of the LocalizedString object for the name.
|
|
63
|
+
*/
|
|
64
|
+
getName(): LocalizedString;
|
|
65
|
+
/**
|
|
66
|
+
* Gets the product name for a specific locale, falling back to English ('en').
|
|
67
|
+
* @param locale - The desired locale code.
|
|
68
|
+
* @returns The name string for the specified locale.
|
|
69
|
+
*/
|
|
70
|
+
getName(locale: LocaleCode): string;
|
|
71
|
+
/** Gets the variant attributes. */
|
|
72
|
+
getAttributes(): {
|
|
73
|
+
color: Color;
|
|
74
|
+
};
|
|
75
|
+
/** Gets the image information model for this line item. */
|
|
76
|
+
getImage(): ImageInfoModel;
|
|
77
|
+
/** Gets the sub-items (size/quantity breakdown). */
|
|
78
|
+
getSubItems(): SubItem[];
|
|
79
|
+
/** Gets the total quantity for this line item across all sub-items. */
|
|
80
|
+
getTotalQuantity(): number;
|
|
81
|
+
/** Gets the base price for a single unit. */
|
|
82
|
+
getBasePrice(): BasePrice;
|
|
83
|
+
/** Gets the calculated price details (subtotal, mrpTotal) for this line item. */
|
|
84
|
+
getPriceTotals(): {
|
|
85
|
+
subtotal: number;
|
|
86
|
+
mrpTotal: number;
|
|
87
|
+
};
|
|
88
|
+
/** Gets the applicable price tiers for this product variant. */
|
|
89
|
+
getPriceTiers(): PriceTier[];
|
|
90
|
+
/**
|
|
91
|
+
* Recalculates the total quantity based on the quantities in subItems.
|
|
92
|
+
*/
|
|
93
|
+
protected recalculateTotalQuantity(): void;
|
|
94
|
+
/**
|
|
95
|
+
* Recalculates the line item's price (subtotal and mrpTotal)
|
|
96
|
+
* based on total quantity, base price, and applicable price tiers.
|
|
97
|
+
*/
|
|
98
|
+
protected recalculatePriceTotal(): void;
|
|
99
|
+
/**
|
|
100
|
+
* Gets a plain data object representing the line item's details.
|
|
101
|
+
* @returns LineItemData.
|
|
102
|
+
*/
|
|
103
|
+
getDetails(): LineItemData;
|
|
104
|
+
/**
|
|
105
|
+
* Adds or updates sub-items (e.g., sizes with quantities) to the line item.
|
|
106
|
+
* If a sub-item with the same size already exists, its quantity is either
|
|
107
|
+
* updated by adding the new quantity or replaced entirely, based on the `addQuantity` flag.
|
|
108
|
+
* Sub-items with a resulting quantity of 0 are removed.
|
|
109
|
+
* Recalculates total quantity and price totals afterwards.
|
|
110
|
+
*
|
|
111
|
+
* @param subItems - An array of `SubItem` objects to add or update.
|
|
112
|
+
* @param addQuantity - If true, adds the quantity from `subItem` to the existing quantity.
|
|
113
|
+
* If false, replaces the existing quantity with the one from `subItem`.
|
|
114
|
+
*/
|
|
115
|
+
addSubItems(subItems: SubItem[], addQuantity: boolean): void;
|
|
116
|
+
/**
|
|
117
|
+
* Resets the line item's properties to their default empty or initial state.
|
|
118
|
+
* Useful for clearing out line item data without creating a new instance.
|
|
119
|
+
* Recalculates total quantity and price totals afterwards (which will be zero).
|
|
120
|
+
*/
|
|
121
|
+
clearLineItem(): void;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export { type LineItemAttributes, type LineItemData, type SubItem, LineItemModel as default };
|