Magento 1.6.0 API product update not working when

2020-03-27 06:25发布

My products all use numerical SKUs, but it seems to cause a problem when using the API to do product update.

According to the API doc, you can use either product ID or SKU.

Arguments:

  • mixed product - product ID or Sku
  • array productData - array of attributes values
  • mixed storeView - store view ID or code (optional)

But fully numerical SKUs don't seem to work. I'm convinced there is some code somewhere which checks if the value is numerical and assumes I must be supplying the product ID.

I also read somewhere you can pass in a 4th parameter to specify you are using sku, but that didn't work either.

$proxy->call($sessionId, 'product.update', array('123456', array('name'=>'Updated name1'), null, 'sku') );

Does anyone know how to get this working?

标签: magento
2条回答
叛逆
2楼-- · 2020-03-27 06:47

In a similar question TurmDrummer posted another workaround: https://stackoverflow.com/a/10915276/1598270

There is a workaround for pure numeric or mixed SKU, that works quiet well for me.

Just add a whitespace at the end of your SKU. Magento will interpret the value as a SKU, because whitespace is non numeric. Internaly Magento trims the whitespace later

This works perfectly from Magento 1.4.x - 1.7.

I liked this solution a bit better as a workaround because you aren't modifying any core code files, which I try to avoid.

查看更多
smile是对你的礼貌
3楼-- · 2020-03-27 06:56

Short answer is that there's a bug somewhere preventing the last param of product.update from being set properly (or maybe Varien haven't yet implemented it), which also presents a problem for the method product.info.

A quick workaround (if you don't mind losing the option to update by ID) is just to set the $identifierType in the Product API update() method ):

In app/code/core/Mage/Catalog/Model/Product/Api.php l.198

public function update($productId, $productData, $store = null, $identifierType = 'sku')

And finally load the product within the if ($idBySku) condition of the method getProduct() around l.427 of app/code/core/Mage/Catalog/Helper/Product.php

$productId = $idBySku;
$product->load($productId);

It's a bit of a fudge. I'll have a look for a better workaround as an override; otherwise, maybe someone else can post a better solution.

查看更多
登录 后发表回答