2013-05-25 42 views
3

當我調用API函數如下Magento的SOAP API V2 catalogProductInfo不工作

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

我碰到下面的錯誤。我肯定所有傳遞的變量設置正確,因爲其他magento API函數工作得很好。產品不存在 錯誤:發生內部錯誤。

我假設這是調用語法的錯誤。我無法找到一個正確的示例,即使用sku而不是產品ID調用catalogProductInfo。 文檔http://www.magentocommerce.com/api/soap/catalog/catalogProduct/catalog_product.info.html向我建議我的電話是正確的。

任何想法,我做錯了高度讚賞。

回答

4

嘗試提交一個空間,你SKU的最後一個字符。 例如如果SKU是"1234"提交"1234 "

如果您提交的sku僅包含數字,則有時會出現此問題。

+0

謝謝,這對我來說是個訣竅。 – danba

+0

8小時搜索黑暗的網站,最後這個答案出現了。我想要抱你 –

0

我想你打了一個問題,你可以採取的可選參數。 catalogProductInfo()可以採取五個參數,其中第一個是sessionId;所有其他的參數傳遞給方法Mage_Catalog_Model_Product_Api_V2::info(),這需要它們如下:

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

正如你所看到的,只是$productId是強制性的,其他參數都是可選的。但是,如果您想通過該方法的參數,則必須傳遞所有其他參數。因此,對於您的情況,您省略了$store$attributes參數之一,並且該方法將您的sku作爲$attributes參數。這會產生你的錯誤。

所以你要麼通過缺少的參數,要麼你可以忽略$identifierType參數。 Magento可以從$productId的輸入中猜出您通過哪種標識符類型(產品ID或sku)。 info()方法調用_getProduct()方法,該方法又調用Mage::helper('catalog/product')->getProduct($productId, $this->_getStoreId($store), $identifierType)。在這種方法的Magento需要猜測你$productId論點:

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

謝謝!我按照你的建議做了'$ result = $ client-> catalogProductInfo($ session,$ id。「」「);''。現在,當我使用[鏈接](http:// /checkout/cart /)時,購物車顯示爲空。我猜我的購物車ID需要通過或smtg? – danba

+0

不知道你爲什麼要傳遞'$ id。「」'?並且:您的API調用是用於目錄的,而不是用於購物車的,您不應該混淆這個問題 –

0

你遺漏了4.參數。

功能不起作用。像這樣:

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

作爲「屬性」你傳遞了「sku」。

相關問題