1

Background

I have a live and test Magento store. I generate a MagentoApi C# class from the WSDL of the Magento store.

Problem

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.

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 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.

4

1 回答 1

7

事实证明,我需要通过添加参数来指定我正在提供该is_in_stock字段is_in_stock_specified=true

所以,我的 API 调用如下:

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)
                      };
于 2013-10-05T01:58:57.020 回答