Reputation: 5596
I have a live and test Magento store. I generate a MagentoApi C# class from the WSDL of the Magento store.
I am able to update product quantities with no issues via my API class. I am now trying to set the Stock Availability
field from the API but it will not change it's value.
[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);
}
From the Magento store's admin section, the quantity value changes for the product but the Stock Availability
value has not changed.
I am setting the manage_stock
and use_config_manage_stock
as per the instructions outlined here in the Magento API reference guide.
Upvotes: 1
Views: 2352
Reputation: 5596
It turns out that I need to specify that I am supplying the is_in_stock
field by adding the parameter is_in_stock_specified=true
.
So, my API call is as 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)
};
Upvotes: 7