c# - Can not update Stock Availability / Is In Stock value via Magento API -
background
i have live , test magento store. generate magentoapi c# class wsdl of magento store.
problem
i able update product quantities no issues via api class. trying set stock availability
field api not change it's value.
code
[test] public void updateisinstockfield() { magentostoreconfig storeconfig = gettestmagentostore(); var magentoapirepo = new magentoapirepository(storeconfig); cataloginventorystockitementity magentoproduct = magentoapirepo.getproductfromsku(new[] { "sku-123456" }); var productupdated = new cataloginventorystockitemupdateentity { is_in_stock = 0, manage_stock = 0, use_config_manage_stock = 0, qty = new random().next(50, 100).tostring(cultureinfo.invariantculture) }; magentoapirepo.updatestockquantity(magentoproduct.product_id, productupdated); }
result
from magento store's admin section, quantity value changes product stock availability
value has not changed.
i setting manage_stock
, use_config_manage_stock
per instructions outlined here in magento api reference guide.
it turns out need specify supplying is_in_stock
field adding parameter is_in_stock_specified=true
.
so, api call follows:
var productupdated = new cataloginventorystockitemupdateentity { is_in_stock_specified = true, is_in_stock = 0, manage_stock = 0, use_config_manage_stock = 0, qty = new random().next(50, 100).tostring(cultureinfo.invariantculture) };
Comments
Post a Comment