@pmcretail/mapper-library 0.0.33 → 0.0.35

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.
@@ -7719,7 +7719,7 @@
7719
7719
  var transactionPromotionObj = (/** @type {?} */ ({}));
7720
7720
  transactionPromotionObj.displayText = transactionPromotion.item_text ? transactionPromotion.item_text : '';
7721
7721
  transactionPromotionObj.name = transactionPromotion.coupon_code ? transactionPromotion.coupon_code : (transactionPromotion.item_text ? transactionPromotion.item_text : '');
7722
- transactionPromotionObj.promotionAmount = transactionPromotion.price ? -Math.abs(transactionPromotion.price) : 0;
7722
+ transactionPromotionObj.promotionAmount = transactionPromotion.price ? Math.abs(transactionPromotion.price) : 0;
7723
7723
  transactionPromotionObj.promotionId = transactionPromotion.promotion_id ? transactionPromotion.promotion_id : '';
7724
7724
  transactionPromotionObj.promotionInfo = transactionPromotion.item_text ? transactionPromotion.item_text : '';
7725
7725
  transactionPromotionObj.promotionType = transactionPromotion.applied_discount && transactionPromotion.applied_discount.type ? transactionPromotion.applied_discount.type : '';
@@ -7863,66 +7863,47 @@
7863
7863
  */
7864
7864
  function (txDoc, promotion) {
7865
7865
  var _this = this;
7866
- /** @type {?} */
7867
- var total = 0;
7868
- /** @type {?} */
7869
- var percentage = 0;
7870
- {
7871
- console.log("ebasket: transactionPromotionProductPortionCalc: trnsactionPromotion: " + JSON.stringify(promotion));
7872
- if (promotion.type === PROMOTION_TYPE.COUPON && promotion.subLevelType === PROMOTION_LEVEL.LINE) {
7873
- txDoc.basket.products.forEach((/**
7874
- * @param {?} product
7875
- * @return {?}
7876
- */
7877
- function (product) {
7878
- product = _this.validateProductItemDiscount(product);
7879
- if (promotion.trigger && promotion.trigger.length > 0) {
7880
- promotion.trigger.forEach((/**
7881
- * @param {?} t
7882
- * @return {?}
7883
- */
7884
- function (t) {
7885
- if (t.itemLineId === product.itemLineId.toString()) {
7886
- product.itemDiscounts.trnPromotionsPortion += t.promotionAmount;
7887
- }
7888
- }));
7889
- }
7890
- }));
7891
- }
7892
- else {
7893
- txDoc.basket.products.forEach((/**
7894
- * @param {?} p
7895
- * @return {?}
7896
- */
7897
- function (p) {
7898
- if (promotion.itemLineIds && promotion.itemLineIds.includes(p.itemLineId) && !p.giftCard) {
7899
- p = _this.validateProductItemDiscount(p);
7900
- /** @type {?} */
7901
- var productContributionInTotal = _this.numberUtilService.trimTo2Decimal2(p.itemDiscounts.trnDiscountsPortion) +
7902
- _this.numberUtilService.trimTo2Decimal2(p.itemDiscounts.trnPromotionsPortion) -
7903
- _this.numberUtilService.trimTo2Decimal2(p.itemDiscounts.refundPortion);
7904
- total += (p.total - _this.numberUtilService.trimTo2Decimal2(productContributionInTotal));
7905
- }
7906
- }));
7907
- console.log("ebasket: trnsactionPromotion: " + JSON.stringify(promotion) + ", selected products total: " + total);
7908
- txDoc.basket.products.forEach((/**
7909
- * @param {?} product
7910
- * @return {?}
7911
- */
7912
- function (product) {
7913
- product = _this.validateProductItemDiscount(product);
7866
+ console.log("ebasket: transactionPromotionProductPortionCalc: trnsactionPromotion: " + JSON.stringify(promotion));
7867
+ if (promotion.type === PROMOTION_TYPE.COUPON && promotion.subLevelType === PROMOTION_LEVEL.LINE) {
7868
+ txDoc.basket.products.forEach((/**
7869
+ * @param {?} product
7870
+ * @return {?}
7871
+ */
7872
+ function (product) {
7873
+ product = _this.validateProductItemDiscount(product);
7874
+ if (promotion.trigger && promotion.trigger.length > 0) {
7875
+ promotion.trigger.forEach((/**
7876
+ * @param {?} t
7877
+ * @return {?}
7878
+ */
7879
+ function (t) {
7880
+ if (t.itemLineId === product.itemLineId.toString()) {
7881
+ product.itemDiscounts.trnPromotionsPortion += t.promotionAmount;
7882
+ }
7883
+ }));
7884
+ }
7885
+ }));
7886
+ }
7887
+ else {
7888
+ txDoc.basket.products.forEach((/**
7889
+ * @param {?} product
7890
+ * @return {?}
7891
+ */
7892
+ function (product) {
7893
+ product = _this.validateProductItemDiscount(product);
7894
+ if (promotion.itemLineIds.includes(+product.itemLineId)) {
7914
7895
  /** @type {?} */
7915
- var productContributionInTotal = _this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.trnDiscountsPortion) +
7916
- _this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.trnPromotionsPortion) -
7917
- _this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.refundPortion);
7918
- if (promotion.itemLineIds.includes(product.itemLineId)) {
7919
- percentage = ((product.total - _this.numberUtilService.trimTo2Decimal2(productContributionInTotal)) / total) * 100;
7920
- product.itemDiscounts.trnPromotionsPortion +=
7921
- (promotion.promotionAmount * percentage) / 100;
7922
- product.itemDiscounts.trnPromotionsPortion = _this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.trnPromotionsPortion);
7923
- }
7924
- }));
7925
- }
7896
+ var productItem = _this.orderDetails.product_items.find((/**
7897
+ * @param {?} productItem
7898
+ * @return {?}
7899
+ */
7900
+ function (productItem) { return productItem.product_id === product.SKU; }));
7901
+ /** @type {?} */
7902
+ var transactionPromotionPortion = (productItem && productItem.price_after_item_discount && productItem.price_after_order_discount) ?
7903
+ (productItem.price_after_item_discount - productItem.price_after_order_discount) : 0;
7904
+ product.itemDiscounts.trnPromotionsPortion += _this.numberUtilService.trimTo2Decimal2(transactionPromotionPortion);
7905
+ }
7906
+ }));
7926
7907
  }
7927
7908
  return txDoc;
7928
7909
  };