2012-01-15 16 views
6

我使用Magento的V2的Web服務在WS-I兼容模式Magento的WS-I兼容V2 API WSDL Web服務SOAP的錯誤:編碼:對象有沒有 '的sessionId' 屬性

時嘗試列出的產品我得到例外

SOAP-ERROR: Encoding: object has no 'sessionId' property 

我的代碼是下面列出

$proxy = new SoapClient('http://127.0.0.1/Magento1620/index.php/api/v2_soap?wsdl', array('trace' => 1, 'connection_timeout' => 120)); 

    $sessionId = $proxy->login(array(
     'username' => "zzc000", 
     'apiKey' => "zzc000" 
    )); 

    $filters = array(
     'sku' => array('like'=>'zol%') 
    ); 

    $products = $proxy->catalogProductList($sessionId, $filters); 

請幫幫忙,謝謝

+0

嗨。有沒有從Magento的SOAP API的任何其他工作職能在你的項目,或者這是您的第一個API的第一拍? – 2012-01-15 06:32:28

+0

@AndreasRohde 這是一個全新的magento安裝在Windows 7樣本數據,IIS 7.5,PHP 5.3.8 這是第一次到PHP客戶端內消費它,只有登錄的作品。我可以從C#.NET調用它。 – Joe 2012-01-15 07:44:43

回答

19

WS-I模式,有一些細微差別在使用API​​。

  1. $ proxy-> login()的結果是一個對象。你需要提取sessionId。
  2. 當調用$的Proxy-> catalogProductList(),您需要提供一個關聯數組參數(就像你用$的Proxy-做>登錄())。

請試試這個:

<?php 

try { 
    error_reporting(E_ALL | E_STRICT); 
    ini_set('display_errors', 1); 
    $proxy = new SoapClient('http://127.0.0.1/Magento1620/index.php/api/v2_soap?wsdl', array('trace' => 1, 'connection_timeout' => 120)); 

    $session = $proxy->login(array(
     'username' => "zzc000", 
     'apiKey' => "zzc000" 
    )); 
    $sessionId = $session->result; 

    $filters = array(
     'sku' => array('like'=>'zol%') 
    ); 

    $products = $proxy->catalogProductList(array("sessionId" => $sessionId, "filters" => $filters)); 

    echo '<h1>Result</h1>'; 
    echo '<pre>'; 
    var_dump($products); 
    echo '</pre>'; 

} catch (Exception $e) { 
    echo '<h1>Error</h1>'; 
    echo '<p>' . $e->getMessage() . '</p>'; 
} 

這同樣適用於其他方法調用的WS-I兼容V2 SOAP API。

+1

[鏈接](http://stackoverflow.com/a/8868668/1015655)@MatthiasZeis 謝謝你,它的工作原理!但我必須以一種奇怪的方式通過過濾器才能使它工作,我會走錯路線嗎? '$濾波器=陣列( \t \t \t 'complex_filter'=>數組( \t \t \t \t \t陣列( \t \t \t \t \t \t \t '鍵'=> 'PRODUCT_ID', \t \t \t \t \t \t \t'value'=> array( \t \t \t \t \t \t \t \t \t '鍵'=> '當量', \t \t \t \t \t \t \t \t \t '值'=> '18' \t \t \t \t \t \t \t \t \t) \t \t \t \t \t \t \t) \t \t \t \t \t) \t \t \t); \t \t $產品= $的Proxy-> catalogProductList(陣列( 「的sessionId」=> $的sessionId, 「過濾器」=> $過濾器));' – Joe 2012-01-15 10:40:55

+0

如果你需要一個單一的產品信息,使用: $產品= $ proxy-> catalogProductInfo(array(「sessionId」=> $ sessionId,「productId」=> 18)); 要過濾產品列表,您可能需要使用複雜的過濾器,是的,這可能很奇怪。 ;-) – 2012-01-15 11:33:12

+0

你能幫我看看我在另一篇文章中遇到的問題嗎? [鏈接](http://stackoverflow.com/a/8867327/1015655) – Joe 2012-01-16 12:11:30

相關問題