@pmcretail/mapper-library 0.0.46 → 0.0.47

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.
@@ -75,6 +75,7 @@ var PROVIDERS;
75
75
  (function (PROVIDERS) {
76
76
  PROVIDERS["SALESFORCE"] = "Salesforce";
77
77
  PROVIDERS["MAGENTO"] = "Magento";
78
+ PROVIDERS["MAGENTO2"] = "Magento2";
78
79
  })(PROVIDERS || (PROVIDERS = {}));
79
80
  var PROMOTION_LEVEL;
80
81
  (function (PROMOTION_LEVEL) {
@@ -3490,10 +3491,10 @@ class WebReturnSalesforceMapperBuilderClass {
3490
3491
  }
3491
3492
  }
3492
3493
 
3493
- class WebReturnMagentoV2RestMapperBuilderClass {
3494
+ class WebReturnMagento2RestV1MapperBuilderClass {
3494
3495
  constructor(orderDetails, currencyPipe) {
3495
3496
  this.currencyPipe = currencyPipe;
3496
- this.className = "WebReturnMagentoV2RestMapperBuilderClass";
3497
+ this.className = "WebReturnMagento2RestV1MapperBuilderClass";
3497
3498
  this.webReturnObject = {
3498
3499
  id: '',
3499
3500
  orgCode: "",
@@ -3520,7 +3521,8 @@ class WebReturnMagentoV2RestMapperBuilderClass {
3520
3521
  postCode: '',
3521
3522
  noCustomerSelected: false
3522
3523
  },
3523
- currentTransactionDetails: {}
3524
+ currentTransactionDetails: {},
3525
+ externalTransactionDetails: []
3524
3526
  };
3525
3527
  if (orderDetails) {
3526
3528
  this.orderDetails = orderDetails;
@@ -3528,8 +3530,7 @@ class WebReturnMagentoV2RestMapperBuilderClass {
3528
3530
  this.numberUtilService = new NumberUtilService(currencyPipe);
3529
3531
  }
3530
3532
  webReturnCommonMapper() {
3531
- AppLoggerService.logDebug(this.className, "webReturnCommonMapper", "webReturnCommonMapper started...");
3532
- // this.webReturnObject['type'] = TRANSACTION_TYPE.WEB_RETURNS; // TODO
3533
+ AppLoggerService.logDebug(this.className, "webReturnCommonMapper", "Mapping started...");
3533
3534
  this.webReturnObject['datetime'] = this.getUTCDateTime(this.orderDetails.updated_at);
3534
3535
  this.webReturnObject.baseCurrency = this.orderDetails.order_currency_code;
3535
3536
  this.webReturnObject.subsidiaryId = '1';
@@ -3539,167 +3540,173 @@ class WebReturnMagentoV2RestMapperBuilderClass {
3539
3540
  this.webReturnObject.updatedAt = this.getUTCDateTime(this.orderDetails.updated_at);
3540
3541
  this.webReturnObject.transCompletedAt = this.getUTCDateTime(this.orderDetails.updated_at);
3541
3542
  this.webReturnObject['externalTransactionId'] = this.orderDetails.increment_id;
3542
- AppLoggerService.logDebug(this.className, "webReturnCommonMapper", "webReturnCommonMapper ended...");
3543
+ AppLoggerService.logDebug(this.className, "webReturnCommonMapper", "Mapping ended...");
3543
3544
  return this;
3544
3545
  }
3545
- // getDeliveryMethod() {
3546
- // if(this.orderDetails.shipments && this.orderDetails.shipments.length > 0) {
3547
- // const shipToStoreShipment = this.orderDetails.shipments.find(shipment => shipment.c_fromStoreId);
3548
- // if(shipToStoreShipment) return DELIVERY_METHODS.SHIP_TO_STORE;
3549
- // else return DELIVERY_METHODS.DELIVERY;
3550
- // } else {
3551
- // return '';
3552
- // }
3553
- // }
3554
3546
  product() {
3555
- AppLoggerService.logDebug(this.className, "product", "product mapping started...");
3556
- this.webReturnObject.basket['products'] = [];
3557
- if (this.orderDetails.items && this.orderDetails.items.length > 0) {
3558
- let index = 0;
3559
- this.orderDetails.items.forEach((product) => {
3560
- if (product && product.base_price) {
3561
- const productObj = {
3562
- description: product.name ? product.name : '',
3563
- SKU: product.sku ? product.sku : '',
3564
- quantity: product.qty_ordered ? product.qty_ordered : 0,
3565
- refundedQuantity: product.qty_refunded ? product.qty_refunded : 0,
3566
- price: product.base_price ? product.base_price : 0,
3567
- itemLineId: (index + 1).toString(),
3568
- externalItemLineId: product.item_id ? product.item_id : (index + 1).toString(),
3569
- // deliveryMethod: this.getDeliveryMethod().toString(),
3570
- totalLinePrice: (product.qty_ordered && product.base_price) ? (product.qty_ordered * product.base_price) : 0
3571
- };
3572
- this.webReturnObject.basket['products'].push(productObj);
3573
- index++;
3574
- }
3547
+ var _a;
3548
+ AppLoggerService.logDebug(this.className, "product", "Mapping started...");
3549
+ this.webReturnObject.basket['products'] = ((_a = this.orderDetails.items) === null || _a === void 0 ? void 0 : _a.filter(product => product === null || product === void 0 ? void 0 : product.base_price).map((product, index) => {
3550
+ var _a, _b;
3551
+ return ({
3552
+ description: product.name || '',
3553
+ SKU: product.sku || '',
3554
+ quantity: product.qty_ordered || 0,
3555
+ refundedQuantity: product.qty_refunded || 0,
3556
+ price: product.base_price || 0,
3557
+ itemLineId: (index + 1).toString(),
3558
+ externalItemLineId: product.item_id || (index + 1).toString(),
3559
+ totalLinePrice: ((_a = product.qty_ordered) !== null && _a !== void 0 ? _a : 0) * ((_b = product.base_price) !== null && _b !== void 0 ? _b : 0),
3560
+ refundedTotal: product.amount_refunded || 0
3575
3561
  });
3576
- }
3577
- AppLoggerService.logDebug(this.className, "product", "product mapping ended...");
3562
+ })) || [];
3563
+ AppLoggerService.logDebug(this.className, "product", "Mapping ended...");
3578
3564
  return this;
3579
3565
  }
3580
3566
  linePromotion() {
3581
- AppLoggerService.logDebug(this.className, "linePromotion", "linePromotion mapping started...");
3582
- this.webReturnObject.basket['linePromotion'] = [];
3583
- if (this.orderDetails.items && this.orderDetails.items.length > 0) {
3584
- let index = 0;
3585
- this.orderDetails.items.forEach((product) => {
3586
- if (product && product.base_price) {
3587
- let linePromotionObj = {};
3588
- let trigger = {};
3589
- trigger.itemLineId = (index + 1).toString();
3590
- trigger.quantity = product.qty_ordered ? product.qty_ordered : 0;
3591
- linePromotionObj.trigger = [];
3592
- linePromotionObj.trigger.push(trigger);
3593
- linePromotionObj.itemLineId = index + 1;
3594
- linePromotionObj.promotionId = '';
3595
- linePromotionObj.displayText = this.orderDetails.coupon_code ? this.orderDetails.coupon_code : '';
3596
- linePromotionObj.promotionType = '';
3597
- linePromotionObj.promotionAmount = product.discount_amount ? product.discount_amount : 0;
3598
- linePromotionObj.name = this.orderDetails.coupon_code ? this.orderDetails.coupon_code : '';
3599
- ;
3600
- linePromotionObj.promotionInfo = '';
3601
- linePromotionObj.promotionLinePrice = product.row_total ? product.row_total : 0;
3602
- this.webReturnObject.basket.linePromotion.push(linePromotionObj);
3603
- index++;
3604
- }
3605
- });
3606
- }
3607
- AppLoggerService.logDebug(this.className, "linePromotion", "linePromotion mapping ended...");
3567
+ var _a;
3568
+ AppLoggerService.logDebug(this.className, "linePromotion", "Mapping started...");
3569
+ this.webReturnObject.basket['linePromotion'] = ((_a = this.orderDetails.items) === null || _a === void 0 ? void 0 : _a.filter(product => (product === null || product === void 0 ? void 0 : product.base_price) && product.discount_amount).map((product, index) => ({
3570
+ trigger: [{
3571
+ itemLineId: (index + 1).toString(),
3572
+ quantity: product.qty_ordered || 0
3573
+ }],
3574
+ itemLineId: index + 1,
3575
+ promotionId: '',
3576
+ displayText: this.orderDetails.coupon_code || '',
3577
+ promotionType: '',
3578
+ promotionAmount: product.discount_amount || 0,
3579
+ name: this.orderDetails.coupon_code || '',
3580
+ promotionInfo: '',
3581
+ promotionLinePrice: product.row_total || 0
3582
+ }))) || [];
3583
+ AppLoggerService.logDebug(this.className, "linePromotion", "Mapping ended...");
3608
3584
  return this;
3609
3585
  }
3610
3586
  customer() {
3611
- AppLoggerService.logDebug(this.className, "customer", "customer mapping started...");
3612
- this.webReturnObject.customer.id = this.orderDetails.customer_id ? this.orderDetails.customer_id : '';
3613
- this.webReturnObject.customer.email = this.orderDetails.customer_email ? this.orderDetails.customer_email : '';
3614
- this.webReturnObject.customer.firstName = this.orderDetails.customer_firstname ? this.orderDetails.customer_firstname : '';
3615
- this.webReturnObject.customer.lastName = this.orderDetails.customer_lastname ? this.orderDetails.customer_lastname : '';
3616
- const isShipping = this.orderDetails.extension_attributes &&
3617
- Object.values(this.orderDetails.extension_attributes).length > 0 && this.orderDetails.extension_attributes.shipping_assignments &&
3618
- this.orderDetails.extension_attributes.shipping_assignments.length > 0;
3619
- if (isShipping) {
3620
- this.orderDetails.extension_attributes.shipping_assignments.forEach(shipment => {
3621
- if (shipment.shipping && Object.values(shipment.shipping) && shipment.shipping.address && Object.values(shipment.shipping.address)) {
3622
- const address = shipment.shipping.address;
3623
- let shippingAddressObj = {};
3624
- shippingAddressObj.id = address.customer_address_id ? address.customer_address_id : '';
3625
- shippingAddressObj.countryCode = address.country_id ? address.country_id : '';
3626
- if (address.street && address.street.length > 0) {
3627
- shippingAddressObj.address1 = address.street[0] ? address.street[0] : '';
3628
- shippingAddressObj.address2 = address.street[1] ? address.street[1] : '';
3629
- shippingAddressObj.address3 = address.street[2] ? address.street[2] : '';
3630
- }
3631
- shippingAddressObj.city = address.city ? address.city : '';
3632
- shippingAddressObj.country = '';
3633
- shippingAddressObj.postCode = address.postcode ? address.postcode : '';
3634
- this.webReturnObject.customer.shippingAddress.push(shippingAddressObj);
3635
- }
3587
+ var _a, _b, _c, _d;
3588
+ AppLoggerService.logDebug(this.className, "customer", "Mapping started...");
3589
+ const { orderDetails, webReturnObject } = this;
3590
+ webReturnObject.customer = {
3591
+ id: orderDetails.customer_id || '',
3592
+ email: orderDetails.customer_email || '',
3593
+ firstName: orderDetails.customer_firstname || '',
3594
+ lastName: orderDetails.customer_lastname || '',
3595
+ shippingAddress: [],
3596
+ billingAddress: []
3597
+ };
3598
+ const shippingAssignments = ((_a = orderDetails.extension_attributes) === null || _a === void 0 ? void 0 : _a.shipping_assignments) || [];
3599
+ webReturnObject.customer.shippingAddress = shippingAssignments
3600
+ .filter(shipment => { var _a; return (_a = shipment === null || shipment === void 0 ? void 0 : shipment.shipping) === null || _a === void 0 ? void 0 : _a.address; })
3601
+ .map(shipment => {
3602
+ var _a, _b, _c;
3603
+ const address = shipment.shipping.address;
3604
+ return {
3605
+ id: address.customer_address_id || '',
3606
+ countryCode: address.country_id || '',
3607
+ address1: ((_a = address.street) === null || _a === void 0 ? void 0 : _a[0]) || '',
3608
+ address2: ((_b = address.street) === null || _b === void 0 ? void 0 : _b[1]) || '',
3609
+ address3: ((_c = address.street) === null || _c === void 0 ? void 0 : _c[2]) || '',
3610
+ city: address.city || '',
3611
+ country: '',
3612
+ postCode: address.postcode || ''
3613
+ };
3614
+ });
3615
+ const billingAddress = orderDetails.billing_address;
3616
+ if (billingAddress) {
3617
+ webReturnObject.customer.billingAddress.push({
3618
+ id: billingAddress.customer_address_id || '',
3619
+ countryCode: billingAddress.country_id || '',
3620
+ address1: ((_b = billingAddress.street) === null || _b === void 0 ? void 0 : _b[0]) || '',
3621
+ address2: ((_c = billingAddress.street) === null || _c === void 0 ? void 0 : _c[1]) || '',
3622
+ address3: ((_d = billingAddress.street) === null || _d === void 0 ? void 0 : _d[2]) || '',
3623
+ city: billingAddress.city || '',
3624
+ country: '',
3625
+ postCode: billingAddress.postcode || ''
3636
3626
  });
3637
3627
  }
3638
- if (this.orderDetails.billing_address && Object.values(this.orderDetails.billing_address).length > 0) {
3639
- const address = this.orderDetails.billing_address;
3640
- let billingAddressObj = {};
3641
- billingAddressObj.id = address.customer_address_id ? address.customer_address_id : '';
3642
- billingAddressObj.countryCode = address.country_id ? address.country_id : '';
3643
- if (address.street && address.street.length > 0) {
3644
- billingAddressObj.address1 = address.street[0] ? address.street[0] : '';
3645
- billingAddressObj.address2 = address.street[1] ? address.street[1] : '';
3646
- billingAddressObj.address3 = address.street[2] ? address.street[2] : '';
3647
- }
3648
- billingAddressObj.city = address.city ? address.city : '';
3649
- billingAddressObj.country = '';
3650
- billingAddressObj.postCode = address.postcode ? address.postcode : '';
3651
- this.webReturnObject.customer.shippingAddress.push(billingAddressObj);
3652
- }
3653
- // let shipmentDetails = [] as ShipmentDetails[];
3654
- // this.orderDetails.shipments.forEach(
3655
- // shipment => {
3656
- // let shipmentDetailsObj = {} as ShipmentDetails;
3657
- // shipmentDetailsObj.id = shipment.shipment_id ? shipment.shipment_id : '';
3658
- // shipmentDetailsObj.deliveryGroup = shipment.shipment_id ? shipment.shipment_id : '';
3659
- // shipmentDetails.push(shipmentDetailsObj);
3660
- // }
3661
- // );
3662
- // customerObj.shipmentDetails = shipmentDetails;
3663
- // this.webReturnObject.customer = customerObj;
3664
- AppLoggerService.logDebug(this.className, "customer", "customer mapping ended...");
3628
+ AppLoggerService.logDebug(this.className, "customer", "Mpping ended...");
3665
3629
  return this;
3666
3630
  }
3667
3631
  isInStoreOrder() {
3668
- AppLoggerService.logDebug(this.className, "isInStoreOrder", "isInStoreOrder mapping started...");
3632
+ AppLoggerService.logDebug(this.className, "isInStoreOrder", "Mapping started...");
3669
3633
  this.webReturnObject.isInStoreOrder = false;
3670
- AppLoggerService.logDebug(this.className, "isInStoreOrder", "isInStoreOrder mapping ended...");
3671
- return this;
3672
- }
3673
- externalTransactionDetails() {
3674
- AppLoggerService.logDebug(this.className, "externalTransactionDetails", "externalTransactionDetails mapping started...");
3675
- let externalTransactionDetails = [];
3676
- let externalTransactionDetailsObj = {};
3677
- let transactionInfo = {};
3678
- externalTransactionDetailsObj.uniqueId = this.orderDetails.increment_id ? this.orderDetails.increment_id : '';
3679
- externalTransactionDetailsObj.providerType = PROVIDERS.MAGENTO;
3680
- externalTransactionDetails.push(externalTransactionDetailsObj);
3681
- this.webReturnObject.externalTransactionDetails = externalTransactionDetails;
3682
- AppLoggerService.logDebug(this.className, "externalTransactionDetails", "externalTransactionDetails mapping ended...");
3634
+ AppLoggerService.logDebug(this.className, "isInStoreOrder", "Mapping ended...");
3635
+ return this;
3636
+ }
3637
+ externalTransactionDetails(invoiceId) {
3638
+ AppLoggerService.logDebug(this.className, "externalTransactionDetails", "Mapping started...");
3639
+ const coupon = this.orderDetails.coupon_code
3640
+ ? { name: this.orderDetails.coupon_code, id: this.orderDetails.coupon_code }
3641
+ : null;
3642
+ const externalTransactionDetailsObj = {
3643
+ uniqueId: this.orderDetails.increment_id || '',
3644
+ providerType: PROVIDERS.MAGENTO2,
3645
+ transactionInfo: { invoiceId: (invoiceId === null || invoiceId === void 0 ? void 0 : invoiceId.toString()) || '' },
3646
+ coupons: coupon ? [coupon] : []
3647
+ };
3648
+ this.webReturnObject.externalTransactionDetails.push(externalTransactionDetailsObj);
3649
+ AppLoggerService.logDebug(this.className, "externalTransactionDetails", "Mapping ended...");
3683
3650
  return this;
3684
3651
  }
3685
3652
  basketSummary() {
3686
- AppLoggerService.logDebug(this.className, "basketSummary", "basketSummary mapping started...");
3687
- let basketSummary = {};
3688
- let basketSummaryWebOrder = {};
3689
- const linePromotionTotal = this.webReturnObject.basket.linePromotion.map(linePromotion => linePromotion.promotionAmount).reduce((accumulator, currentValue) => accumulator + currentValue, 0);
3690
- const transactionPromotionTotal = 0;
3691
- basketSummary.discountTotal = linePromotionTotal + transactionPromotionTotal;
3692
- basketSummary.VATTotal = this.orderDetails.tax_amount ? this.orderDetails.tax_amount : 0;
3693
- basketSummary.saleTotal = this.orderDetails.subtotal ? this.orderDetails.subtotal : 0;
3694
- basketSummary.basketTotal = (this.orderDetails.subtotal && this.orderDetails.total_online_refunded) ? (this.orderDetails.subtotal - this.orderDetails.total_online_refunded) : 0;
3695
- basketSummary.totalItems = this.orderDetails.total_qty_ordered ? this.orderDetails.total_qty_ordered.length : 0;
3696
- basketSummary.shippingTotal = this.orderDetails.shipping_incl_tax ? this.orderDetails.shipping_incl_tax : 0;
3697
- basketSummary.basketTotalWithShippingTotal = this.orderDetails.total_invoiced ? this.orderDetails.total_invoiced : 0;
3698
- basketSummaryWebOrder.shippingTotal = this.orderDetails.shipping_incl_tax ? this.orderDetails.shipping_incl_tax : 0;
3699
- basketSummaryWebOrder.basketTotalWithShippingTotal = this.orderDetails.total_invoiced ? this.orderDetails.total_invoiced : 0;
3700
- basketSummary.webOrder = basketSummaryWebOrder;
3701
- this.webReturnObject.basketSummary = basketSummary;
3702
- AppLoggerService.logDebug(this.className, "basketSummary", "basketSummary mapping ended...");
3653
+ var _a;
3654
+ AppLoggerService.logDebug(this.className, "basketSummary", "Mapping started...");
3655
+ const { orderDetails, webReturnObject } = this;
3656
+ const basketSummary = {
3657
+ discountTotal: orderDetails.discount_amount || 0,
3658
+ VATTotal: orderDetails.tax_amount || 0,
3659
+ saleTotal: orderDetails.subtotal || 0,
3660
+ basketTotal: (orderDetails.subtotal || 0) - (orderDetails.total_online_refunded || 0),
3661
+ totalItems: (_a = orderDetails.total_qty_ordered) !== null && _a !== void 0 ? _a : 0,
3662
+ refundTotal: orderDetails.total_online_refunded || 0,
3663
+ shippingTotal: orderDetails.shipping_incl_tax || 0,
3664
+ basketTotalWithShippingTotal: orderDetails.total_invoiced || 0,
3665
+ webOrder: {
3666
+ shippingTotal: orderDetails.shipping_incl_tax || 0,
3667
+ basketTotalWithShippingTotal: orderDetails.total_invoiced || 0
3668
+ }
3669
+ };
3670
+ webReturnObject.basketSummary = basketSummary;
3671
+ AppLoggerService.logDebug(this.className, "basketSummary", "Mapping ended...");
3672
+ return this;
3673
+ }
3674
+ refundRequest() {
3675
+ var _a;
3676
+ AppLoggerService.logDebug(this.className, "refundRequest", "Mapping started...");
3677
+ this.webReturnObject.refundRequest = ((_a = this.orderDetails.items) === null || _a === void 0 ? void 0 : _a.filter(product => (product === null || product === void 0 ? void 0 : product.base_price) && (product.qty_refunded || 0) > 0).map((product, index) => ({
3678
+ itemLineId: index + 1,
3679
+ refundedQuantity: product.qty_refunded || 0,
3680
+ refundWithPromotion: true,
3681
+ quantity: product.qty_ordered || 0
3682
+ }))) || [];
3683
+ AppLoggerService.logDebug(this.className, "refundRequest", `Mapped ${this.webReturnObject.refundRequest.length} refund items.`);
3684
+ AppLoggerService.logDebug(this.className, "refundRequest", "Mapping ended...");
3685
+ return this;
3686
+ }
3687
+ updateTaxBreakdown() {
3688
+ var _a;
3689
+ AppLoggerService.logDebug(this.className, "updateTaxBreakdown", "Mapping started...");
3690
+ const taxLines = ((_a = this.orderDetails.items) === null || _a === void 0 ? void 0 : _a.filter(product => product === null || product === void 0 ? void 0 : product.base_price).map((product, index) => {
3691
+ const taxableAmount = product.row_total_incl_tax || 0;
3692
+ const VAT = product.tax_percent || 0;
3693
+ const preTax = this.numberUtilService.trimTo2Decimal2((taxableAmount * 100) / (100 + VAT));
3694
+ const taxLineTotal = this.numberUtilService.trimTo2Decimal2(taxableAmount - preTax);
3695
+ return {
3696
+ itemLineId: index + 1,
3697
+ VAT,
3698
+ VATCode: '',
3699
+ taxableAmount,
3700
+ PreTax: preTax,
3701
+ taxLineTotal
3702
+ };
3703
+ })) || [];
3704
+ this.webReturnObject.basket["taxBreakdown"] = {
3705
+ taxLines,
3706
+ totalTaxableAmount: this.orderDetails.tax_amount || 0
3707
+ };
3708
+ AppLoggerService.logDebug(this.className, "updateTaxBreakdown", `Mapped ${taxLines.length} tax lines.`);
3709
+ AppLoggerService.logDebug(this.className, "updateTaxBreakdown", "Mapping ended...");
3703
3710
  return this;
3704
3711
  }
3705
3712
  deviceId(deviceId) {
@@ -3739,7 +3746,7 @@ class WebReturnMagentoV2RestMapperBuilderClass {
3739
3746
  return this;
3740
3747
  }
3741
3748
  build() {
3742
- AppLoggerService.logDebug(this.className, "build", "mapping done...");
3749
+ AppLoggerService.logDebug(this.className, "build", "Mapping done...");
3743
3750
  return this.webReturnObject;
3744
3751
  }
3745
3752
  getUTCDateTime(date) {
@@ -3757,5 +3764,5 @@ class WebReturnMagentoV2RestMapperBuilderClass {
3757
3764
  * Generated bundle index. Do not edit.
3758
3765
  */
3759
3766
 
3760
- export { MapperLibraryComponent, MapperLibraryModule, RJMapperBuilderClass, WebReturnMagentoV2RestMapperBuilderClass, WebReturnMapperBuilderClass, WebReturnSalesforceMapperBuilderClass };
3767
+ export { MapperLibraryComponent, MapperLibraryModule, RJMapperBuilderClass, WebReturnMagento2RestV1MapperBuilderClass, WebReturnMapperBuilderClass, WebReturnSalesforceMapperBuilderClass };
3761
3768
  //# sourceMappingURL=pmcretail-mapper-library.js.map