function xmlContent(content){ if(content != null){ return { "$t" : content }; } return null; } export class RetailInvoiceConverter { shopify2Wintersteiger(data){ console.log(data); const invoices = data.map(this.populateWintersteigerInovice.bind(this)); const xmlData = { invoices : { invoice : invoices } } return xmlData; } wintersteiger2Shopify(data){ const jsonData = data.map(function(orderData){ return orderData; }); return jsonData; } populateWintersteigerInovice(order) { var tax1amount = order.total_tax; var grand_total = order.total_price; var self = this; const invoiceitem = order.line_items.filter(this.filterRetailItems).map(function(line_item){ grand_total = parseFloat(grand_total) + parseFloat(line_item.price); return self.populateWintersteigerInoviceItem(line_item); }); let marketingpermission = null; if(order.customer && order.customer.marketing_opt_in_level == "confirmed_opt_in"){ marketingpermission = { "$t" : "yes" }; } const invoice = { invoiceid : { "$t" : order.id }, invoice_number: { "$t" : order.name.replace("#", "") }, created_at : { "$t" : order.created_at }, currency : { "$t" : order.currency }, custextid : { "$t" : order.customer && order.customer.id }, custextidorigin : { "$t" : "Shopify" }, firstname : { "$t" : order.customer && order.customer.first_name }, lastname : { "$t" : order.customer && order.customer.last_name }, address1 : { "$t" : order.shipping_address && order.shipping_address.address1 }, address2 : order.shipping_address && order.shipping_address.address2 ? {"$t":order.shipping_address.address2} :null, zip : { "$t" : order.shipping_address && order.shipping_address.zip }, city : { "$t" : order.shipping_address && order.shipping_address.city }, countryisoa2 : { "$t" : order.shipping_address && order.shipping_address.country_code }, countryname : { "$t" : order.shipping_address && order.shipping_address.country }, er_regioncode : { "$t" : order.shipping_address && order.shipping_address.province_code }, phone : order.shipping_address && order.shipping_address.phone ? {"$t":order.shipping_address.phone} :null, email : { "$t" : order.email }, marketingpermission : marketingpermission, tax1amount : { "$t" : tax1amount }, grand_total : { "$t" : grand_total }, invoiceitem : invoiceitem } return invoice } filterRetailItems(line_item){ console.log(line_item); return true; } populateWintersteigerInoviceItem(line_item){ console.log(line_item); const invoiceitem = { invoiceitemid : { "$t" : line_item.id }, articlecode : { "$t" : line_item.sku }, articlename : { "$t" : line_item.name }, quantity : { "$t" : line_item.quantity }, // indicating that this item is taxable or that the totals in this item inlcude tax totals_include_tax : { "$t" : line_item.taxable }, total_listprice : { "$t" : line_item.price }, total_price_alteration : { "$t" : line_item.total_discount }, total_amount : { "$t" : line_item.price - line_item.total_discount } // precentage of total tax or tax rate? // tax1percent : { //calculate average rate from taxlines? } }; return invoiceitem; } } // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //