rerobe-js-orm 4.3.7 → 4.3.9

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.
@@ -45,20 +45,28 @@ class RefundFormState extends FormState_1.default {
45
45
  }
46
46
  updateDiscountsAndSubtotals() {
47
47
  const calculated = this.fields.refundLineItems.selectedValues.reduce((total, item) => {
48
- var _a, _b, _c, _d, _e, _f, _g;
48
+ var _a, _b, _c, _d, _e, _f, _g, _h;
49
49
  const lineItemPriceAmount = Number(item.lineItem.isOnSale === 'yes' ? item.lineItem.salePrice || 0 : (_a = item.lineItem.originalUnitPrice) === null || _a === void 0 ? void 0 : _a.amount);
50
50
  const lineItemPricePresentmentAmount = Number(item.lineItem.isOnSale === 'yes'
51
51
  ? ((_b = item.lineItem.presentmentSalePrice) === null || _b === void 0 ? void 0 : _b.amount) || 0
52
52
  : ((_c = item.lineItem.presentmentUnitPrice) === null || _c === void 0 ? void 0 : _c.amount) || 0);
53
+ // Calculate tax-adjusted prices if item is taxable
54
+ const taxAdjustedPriceAmount = item.lineItem.isTaxable && item.lineItem.taxRate
55
+ ? Number((lineItemPriceAmount * (1 + Number(item.lineItem.taxRate))).toFixed(2))
56
+ : lineItemPriceAmount;
57
+ const taxAdjustedPresentmentPriceAmount = item.lineItem.isTaxable && ((_d = item.lineItem.presentmentTaxPrice) === null || _d === void 0 ? void 0 : _d.amount)
58
+ ? Number((lineItemPricePresentmentAmount +
59
+ Number(item.lineItem.presentmentTaxPrice.amount) / Number(item.lineItem.quantity)).toFixed(2))
60
+ : lineItemPricePresentmentAmount;
53
61
  return {
54
- refundDiscount: total.refundDiscount + Number((_d = item.discountRefund) === null || _d === void 0 ? void 0 : _d.amount),
55
- refundCreditDiscount: total.refundCreditDiscount + Number((_e = item.creditDiscountRefund) === null || _e === void 0 ? void 0 : _e.amount),
56
- subtotalRefunded: total.subtotalRefunded + Number(lineItemPriceAmount * (item.quantityRefund + item.quantityCancel)),
62
+ refundDiscount: total.refundDiscount + Number((_e = item.discountRefund) === null || _e === void 0 ? void 0 : _e.amount),
63
+ refundCreditDiscount: total.refundCreditDiscount + Number((_f = item.creditDiscountRefund) === null || _f === void 0 ? void 0 : _f.amount),
64
+ subtotalRefunded: total.subtotalRefunded + Number(taxAdjustedPriceAmount * (item.quantityRefund + item.quantityCancel)),
57
65
  // Presentment:
58
- refundDiscountPresentment: total.refundDiscountPresentment + Number((_f = item.discountRefundPresentment) === null || _f === void 0 ? void 0 : _f.amount),
59
- refundCreditDiscountPresentment: total.refundCreditDiscountPresentment + Number((_g = item.creditDiscountRefundPresentment) === null || _g === void 0 ? void 0 : _g.amount),
66
+ refundDiscountPresentment: total.refundDiscountPresentment + Number((_g = item.discountRefundPresentment) === null || _g === void 0 ? void 0 : _g.amount),
67
+ refundCreditDiscountPresentment: total.refundCreditDiscountPresentment + Number((_h = item.creditDiscountRefundPresentment) === null || _h === void 0 ? void 0 : _h.amount),
60
68
  subtotalRefundedPresentment: total.subtotalRefundedPresentment +
61
- Number(lineItemPricePresentmentAmount * (item.quantityRefund + item.quantityCancel)), // Number(item.subtotalRefundPresentment?.amount || 0) + Number(item.subtotalCanceledPresentment?.amount || 0),
69
+ Number(taxAdjustedPresentmentPriceAmount * (item.quantityRefund + item.quantityCancel)),
62
70
  };
63
71
  }, {
64
72
  refundDiscount: 0,
@@ -268,17 +268,17 @@ class ReRobeProductHelpers {
268
268
  }
269
269
  static autoCreateMetaDescription(productObj) {
270
270
  var _a;
271
- const { color, productType, productStyle, condition, size, standardSize, brand, sizeComment, materialComposition, gender, } = productObj;
271
+ const { color, productType, productStyle = [], condition, size, standardSize, brand, sizeComment, materialComposition, gender, } = productObj;
272
272
  const materials = this.materialCompJoinedString(materialComposition);
273
273
  const fit = ((_a = options_1.sizeCommentOptions.find((option) => option.value === sizeComment)) === null || _a === void 0 ? void 0 : _a.label) || '';
274
- const joinedProductStyle = productStyle.join(', ');
274
+ const joinedProductStyle = Array.isArray(productStyle) ? productStyle.join(', ') : '';
275
275
  const elements = [
276
276
  gender && `Primary segment: ${gender}`,
277
277
  brand && `Brand: ${brand}`,
278
278
  size && `Size: ${standardSize ? standardSize : size}`,
279
279
  color && `Color: ${color}`,
280
280
  productType && `Type: ${productType}`,
281
- productStyle.length > 0 && `Style: ${joinedProductStyle}`,
281
+ joinedProductStyle && `Style: ${joinedProductStyle}`,
282
282
  condition && `Condition: ${condition}`,
283
283
  materials && `Material: ${materials}`,
284
284
  fit && `Fit: ${fit}`,
@@ -317,7 +317,7 @@ class ReRobeProductHelpers {
317
317
  Vi använder oss av "Tradera betalning" vilket innebär att du som köpare kan välja att betala med Swish, kort eller PayPal. ${merchantName}’s rabatter och erbjudanden gäller endast vid köp på vår hemsida samt via vår app.
318
318
  <br>
319
319
  <br>
320
- Tänk på att produkter kan ligga i flera varukorgar samtidigt. Om din vara står som slut/såld vid utcheckningen beror det på att någon annan hunnit före.
320
+ Tänk på att produkter kan ligga i flera varukorgar samtidigt. Om din vara står som "slut/såld" vid utcheckningen beror det på att någon annan hunnit före.
321
321
  </p>
322
322
 
323
323
  <p>
@@ -705,13 +705,26 @@ class ReRobeProductHelpers {
705
705
  productObj.isOnSale === 'yes' &&
706
706
  productObj.salePrice &&
707
707
  productObj.clearanceTimestamp;
708
- let price = Number(productObj.price).toFixed(2);
709
- if (targetMarketTaxRate && productObj.isTaxable === 'yes') {
710
- price = (Number(productObj.price) * (1 + targetMarketTaxRate)).toFixed(2);
708
+ let price = '0.00';
709
+ let salePrice = '0.00';
710
+ try {
711
+ const basePrice = Number(productObj.price);
712
+ const baseSalePrice = Number(productObj.salePrice || 0);
713
+ if (!isNaN(basePrice)) {
714
+ price = (targetMarketTaxRate && productObj.isTaxable === 'yes' ? basePrice * (1 + targetMarketTaxRate) : basePrice).toFixed(2);
715
+ }
716
+ if (!isNaN(baseSalePrice) && isOnSale) {
717
+ salePrice = (targetMarketTaxRate && productObj.isTaxable === 'yes'
718
+ ? baseSalePrice * (1 + targetMarketTaxRate)
719
+ : baseSalePrice).toFixed(2);
720
+ }
721
+ }
722
+ catch (error) {
723
+ // Keep default values if parsing fails
711
724
  }
712
725
  return {
713
- id: productObj.documentId,
714
- title: productObj.metaDataTitle || productObj.title,
726
+ id: String(productObj.documentId || ''),
727
+ title: productObj.metaDataTitle || productObj.title || '',
715
728
  description: productObj.description || '',
716
729
  link: `https://${primaryDomain}/products/${productObj.handle}`,
717
730
  image_link: productObj.imageUrls && productObj.imageUrls.length > 0 ? productObj.imageUrls[0] : '',
@@ -719,7 +732,7 @@ class ReRobeProductHelpers {
719
732
  cost_of_goods_sold: productObj.costPerItem
720
733
  ? `${Number(productObj.costPerItem).toFixed(2)} ${currency}`
721
734
  : undefined,
722
- sale_price: isOnSale ? `${Number(productObj.salePrice).toFixed(2)} ${currency}` : undefined,
735
+ sale_price: isOnSale ? `${salePrice} ${currency}` : undefined,
723
736
  brand: productObj.brand || 'Unknown',
724
737
  condition: 'used',
725
738
  availability: availabilityMapper(productObj.status),
@@ -790,20 +803,33 @@ class ReRobeProductHelpers {
790
803
  productObj.isOnSale === 'yes' &&
791
804
  productObj.salePrice &&
792
805
  productObj.clearanceTimestamp;
793
- let price = Number(productObj.price).toFixed(2);
794
- if (targetMarketTaxRate && productObj.isTaxable === 'yes') {
795
- price = (Number(productObj.price) * (1 + targetMarketTaxRate)).toFixed(2);
806
+ let price = '0.00';
807
+ let salePrice = '0.00';
808
+ try {
809
+ const basePrice = Number(productObj.price);
810
+ const baseSalePrice = Number(productObj.salePrice || 0);
811
+ if (!isNaN(basePrice)) {
812
+ price = (targetMarketTaxRate && productObj.isTaxable === 'yes' ? basePrice * (1 + targetMarketTaxRate) : basePrice).toFixed(2);
813
+ }
814
+ if (!isNaN(baseSalePrice) && isOnSale) {
815
+ salePrice = (targetMarketTaxRate && productObj.isTaxable === 'yes'
816
+ ? baseSalePrice * (1 + targetMarketTaxRate)
817
+ : baseSalePrice).toFixed(2);
818
+ }
819
+ }
820
+ catch (error) {
821
+ // Keep default values if parsing fails
796
822
  }
797
823
  return {
798
- id: productObj.documentId,
799
- title: productObj.metaDataTitle || productObj.title,
800
- description: productObj.metaDataDescription || this.autoCreateMetaDescription(productObj),
824
+ id: String(productObj.documentId || ''),
825
+ title: productObj.metaDataTitle || productObj.title || '',
826
+ description: productObj.metaDataDescription || this.autoCreateMetaDescription(productObj) || '',
801
827
  availability: availabilityMapper(productObj.status),
802
828
  condition: 'used',
803
829
  price: `${price} ${currency}`,
804
830
  link: `https://${primaryDomain}/products/${productObj.handle}`,
805
831
  image_link: productObj.imageUrls && productObj.imageUrls.length > 0 ? productObj.imageUrls[0] : '',
806
- sale_price: isOnSale ? `${Number(productObj.salePrice).toFixed(2)} ${currency}` : undefined,
832
+ sale_price: isOnSale ? `${salePrice} ${currency}` : undefined,
807
833
  brand: productObj.brand || 'Unknown',
808
834
  color: productObj.color || 'various',
809
835
  gender: genderMapper(productObj.gender),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "4.3.7",
3
+ "version": "4.3.9",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",