2013-04-04 49 views
4

我目前使用名爲'catalogProductList'(http://www.magentocommerce.com/api/soap/catalog/catalogProduct/catalog_product.list.html)的SOAP方法來檢索catalogProductEntity數組。Magento肥皂 - 通過一次調用獲取詳細的產品清單

問題是catalogProductEntity沒有像'price'和'description'這樣的一些屬性。問題是:是否有任何(已經實現的)SOAP方法通過一次調用給我提供這些信息?

如果不這樣,我該如何/在哪裏可以將這些字段添加到返回值中?我的意思是,改變服務器端的php代碼,以便在一次調用中獲得這個「產品清單」。

我試圖避免對每個產品的幾個查詢來獲取此信息。 PS:我正在使用Magento 1.7。


編輯

繼@Mat提示,我編輯\程序\代碼\核心\法師\目錄\型號\產品\ Api.php文件和我的方法items僅僅是這樣的:

public function items($filters = null, $store = null) 
{ 
    $collection = Mage::getModel('catalog/product')->getCollection() 
     ->addStoreFilter($this->_getStoreId($store)) 
     ->addAttributeToSelect('price') 
     ->addAttributeToSelect('description') 
     ->addAttributeToSelect('name'); 

    /** @var $apiHelper Mage_Api_Helper_Data */ 
    $apiHelper = Mage::helper('api'); 
    $filters = $apiHelper->parseFilters($filters, $this->_filtersMap); 
    try { 
     foreach ($filters as $field => $value) { 
      $collection->addFieldToFilter($field, $value); 
     } 
    } catch (Mage_Core_Exception $e) { 
     $this->_fault('filters_invalid', $e->getMessage()); 
    } 
    $result = array(); 
    foreach ($collection as $product) { 
     $result[] = array(
      'product_id' => $product->getId(), 
      'sku'  => $product->getSku(), 
      'price'  => $product->getData('price'), 
      'description'=> $product->getData('description'), 
      'name'  => $product->getName(), 
      'set'  => $product->getAttributeSetId(), 
      'type'  => $product->getTypeId(), 
      'category_ids' => $product->getCategoryIds(), 
      'website_ids' => $product->getWebsiteIds() 
     ); 
    } 
    error_log(print_r($result, true) . "\n", 3, "c:\log.txt"); 
    return $result; 
} 

日誌文件輸出這樣的結果:

Array 
(
    [0] => Array 
     (
      [product_id] => 3 
      [sku] => sim12ple1235 
      [price] => 99.9500 
      [description] => Simple Description 
      [name] => Simple Product 
      [set] => 4 
      [type] => simple 
      [category_ids] => Array 
       (
       ) 
      [website_ids] => Array 
       (
        [0] => 1 
       ) 
     ) 
) 

注意價格和描述在$ result變量,但XML響應我的客戶端應用程序得到的是:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
<SOAP-ENV:Body> 
<ns1:catalogProductListResponse> 
<storeView SOAP-ENC:arrayType="ns1:catalogProductEntity[1]" xsi:type="ns1:catalogProductEntityArray"> 
<item xsi:type="ns1:catalogProductEntity"> 
<product_id xsi:type="xsd:string">3</product_id> 
<sku xsi:type="xsd:string">sim12ple1235</sku> 
<name xsi:type="xsd:string">Simple Product</name> 
<set xsi:type="xsd:string">4</set> 
<type xsi:type="xsd:string">simple</type> 
<category_ids SOAP-ENC:arrayType="xsd:string[0]" xsi:type="ns1:ArrayOfString"/> 
<website_ids SOAP-ENC:arrayType="xsd:string[1]" xsi:type="ns1:ArrayOfString"> 
<item xsi:type="xsd:string">1</item> 
</website_ids> 
</item> 
</storeView> 
</ns1:catalogProductListResponse> 
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

我的問題是:是否有任何XML架構或指定輸出另一個配置文件?還有什麼我想在服務器端編輯?

回答

2

這個問題的部分是,它缺少在文件app /代碼/核心/法師/目錄的/ etc/WSDL這個領域(價格和描述)。 xml,應用php更改後。

... 
<complexType name="catalogProductEntity"> 
<all> 
    <element name="product_id" type="xsd:string"/> 
    <element name="sku" type="xsd:string"/> 
    <element name="name" type="xsd:string"/> 
    <element name="set" type="xsd:string"/> 
    <element name="type" type="xsd:string"/> 
    <element name="category_ids" type="typens:ArrayOfString"/> 
    <element name="website_ids" type="typens:ArrayOfString"/> 

    <element name="price" type="xsd:string"/> 
    <element name="description" type="xsd:string"/> 
</all> 
</complexType> 
... 

,不要忘記清除緩存!

+1

是的,這是正確的,是最後添加的東西 – Mat 2013-04-06 13:02:23

3

要獲得產品信息,你必須使用catalog_product.info

你之前得到清單列表,然後你循環得到產品的詳細信息。

$list = $proxy->catalogProductList($sessionId, $filters); 
for($i = 0; $i < count($list); $i ++){ 
    $current = $list[$i]; 
    $product = $proxy->catalogProductInfo($sessionId, $current['product_id']); 
} 

//// UPDATE ////

改變catalogProductList碼進入

\app\code\core\Mage\Catalog\Model\Product\Api.php 

,並添加您在

public function items 

需要做這樣的事情參數週期前

$collection = Mage::getModel('catalog/product')->getCollection() 
     ->addStoreFilter($this->_getStoreId($store)) 
     ->addAttributeToSelect('name'); 

,你必須添加

->addAttributeToSelect('what_you_need'); 

foreach ($collection as $product) { 
     $result[] = array(
      'product_id' => $product->getId(), 
      'sku'  => $product->getSku(), 
      'name'  => $product->getName(), 
      'set'  => $product->getAttributeSetId(), 
      'type'  => $product->getTypeId(), 
      'category_ids' => $product->getCategoryIds(), 
      'website_ids' => $product->getWebsiteIds(), 
      'what_you_need' => $product->getData('what_you_need') 

     ); 
    } 

//// /// UPDATE(感謝@matheusjardimb)

對於最後你必須添加

what_you_need 

元素爲

app/code/core/mage/catalog/etc/wsdl.xml 

在XML

<complexType name="catalogProductEntity"> 
      <all> 
       <element name="product_id" type="xsd:string"/> 
       <element name="sku" type="xsd:string"/> 
       <element name="name" type="xsd:string"/> 
       <element name="set" type="xsd:string"/> 
       <element name="type" type="xsd:string"/> 
       <element name="category_ids" type="typens:ArrayOfString"/> 
       <element name="website_ids" type="typens:ArrayOfString"/> 
       <element name="**what_you_need**" type="xsd:string"/> 
      </all> 
     </complexType> 
+0

但是這種方法隱含在兩個soap方法調用中。我正在使用Android客戶端,並試圖節省網絡資源。 – MatheusJardimB 2013-04-04 21:37:31

+0

如果你有一個product_id保存在某個地方,你可以直接使用catalogProductInfo – Mat 2013-04-04 21:39:26

+0

,但它再次,它不會救我多次調用catalogProductInfo ... – MatheusJardimB 2013-04-04 21:41:57

相關問題