Developer forum

Forum » Ecommerce - Standard features » ProductViewModel - StockLevel is not correct when using stock locations

ProductViewModel - StockLevel is not correct when using stock locations

Niels Foldager
Reply

Hi Dynamicweb,

I have an issue getting the correct stock quantity when using stock locations and a ProductViewModel. Model.StockLevel is not returning the correct stock quantity from the stock location defined on the website.

When using Dynamicweb.Rendering.RazorTemplateModel, then GetDouble("Ecom:Product.Stock") is returning the correct stock quantity.

I can see a difference in the code when comparing ViewEnginec.cs and Renderer.cs. In ViewEnginec.cs GetUnitStock(StockLocation stockLocation, string unitId) is called without af stock location, but in Renderer.cs the same method is called including a stock location coming from the context.

(Dynamicweb 9.15.6)

Best regards,
Niels Foldager


 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Niels

Yes - it is kind of on purpose. The tag based version is very dependent on the current context. Viewmodels cannot depend on the same context because they are also exposed in the webapi. So that property cannot change 'randomly' by current unitid and stocklocation from context. But I can see that the stocklocation is now on the viewmodel settings, so I have changed it to this:

product.GetUnitStock(Services.StockLocationService.GetStockLocation(settings.StockLocationId), product.DefaultUnitId));

Instead use the ProductViewmodel.StockUnits - it will give you a lot more information and include units and locations.

BR Nicolai

 
Niels Foldager
Reply

Thank you, Nicolai.

Best regards,
Niels Foldager

 

You must be logged in to post in the forum