rerobe-js-orm 3.9.9 → 4.0.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.
|
@@ -364,26 +364,32 @@ class OrderHelpers {
|
|
|
364
364
|
return Number(price || 0) * Number(item.quantity);
|
|
365
365
|
})
|
|
366
366
|
.reduce((a, b) => a + b, 0); // Sum up the pre-tax prices of all items
|
|
367
|
-
// Step 2:
|
|
368
|
-
const discountedSubtotal = Math.max(preTaxSubtotal - orderDiscount, 0);
|
|
369
|
-
// Step 3: Calculate the total tax based on the discounted subtotal
|
|
367
|
+
// Step 2: Calculate the total tax based on the pre-tax subtotal
|
|
370
368
|
const totalTax = productsFullInfoWithQuantity
|
|
371
369
|
.map((item) => {
|
|
372
370
|
const price = item.product.isOnSale && item.product.clearanceTimestamp ? item.product.salePrice : item.product.price;
|
|
373
371
|
const basePrice = Number(price || 0) * Number(item.quantity);
|
|
374
|
-
|
|
375
|
-
const discountedPriceForItem = basePrice - orderDiscount * discountFactor; // Apply discount proportionally to this item
|
|
376
|
-
const taxableAmount = Math.max(discountedPriceForItem, 0); // Cap the discounted price at 0
|
|
377
|
-
// Calculate tax only for taxable items, based on the discounted price
|
|
372
|
+
// Calculate tax only for taxable items
|
|
378
373
|
if (item.isTaxable && item.taxRate) {
|
|
379
|
-
return
|
|
374
|
+
return basePrice * Number(item.taxRate);
|
|
380
375
|
}
|
|
381
376
|
return 0; // No tax for non-taxable items
|
|
382
377
|
})
|
|
383
378
|
.reduce((a, b) => a + b, 0); // Sum up the taxes for all items
|
|
384
|
-
// Step
|
|
385
|
-
const
|
|
386
|
-
|
|
379
|
+
// Step 3: Calculate subtotal with tax
|
|
380
|
+
const subtotalWithTax = preTaxSubtotal + totalTax;
|
|
381
|
+
// Step 4: Apply discount logic
|
|
382
|
+
let finalSubtotal;
|
|
383
|
+
if (orderDiscount >= preTaxSubtotal) {
|
|
384
|
+
// If the discount is greater than or equal to the pre-tax subtotal, the subtotal is 0 and no tax is applied
|
|
385
|
+
finalSubtotal = 0;
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
// If the discount is less than the pre-tax subtotal, apply it to the subtotal with tax
|
|
389
|
+
finalSubtotal = Math.max(subtotalWithTax - orderDiscount, 0);
|
|
390
|
+
}
|
|
391
|
+
// Step 5: Return the final total, rounded to the correct decimal places
|
|
392
|
+
return Number(this.toFixedPointPrice(finalSubtotal));
|
|
387
393
|
}
|
|
388
394
|
getSaleDiscountAmount(productsFullInfoWithQuantity) {
|
|
389
395
|
return productsFullInfoWithQuantity
|
package/lib/models/Order.js
CHANGED
|
@@ -276,6 +276,11 @@ class Order extends Base_1.default {
|
|
|
276
276
|
name: 'orderNumber',
|
|
277
277
|
type: 'int32',
|
|
278
278
|
},
|
|
279
|
+
{
|
|
280
|
+
facet: true,
|
|
281
|
+
name: 'orderNumberString',
|
|
282
|
+
type: 'string',
|
|
283
|
+
},
|
|
279
284
|
{
|
|
280
285
|
facet: true,
|
|
281
286
|
name: 'customerName',
|
|
@@ -393,6 +398,7 @@ class Order extends Base_1.default {
|
|
|
393
398
|
merchantId: this.utilities.sanitizeString(this.merchantId),
|
|
394
399
|
image: this.utilities.sanitizeString(image),
|
|
395
400
|
orderNumber: this.utilities.sanitizeNumber(this.orderNumber),
|
|
401
|
+
orderNumberString: this.utilities.sanitizeString(this.orderNumber),
|
|
396
402
|
customerName: this.utilities.sanitizeString(this.customerName),
|
|
397
403
|
customerEmail: this.utilities.sanitizeString(this.email),
|
|
398
404
|
totalPrice: this.utilities.sanitizeNumber(Number(this.totalPrice.amount) - Number(this.totalRefunded.amount)),
|