Hi all,
We have a Shopify module set up to Watch orders.
If a new order is received and that order matches with a filter, a purchase order is raised in Xero.
Here’s an example of the flow…
I want to automate entry of the COST price of the product on the Xero purchase order.
All our cost prices are stored in Xero (in the products and services section). They are stored under SKUs that correspond exactly with those SKUs in Shopify. This means we can map the SKU from Shopify to the SKU in Xero as shown below. I was thinking that if we can map the SKUs like this, then the cost price data against the Xero version of the product will pull through onto the purchase order.
The problem I’m having is that the Unit Amount field in the Xero module cannot be left empty. In other words, we need to define a Unit amount (the cost price) before the data is even communicated to Xero. I’ve tried setting the Unit Amount field to zero in the hope that 0 is overridden by the actual product cost stored in Xero but this doesn’t work, the Unit Amount field is overriding the cost data stored against the corresponding SKU in Xero.
One option may be to move our cost prices to Shopify by adding them to the Cost per item field as shown here…
Just wondering if anyone has ever come up against this issue?
Does anyone know whether the cost per item variable is available via Shopify’s API.
Or is there another way around this problem?
I’m guessing that’s a limitation of the Xero API. Possibly because a PO might have a different unit amount to what’s listed on the Xero Item.
If you just want to use the stored unit amount (product cost) from what you have stored in the Xero Item, then add a Xero Get a Item module before the Create a Purchase Order module.
Also, something really important that’s missing in your scenario … unless I’m very much mistaken, you’ll need an Iterator to iterate through each line item in the Shopify order. This will need to build a Xero line items array that you can then Map (see that little “Map” slider next to Line Items?) into the Create a Purchase Order module.
Thank you so much for getting back to me regarding this.
You are broadly correct in that each line item on the Shopify order will need adding to the Xero purchase order. I can see why an iterator would be required for this, I assume to split out each line item right? However, I’m not totally sure how to configure the modules correctly. Here’s the flow…
Actually surprised myself and managed to figure this out myself! The only issue I have now is that the array is putting each line item on a separate Xero purchase order, so if there are 3 line items on the Shopify order, there are 3 separate purchase orders being created in Xero!
Ideally I would like each Shopify line item as a separate line item on the same Xero invoice. Any idea how I would do that?
You’re going to need to build a new array for the Xero Create a Purchase Order module that contains all the SKU items from the Shopify line items.
You can’t just pass the Shopify Line Items array as it is, as it contains a lot of other fields that Xero neither knows nor cares about.
The easiest way to do this in your scenario is to use an Aggregator module after the Iterator.
The Source Module for the Aggregator will be the Iterator. The Aggregated Fields will be SKU and the Quantity. The Target Structure will be the Xero Create a Purchase Order Line Items array.
The Aggregator link above has some help on this, but for more (and better) background I’d recommend taking the free Make Academy courses. The Intermediate course has a great module on Iterators and Aggregators!
Hi David, thanks for the reply.
Not sure if you saw my most recent message. I managed to figure this out yesterday using the Aggregator as you suggested. The only issue I have now is that the array is putting each line item on a separate Xero purchase order, so if there are 3 line items on the Shopify order, there are 3 separate purchase orders being created in Xero!
Ideally I would like each Shopify line item as a separate line item on the same Xero invoice. Any idea how I would do that?
Thanks for the link to the academy courses. Will definitely look at these.
The Aggregator (note - that’s different from, but complementary to the Iterator) should mean that the following Xero app will get a single bundle for the whole order.
Could you post a screenshot of your current scenario?
Hi David, I figured it out! Or rather @Runcorn did. I changed the Source Module of the aggregator from Xero Get An Item to Iterator. That seems to have fixed it.
This has raised another issue though, which I’m unsure how to fix.
Prior to implementing the iterator and array, I had set the Xero create purchase order module up to add a fixed cost (an order “handling fee” that our supplier charges) plus a variable shipping cost based on the shipping method name in Shopify.
The handling fee and shipping cost are not items that are passed over in the array from Shopify, they are items that we add on to the purchase order before sending it to the supplier.
I can’t add these additional items because the array aggregator doesn’t give me options to add additional line items. See the screenshot below as an example…
This got me thinking, maybe after creating the purchase order I can then set up a Xero Get An Item module to fetch the “Handling fee” from Xero. And then a Xero Update purchase order to append the handling fee onto the bottom of the purchase order in Xero. As shown in the below scenario…
After that I would then add another Xero Get An Item module to fetch the shipping price from Xero and then a final Xero Update purchase order to append the shipping price below the handling fee.
The problem is, the Xero Update purchase order module deletes all the previously added line items and replaces them with the latest line item from the Xero Get An Item module (second to last module in the flow above).
Any idea how I can get around this? The expected functionality would be for Xero NOT to delete the previously added line items each time it updates the purchase order.
A variable shipping fee charged to us by the supplier, cost dependent on which Shipping method the customer selects in Shopify (Standard or Express, basically)
I think you could solve this by using the Set a Variable (or Set Multiple Variables) module. The values of these should then be available to the Aggregator to put into the array.
You’d set these before the Iterator so that they only get run once for each order, rather than once for each line.
David, thanks for the reply.
I get what you’re saying, I’m just unsure how I link to that variable to make it appear on the Xero purchase order. Here’s the flow…
I was assuming you wanted these items to be added to every line item, in which case you’d reference them in the aggregator.
If not, then you need to add them to the end of the array that the aggregator creates. To do that, add a Set Variable module after the Aggregator, with the value set by the add() function like this:
add(, item1, item2)
You’d then map that new variable as the Line Items parameter for the Xero module.
The Make Academy courses are invaluable for this kind of thing!
You are in the right direction, But, You are adding a primitive field to an array of collections,s and since it is not as per the format that Xero Expects you are getting the error.
I shared a video to set this up on your DM, If you have time do check and see if that helps you with this issue.
@Runcorn thank you for the DM, your explanation worked perfectly and this is now fully working. Please do share the video here if you can as I’m sure it would be of help to others.
Thank you again for all your help!