简体   繁体   中英

update product inventory in magento using magento soap api in C#

I am trying to update the Product inventory in Magento, using Magento SOAP API in C#. When I call the product_stock.update api, it returns true. But when I check in Magento Admin panel, it is not updated.

ProductInventoryStock[] arrProdInventoryStock = new ProductInventoryStock[1];
for (int iCnt = 0; iCnt < arrProdInventoryStock.Count(); iCnt++)
{
  ProductInventoryStock objProdInventoryStock = new ProductInventoryStock();
  objProdInventoryStock.qty = "111";
  objProdInventoryStock.is_in_stock = 1;
  objProdInventoryStock.manage_stock = 1;
  objProdInventoryStock.use_config_manage_stock = 0;
  arrProdInventoryStock[iCnt] = objProdInventoryStock;
}

bool test = Inventory.Update(apiUrl, sessionId, new object[] { "126", arrProdInventoryStock });

Please check this, and is there any problem over here. or something else? Thanks.

Im using Mangento 1.9.x with the v2_soap?wsdl=1 and integrate with C# (4.5 Framework), I made a simple function that will update the stock, taking parameters as activeSession , ProductId , stockQty , stockStatus . Most important thing to note is that I've set the value to is_in_stock along with is_in_stockSpecified

        protected void AddInventory(string activeSession, string ProductId, string stockQty, int stockStatus)
        {
        MagentoService mservice = new MagentoService();
        catalogInventoryStockItemUpdateEntity uStock = new catalogInventoryStockItemUpdateEntity();
        int stock_status=stockStatus;            
        uStock.qty = stockQty;
        uStock.is_in_stock = stock_status;
        uStock.is_in_stockSpecified = Convert.ToBoolean(stock_status);
        int result;

        try
        {                
            result = mservice.catalogInventoryStockItemUpdate(activeSession, ProductId, uStock);                
        }
        catch (Exception ex)
        {         
        }            
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM