我想最大限度地減少連接到基於Magento的商店以顯示產品的移動應用程序的Api調用數量。現在我們必須調用每個產品的catalog_product_attribute_media.list
方法才能獲取圖片Url,並且它確實會降低應用的速度。如何在Magento Api的產品列表方法結果中包含產品圖像
我在answer中發現可以通過編輯某些腳本來擴展Api調用的結果。我試圖用同樣的方式通過編輯應用程序/代碼/核心/法師/目錄/型號/分類/ Api.php線440包括在產品列表圖片:
$storeId = $this->_getStoreId($store);
$collection = $category->setStoreId($storeId)->getProductCollection()
->addAttributeToSelect('brand')
->addAttributeToSelect('media_gallery_images');
($storeId == 0)? $collection->addOrder('position', 'asc') : $collection->setOrder('position', 'asc');;
$result = array();
foreach ($collection as $product) {
$result[] = array(
'product_id' => $product->getId(),
'type' => $product->getTypeId(),
'set' => $product->getAttributeSetId(),
'sku' => $product->getSku(),
'position' => $product->getCatIndexPosition(),
'brand' => $product->getData('brand'),
'media' => $product->getMediaGalleryImages()
);
}
return $result;
我還編輯HTML /應用/碼/core/Mage/Catalog/etc/wsdl.xml包括新的「媒體」屬性線:255
<complexType name="catalogAssignedProduct">
<all>
<element name="product_id" type="xsd:int"/>
<element name="type" type="xsd:string"/>
<element name="set" type="xsd:int"/>
<element name="sku" type="xsd:string"/>
<element name="position" type="xsd:int"/>
<element name="brand" type="xsd:string"/>
<element name="media" type="typens:catalogProductImageEntityArray"/>
</all>
</complexType>
但是當我打電話catalog_category.assignedProducts
它總是爲「媒體」屬性返回null,我不知道爲什麼這不起作用?它是XML類型還是其他?
嗨,我添加了這段代碼,但是這不會返回我添加的任何附加參數。此外,我在wsdl文件中添加這些參數也清理了我的緩存,任何想法我想念。非常感謝。 –