Developer forum

Forum » Development » LSIntegration get stock with multiple Locations Exception thrown

LSIntegration get stock with multiple Locations Exception thrown

Reynir Viðar Ingason
Reply

Hi,

 

we are working on an integration project using DW LSIntegration project agains a customer LSRetail implementation.

In LS the web store is configured to have multiple locations.
This is done because the webstore sells items that can be picked up from multiple stores so we need access to availability and stock from each location.

During data import batch job a duplicate key exception is thrown.
public static Dictionary<string, decimal> GetStock(string shopId, string itemId, string variantId, string serviceUrl)
{
        Dictionary<string, decimal> result = new Dictionary<string, decimal>();
        EcommerceService.IeCommerceServiceClient client = Config.GetClient(serviceUrl);
        EcommerceService.InventoryResponse[] inventories = null;
        inventories = client.ItemsInStockGet(shopId, itemId, variantId, int.MaxValue);
        foreach (var item in inventories)
        {
            result.Add(item.StoreId, item.QtyInventory);
        }
        return result;
}

The exception occurs because we have two inventory responses and both have the same StoreId.

Reynir


Replies

 
Nicolai Pedersen
Reply

I do not think the OMNI API supports multiple locations - if you look at the Inventory response, it only has the store ID and not a location ID:

http://mobiledemo.lsretail.com/lsomnihelp/html/T_LSRetail_Omni_Domain_DataModel_Base_Requests_InventoryResponse.htm

And we does not seem to be able to query the items for each location:

http://mobiledemo.lsretail.com/lsomnihelp/html/M_LSOmni_Service_IUCService_ItemsInStockGet.htm

So my best bet is to check if the key exists in the dictionary, and if it does, sum the inventory quantities. Not perfect, but at least you get a complete stock amount back.

BR Nicolai

 
Reynir Viðar Ingason
Reply

Hey,

 

I will have a look at the LS Omni code with my NAV developer.
Your workaround is exactly what I did to get passed this for now :)

 

Reynir

 
Reynir Viðar Ingason
Reply

Hey again,

 

I have been looking through the LSIntegration code hoping to find the best way to implement a check for stock based on location, example here where it says "vara til í:" https://a4.is/product/bucilla-jolasokkur-santa-choir-practice

I have not found any obvious way to do that, am I missing something or is this functionality I will have to implement?

 

Reynir

 
Reynir Viðar Ingason
Reply

I read up on the LSIntegration documentation a bit further and have implemented a way to get the stock information to the front end.

I altered the "GetStockStatusForProduct" method in the Helpers class:
Get all stores from the item type table for stores.
I get the stock for the product with no store specified.
Join these on StoreId and return the description for the store with the inventory status for that store.

I call this method in the template "ProductTemplateExtender" and create a loop for it.

We are using rapido and are sticking to the handle bars pattern in our front end implementations.


I am wondering how best to identify when my template extender is running on a json feed so I can only generate the loop for the feed?

 

Reynir

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Great job.

Try to take a look at the response content type - maybe it is set at that point.

Otherwise will the template object you get have a reference to the template file used - and then you can check the name of it...

BR Nicolai

Votes for this answer: 1

 

You must be logged in to post in the forum