Wednesday, July 29, 2020

#786 OIC --> Updating Product Inventory in Shopify

This is a typical use case -

I have a eCommerce site that sells the product, I have an ERP that manages the sales lifecycle.

In this case I am looking at Netsuite as the ERP and Shopify as the eCommerce site, but I assume one can extrapolate for other ERP apps.

Firstly, a big thank you to my colleague Shantala S. for her support here!

Now let's begin by looking at the Product inventory in Shopify -

Note from the inventory history, I can see the default location -
I have partially obfuscated it but you still see the street number, 168.

Ergo, we have 4 of these Leica cases in stock at the default location.

As you can see, I can have more than 1 location -

It is very easy to add new locations in Shopify -

Same idea in Netsuite, I have inventory items available at different locations -

So many customers would have the same location in both Netsuite and Shopify and then synchronize the inventory between them.

In the following simple example I will will process each of my products from Shopify, updating them with the quantity available from Netsuite.

I have a large amount of products so I will avail of the Shopify pagination feature discussed in a previous blog post here

So now we will start with the processing of the individual Shopify products.

Step 1 - Check Netsuite for the quantity available

I do this via a Netsuite SavedSearch that returns items, their locations and the quantities available at those locations.


The map to the search is as follows -

I have a lookup that contains the default locationInternalId from Netsuite -
this I assign to the inventoryLocation search value.
Target operator is set to anyOf.

The key I use to link Products/Items is
Product sku = itemid.

Now that I have that -

I check if the search has been successful - i.e. I have found the item at that location.
If so I update Shopify with the quantity available value.

Now, let's take a step back and look at how Shopify works in this respect -
Shopify has products - each product has an id.
Products can have variants e.g. T-Shirt in L, M and S. Each variant has an id.

Each of these variants also has an inventory item id.

Here are those fields in the product structure returned by Shopify.

Locations in Shopify also have their ids -

To update the inventory in Shopify I need the following -

  "location_id": yourLocationId,
  "inventory_item_id": yourInventoryItemId,
  "available": 20

Now to configuring this via the OIC Shopify adapter -

Next, select the Create option and NOT update. 
Setting the inventory is available under Create.

Now to the mapping -

I have retrieved the quantityAvailable from Netsuite. I assigned it to an integration variable.

Now I cast this variable as a number -

Now to testing this - 

Remember, my Leica Case in Shopify has quantity = 12

Here is its pendant in Netsuite Inventory -

Note: sku and item id match.

Here is the quantity available in Netsuite for my Shopify default location -

I test the integration - 
Note this will be called from the main integration that retrieves the products from Shopify.
Request Payload contains sku and inventory_item_id

I validate in Shopify -

No comments: