Developer forum

Forum » Development » Best and most efficient way to update product stock?

Best and most efficient way to update product stock?

Anders Ebdrup
Anders Ebdrup
Reply

Dear Dynamicweb,

 

We are looking into a way to have event based product stock updates in Dynamicweb from the ERP system, and are trying to do this in a efficient way without compromising performance on the site. Right now we expose a webapi loads the given product from the product service, updates the stocklevel and afterwards saves the product.

Is there at more efficient way to do this and still have data and cache updated?

 

Best regards, Anders


Replies

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Alternatively you can use Services.StockService.SaveStockUnit(StockUnit).
That will add/update stock information in the stock matrix and avoid the overhead of loading/saving a product.
I'm not sure if it makes a significant difference. I guess it depends on the data in your solution.

Best regards,
Morten

 
Anders Ebdrup
Anders Ebdrup
Reply

Thanks a lot, Morten! This is excellent when having stock data in EcomStockUnits, but what to do, when data is in EcomProducts?

 

Best regards, Anders

 
Morten Snedker Dynamicweb Employee
Morten Snedker
Reply

Could a page with a cshtml do the job? Just passing the product info and a token, and let the code use Database.ExecuteNonQuery to update EcomProducts, and followingly make a call to update the product cache...?

/snedker

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Snedker,

 

Yes that will be a fine approach. Which cache should I invalidate to have the least impact on the next load time for the product?

 

Best regards, Anders

 
Morten Snedker Dynamicweb Employee
Morten Snedker
Reply

Hi Anders,

You can pass a key to invalidate the product cache for that entry only:

Dynamicweb.Ecommerce.Products.ProductKey key = new Dynamicweb.Ecommerce.Products.ProductKey("productid", "languageid", "variantid");
Dynamicweb.Ecommerce.Services.Products.ClearCache(key);

BR
Snedker

 

You must be logged in to post in the forum