magento soap api v2 catalogProductInfo not working

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 07:56:50

问题


When i call the api function as follows

<?php $result = $client->catalogProductInfo($session, $id, null, 'sku'); ?>

I get the following error. I'm positive that all the passed variables are set correctly, as other magento api functions work just fine.

Product not exists Error: An Internal Error Has Occurred.

I'm assuming that it's a fault with the call syntax. I couldn't find a proper example of calling catalogProductInfo with sku instead of product id. The documentation http://www.magentocommerce.com/api/soap/catalog/catalogProduct/catalog_product.info.html suggests to me that my call is correct.

Any ideas as to what I'm doing wrong are highly appreciated.


回答1:


Try to submit a space as last character of your SKU. e.g. if SKU is "1234" submit "1234 ".

This issue sometimes occurs, if your submitted sku only contains numbers.




回答2:


I think you hit on a problem with the optional arguments which your call can take. catalogProductInfo() can take five arguments, of which the first one is the sessionId; all the other arguments are passed to the method Mage_Catalog_Model_Product_Api_V2::info(), which takes them as follows:

public function info($productId, $store = null, $attributes = null, $identifierType = null)

As you can see, just the $productId is obligatory, the other arguments are optional. But, if you want to pass the $identifierType argument to the method, you have to pass as well all the other arguments. So, in your case, you omit one of the $store or $attributes arguments, and the method takes your sku as the $attributes argument. That produces your error.

So you either should pass the missing argument, or you can just omit the $identifierType argument. Magento can guess from the input at $productId which identifier type you pass (product ID or sku). The info() method calls the _getProduct() method, which in turn calls Mage::helper('catalog/product')->getProduct($productId, $this->_getStoreId($store), $identifierType). In this method Magento takes a guess about your $productId argument:

if ($identifierType === null) {
        if (is_string($productId) && !preg_match("/^[+-]?[1-9][0-9]*$|^0$/", $productId)) {
            $expectedIdType = 'sku';
        }
    }



回答3:


You left out the 4. param.

Function is smth. like this:

public catalogProductReturnEntity catalogProductInfo(
string sessionId,
string product,
string storeView,
**catalogProductRequestAttributes attributes,**
string productIdentifierType)

As "attributes" you passed "sku".



来源:https://stackoverflow.com/questions/16749774/magento-soap-api-v2-catalogproductinfo-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!