Free javascript Hosting


node-self-running.js

Uploaded on Nov 18 2021 20:57 by vanhoi

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).SimpleOrderTransformation=e()}(this,function(){"use strict";var t=(e.prototype.parse=function(t){var e={invoiceNumber:"",orderNumber:"",webshopOrderStatus:"",orderCurrencyCode:"",createdAt:"",taxAmount:0,shippingAmount:0,subTotal:0,grandTotal:0,shippingTotal:0,discountName:"",discountPercent:"",discountAmount:0,discountedProducts:[],payment:{type:"",customFields:[]},shippingMethod:"",shippingFlat:!1,customerId:"",customerTitle:"",customerEmail:"",customerFirstname:"",customerLastname:"",billingAddress:{firstname:"",lastname:"",street:"",city:"",company:"",country:"",phoneNumber:"",postCode:"",region:"",vatId:"",id:""},shippingAddress:{firstname:"",lastname:"",street:"",city:"",company:"",country:"",phoneNumber:"",postCode:"",region:"",vatId:"",id:""},lineItemsGraph:[],lineItemsGraphOriginal:[]};return this.setBaseAmounts(t,e),this.setOrderNumber(t,e),this.setInvoiceNumber(t,e),this.setOrderStatus(t,e),this.setCustomer(t,e),this.setCurrency(t,e),this.setPaymentDetails(t,e),this.setShipment(t,e),this.setLineItems(t,e),this.setAddress(t,e),e},e.prototype.setLineItems=function(t,e){var i=[],r=[];t.included.forEach(function(t){"order_line_item"===t.type&&r.push(t),"promotion"===t.attributes.type&&(t={code:t.attributes.payload.code,value:t.attributes.payload.value,type:t.attributes.payload.discountType,items:t.attributes.payload.composition},i.push(t))});t=this.rebuildHierarchy(r,i);e.lineItemsGraphOriginal=t.original,e.lineItemsGraph=t.formatted},e.prototype.createLineItem=function(i,t){var r={id:i.id,productNumber:i.attributes.payload.productNumber,referenceId:i.attributes.referencedId,type:i.type,typeAttribute:null,price:{quantity:i.attributes.price.quantity,unitPrice:i.attributes.price.unitPrice,totalPrice:i.attributes.price.totalPrice,tax:0,taxRate:0},payload:i.attributes.payload,label:i.attributes.label.replace(/^[\n\r]+|[\n\r]+$/g,""),children:[]};return i.attributes.hasOwnProperty("type")&&(r.typeAttribute=i.attributes.type),0<i.attributes.price.calculatedTaxes.length&&(r.price.tax=i.attributes.price.calculatedTaxes[0].tax,r.price.taxRate=i.attributes.price.calculatedTaxes[0].taxRate),t.forEach(function(e){e.items.forEach(function(t){i.attributes.productId===t.id&&(r.discount={type:e.type,type_amount:e.value,code:e.code,value:t.discount})})}),r},e.prototype.rebuildHierarchy=function(t,e){for(var i,r,s={},a=[],n=[],o=[],d=0;d<t.length;d+=1)t[s[t[d].id]=d].children=[],o[d]=this.createLineItem(t[d],e);for(d=0;d<t.length;d+=1)i=t[d],r=o[d],null!==i.attributes.parentId?(t[s[i.attributes.parentId]].children.push(i),o[s[i.attributes.parentId]].children.push(r)):(a.push(i),n.push(r));return{original:a,formatted:n}},e.prototype.setPaymentDetails=function(t,e){t.included.forEach(function(t){"payment_method"===t.type&&(t=t.attributes,e.payment.type=t.name)}),t.included.forEach(function(t){"order_transaction"!==t.type||(t=t.attributes).hasOwnProperty("paymentMethodId")&&(e.payment.customFields=t.customFields)})},e.prototype.setBaseAmounts=function(t,e){e.createdAt=t.data[0].attributes.orderDate,"tax-free"===t.data[0].attributes.price.taxStatus?(e.subTotal=(1e3*t.data[0].attributes.amountNet-1e3*t.data[0].attributes.shippingCosts.totalPrice)/1e3,e.shippingAmount=t.data[0].attributes.shippingCosts.totalPrice,e.taxAmount=0):(e.subTotal=(1e3*t.data[0].attributes.amountNet-(1e3*t.data[0].attributes.shippingCosts.totalPrice-1e3*t.data[0].attributes.shippingCosts.calculatedTaxes[0].tax))/1e3,e.shippingAmount=(1e3*t.data[0].attributes.shippingCosts.totalPrice-1e3*t.data[0].attributes.shippingCosts.calculatedTaxes[0].tax)/1e3,e.taxAmount=t.data[0].attributes.price.calculatedTaxes[0].tax),e.grandTotal=t.data[0].attributes.amountTotal,e.shippingTotal=t.data[0].attributes.shippingTotal},e.prototype.setCustomer=function(t,e){t.included.forEach(function(t){"order_customer"===t.type&&(t=t.attributes,e.customerTitle=t.title,e.customerEmail=t.email,e.customerFirstname=t.firstName,e.customerLastname=t.lastName,e.customerId=t.customerNumber)})},e.prototype.setOrderNumber=function(t,e){e.orderNumber=t.data[0].attributes.orderNumber},e.prototype.setInvoiceNumber=function(t,i){t.included.forEach(function(t){var e;"document"===t.type&&t.attributes.hasOwnProperty("fileType")&&"pdf"===t.attributes.fileType&&null!==(e=null===(e=t.attributes.config)||void 0===e?void 0:e.custom)&&void 0!==e&&e.invoiceNumber&&(i.invoiceNumber=t.attributes.config.custom.invoiceNumber)})},e.prototype.setOrderStatus=function(t,e){t.included.forEach(function(t){"state_machine_state"===t.type&&(t=t.attributes,e.webshopOrderStatus=t.technicalName)})},e.prototype.setCurrency=function(t,e){t.included.forEach(function(t){"currency"===t.type&&(t=t.attributes,e.orderCurrencyCode=t.isoCode)})},e.prototype.setShipment=function(t,e){t.included.forEach(function(t){"shipping_method"===t.type&&(t=t.attributes,e.shippingMethod=t.name)})},e.prototype.setAddress=function(r,s){var a=r.data[0].attributes.billingAddressId;r.included.forEach(function(t){var i,e;"order_address"===t.type&&(i=t.attributes,t.id===a?(s.billingAddress.id=t.id,s.billingAddress.firstname=i.firstName,s.billingAddress.lastname=i.lastName,s.billingAddress.street=i.street,s.billingAddress.city=i.city,s.billingAddress.company=i.company,s.billingAddress.postCode=i.zipcode,s.billingAddress.phoneNumber=i.phoneNumber,(s.billingAddress.country=null)!==i.vatId&&(e=i.vatId.replace(/\s/g,""),s.billingAddress.vatId=e.replace(/[a-z][a-z]/i,"")),r.included.forEach(function(t){var e;"country"===t.type&&(e=t.attributes,t.id===i.countryId&&(s.billingAddress.country=e.iso))})):(s.shippingAddress.id=t.id,s.shippingAddress.firstname=i.firstName,s.shippingAddress.lastname=i.lastName,s.shippingAddress.street=i.street,s.shippingAddress.city=i.city,s.shippingAddress.company=i.company,s.shippingAddress.postCode=i.zipcode,s.shippingAddress.phoneNumber=i.phoneNumber,r.included.forEach(function(t){var e;"country"===t.type&&(e=t.attributes,t.id===i.countryId&&(s.shippingAddress.country=e.iso))})))}),""===s.shippingAddress.id&&(s.shippingAddress=s.billingAddress)},e);function e(){}function i(){this.parser=new t}return i.prototype.init=function(t){this.shopwareOrder=t},i.prototype.map=function(){return this.parser.parse(this.shopwareOrder)},i});

Back to list