rerobe-js-orm 3.9.6 → 3.9.8
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/lib/factories/ProductCollection/ProductCollectionFromFormState.js +3 -3
- package/lib/form-states/ProductCollection/ProductCollectionFormState.js +2 -0
- package/lib/helpers/OrderHelpers.d.ts +1 -1
- package/lib/helpers/OrderHelpers.js +14 -7
- package/lib/models/ProductCollection.d.ts +1 -0
- package/lib/models/ProductCollection.js +8 -0
- package/lib/types/product-collection-types.d.ts +3 -0
- package/package.json +1 -1
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ProductCollectionFactory_1 = require("./ProductCollectionFactory");
|
|
4
4
|
const ProductCollection_1 = require("../../models/ProductCollection");
|
|
5
|
-
|
|
6
|
-
const lodash_1 = require("lodash");
|
|
5
|
+
const slug = require("slug");
|
|
7
6
|
class ProductCollectionFromFormState extends ProductCollectionFactory_1.default {
|
|
8
7
|
createProductCollection(fs) {
|
|
9
8
|
var _a;
|
|
10
9
|
let collectionId = fs.fields.collectionId.inputValue;
|
|
11
10
|
if (!collectionId) {
|
|
12
|
-
collectionId = (
|
|
11
|
+
collectionId = slug(fs.fields.title.inputValue);
|
|
13
12
|
}
|
|
14
13
|
const productCollectionAttributes = {
|
|
15
14
|
documentId: ((_a = fs.props) === null || _a === void 0 ? void 0 : _a.documentId) || '',
|
|
@@ -23,6 +22,7 @@ class ProductCollectionFromFormState extends ProductCollectionFactory_1.default
|
|
|
23
22
|
refinements: fs.fields.refinements.selectedValue || {},
|
|
24
23
|
tags: fs.fields.tags.selectedValues || [],
|
|
25
24
|
collectionId,
|
|
25
|
+
isExclusive: fs.fields.isExclusive.selectedValue || '',
|
|
26
26
|
};
|
|
27
27
|
return new ProductCollection_1.default(Object.assign({}, productCollectionAttributes));
|
|
28
28
|
}
|
|
@@ -4,6 +4,7 @@ const FormState_1 = require("../FormState");
|
|
|
4
4
|
const ProductCollection_1 = require("../../models/ProductCollection");
|
|
5
5
|
const ProductCollectionFromFormState_1 = require("../../factories/ProductCollection/ProductCollectionFromFormState");
|
|
6
6
|
const slug = require("slug");
|
|
7
|
+
const options_1 = require("../Product/options");
|
|
7
8
|
class ProductCollectionFormState extends FormState_1.default {
|
|
8
9
|
constructor(props, opts) {
|
|
9
10
|
super();
|
|
@@ -19,6 +20,7 @@ class ProductCollectionFormState extends FormState_1.default {
|
|
|
19
20
|
this.fields.refinements = this.fieldFactory('singleSelect', 'refinements');
|
|
20
21
|
this.fields.tags = this.fieldFactory('multiSelect', 'tags', []);
|
|
21
22
|
this.fields.collectionId = this.fieldFactory('textInput', 'collectionId');
|
|
23
|
+
this.fields.isExclusive = this.fieldFactory('singleSelect', 'isExclusive', options_1.productYesNoOptions);
|
|
22
24
|
}
|
|
23
25
|
createProductCollection() {
|
|
24
26
|
const productCollectionFactory = new ProductCollectionFromFormState_1.default();
|
|
@@ -26,7 +26,7 @@ export default class OrderHelpers {
|
|
|
26
26
|
currency: string;
|
|
27
27
|
}): string;
|
|
28
28
|
getSubtotalWithoutSalePrice(productsFullInfoWithQuantity?: ProductsFullInfoWithQuantity): number;
|
|
29
|
-
getSubtotalWithSalePriceIncluded(productsFullInfoWithQuantity?: ProductsFullInfoWithQuantity): number;
|
|
29
|
+
getSubtotalWithSalePriceIncluded(productsFullInfoWithQuantity?: ProductsFullInfoWithQuantity, orderDiscount?: number): number;
|
|
30
30
|
getSaleDiscountAmount(productsFullInfoWithQuantity: ProductsFullInfoWithQuantity): number;
|
|
31
31
|
preparePresentmentData({ merchantName, merchantCurrency, presentmentCurrencyCode, productsFullInfoWithQuantity, currencyConverter, saleDiscountAmount, creditDiscountAmount, additionalDiscount, shippingPrice, itemsTax, shippingFeeTax, subTotalWithSalePriceIncluded, totalIncludingShipping, totalIncludingShippingAndTaxes, }: {
|
|
32
32
|
merchantName: string;
|
|
@@ -351,23 +351,30 @@ class OrderHelpers {
|
|
|
351
351
|
.reduce((a, b) => a + b, 0);
|
|
352
352
|
return Number(this.toFixedPointPrice(cumsum));
|
|
353
353
|
}
|
|
354
|
-
getSubtotalWithSalePriceIncluded(productsFullInfoWithQuantity) {
|
|
354
|
+
getSubtotalWithSalePriceIncluded(productsFullInfoWithQuantity, orderDiscount = 0) {
|
|
355
355
|
if (!productsFullInfoWithQuantity || productsFullInfoWithQuantity.length === 0) {
|
|
356
356
|
return 0;
|
|
357
357
|
}
|
|
358
|
-
|
|
358
|
+
// Step 1: Calculate the total before applying the order-wide discount
|
|
359
|
+
const totalBeforeDiscount = productsFullInfoWithQuantity
|
|
359
360
|
.map((item) => {
|
|
360
361
|
// Determine if the product is on sale and set the price accordingly
|
|
361
362
|
const price = item.product.isOnSale && item.product.clearanceTimestamp ? item.product.salePrice : item.product.price;
|
|
363
|
+
// Base price for this item before tax and discounts
|
|
362
364
|
const basePrice = Number(price || 0) * Number(item.quantity);
|
|
365
|
+
let totalPrice = basePrice;
|
|
366
|
+
// Apply tax if the item is taxable
|
|
363
367
|
if (item.isTaxable && item.taxRate) {
|
|
364
|
-
const taxAmount = basePrice * Number(item.taxRate); // Calculate
|
|
365
|
-
|
|
368
|
+
const taxAmount = basePrice * Number(item.taxRate); // Calculate tax based on base price
|
|
369
|
+
totalPrice += taxAmount; // Add tax to the base price
|
|
366
370
|
}
|
|
367
|
-
return
|
|
371
|
+
return totalPrice; // Return the total price (including tax if applicable)
|
|
368
372
|
})
|
|
369
|
-
.reduce((a, b) => a + b, 0);
|
|
370
|
-
|
|
373
|
+
.reduce((a, b) => a + b, 0); // Sum up the totals for all items
|
|
374
|
+
// Step 2: Apply the order-wide discount, ensuring it doesn't exceed the total before discount
|
|
375
|
+
const totalAfterDiscount = Math.max(totalBeforeDiscount - orderDiscount, 0);
|
|
376
|
+
// Step 3: Return the final subtotal, rounded to fixed decimal points
|
|
377
|
+
return Number(this.toFixedPointPrice(totalAfterDiscount));
|
|
371
378
|
}
|
|
372
379
|
getSaleDiscountAmount(productsFullInfoWithQuantity) {
|
|
373
380
|
return productsFullInfoWithQuantity
|
|
@@ -13,6 +13,7 @@ export default class ProductCollection extends Base {
|
|
|
13
13
|
refinements: ProductRefinements;
|
|
14
14
|
tags: string[];
|
|
15
15
|
collectionId: string;
|
|
16
|
+
isExclusive: string;
|
|
16
17
|
constructor(props?: any);
|
|
17
18
|
toObj(): ProductCollectionType;
|
|
18
19
|
generateSchemaForTypesense(name?: string): {
|
|
@@ -17,6 +17,7 @@ class ProductCollection extends Base_1.default {
|
|
|
17
17
|
this.tags = (props === null || props === void 0 ? void 0 : props.tags) || [];
|
|
18
18
|
this.collectionId = (props === null || props === void 0 ? void 0 : props.collectionId) || '';
|
|
19
19
|
this.imageUrls = (props === null || props === void 0 ? void 0 : props.imageUrls) || [];
|
|
20
|
+
this.isExclusive = (props === null || props === void 0 ? void 0 : props.isExclusive) || '';
|
|
20
21
|
}
|
|
21
22
|
toObj() {
|
|
22
23
|
const productCollectionObj = {
|
|
@@ -33,6 +34,7 @@ class ProductCollection extends Base_1.default {
|
|
|
33
34
|
tags: this.tags,
|
|
34
35
|
collectionId: this.collectionId,
|
|
35
36
|
imageUrls: this.imageUrls,
|
|
37
|
+
isExclusive: this.isExclusive,
|
|
36
38
|
};
|
|
37
39
|
return productCollectionObj;
|
|
38
40
|
}
|
|
@@ -185,6 +187,11 @@ class ProductCollection extends Base_1.default {
|
|
|
185
187
|
name: 'collectionId',
|
|
186
188
|
type: 'string',
|
|
187
189
|
},
|
|
190
|
+
{
|
|
191
|
+
facet: true,
|
|
192
|
+
name: 'isExclusive',
|
|
193
|
+
type: 'string',
|
|
194
|
+
},
|
|
188
195
|
],
|
|
189
196
|
name: 'dev_productCollections_20220726',
|
|
190
197
|
};
|
|
@@ -218,6 +225,7 @@ class ProductCollection extends Base_1.default {
|
|
|
218
225
|
tags: this.utilities.sanitzeStringArr(this.tags),
|
|
219
226
|
imageUrls: this.utilities.sanitzeStringArr(this.imageUrls),
|
|
220
227
|
collectionId: this.utilities.sanitizeString(this.collectionId),
|
|
228
|
+
isExclusive: this.utilities.sanitizeString(this.isExclusive),
|
|
221
229
|
};
|
|
222
230
|
return stagedObj;
|
|
223
231
|
}
|
|
@@ -49,6 +49,7 @@ type ProductCollectionType = {
|
|
|
49
49
|
tags: string[];
|
|
50
50
|
collectionId: string;
|
|
51
51
|
imageUrls: string[];
|
|
52
|
+
isExclusive: string;
|
|
52
53
|
};
|
|
53
54
|
type CompleteProductCollection = ProductCollectionType & {
|
|
54
55
|
[key: string]: any;
|
|
@@ -64,6 +65,7 @@ type ProductCollectionFormFields = {
|
|
|
64
65
|
tags: MultiSelectFormField<string>;
|
|
65
66
|
imageUrls: MultiSelectFormField<string>;
|
|
66
67
|
collectionId: TextInputFormField<string>;
|
|
68
|
+
isExclusive: SingleSelectFormField<string>;
|
|
67
69
|
};
|
|
68
70
|
type TypesenseProductCollectionObj = {
|
|
69
71
|
id: string;
|
|
@@ -93,4 +95,5 @@ type TypesenseProductCollectionObj = {
|
|
|
93
95
|
tags: string[];
|
|
94
96
|
imageUrls: string[];
|
|
95
97
|
collectionId: string;
|
|
98
|
+
isExclusive: string;
|
|
96
99
|
};
|