如何包括在Magento阿比的产品列表的方法结果的产品图片 [英] How to include product images in Magento Api's product list method result
问题描述
我希望尽量减少要求其连接到基于Magento的商店展示产品的移动应用程序API的数量。现在我们必须调用 catalog_product_attribute_media.list
方法对每个产品,以获得图像的URL和它真正减慢应用程序。
I want to minimize the number of Api calls for a mobile application which connects to Magento based shop to display products. right now we have to call catalog_product_attribute_media.list
method for each product in order to get image Urls and it really slows down the app.
我在这个回答,有可能通过编辑某些脚本,以扩展API调用的结果发现了。我试图用同样的方法通过编辑应用程序/ code /核心/法师/目录/型号/分类/ Api.php线440,包括在产品列表图片:
I found out in this answer that it is possible to extend the result of an Api Call by editing certain scripts. I tried to use the same approach to include images in product list by editing app/code/core/Mage/Catalog/Model/Category/Api.php line 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 /应用/ code /核心/法师/目录的/ etc / wsdl.xml,包括新的媒体属性行:255
I also edited html/app/code/core/Mage/Catalog/etc/wsdl.xml to include the new 'media' property line: 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类型或其他什么东西?
but when I call the catalog_category.assignedProducts
it always returns null for the 'media' property, I wonder why this doesn't work? is it the xml type or something else?
推荐答案
感谢这个答案我想出如何在结果中包括图片:
这里是我如何修改assignedProducts方法在app / code /核心/法师/目录/型号/分类/ Api.php和它的工作:
Thanks to this answer I figured out how to include images in the results: here's how I modified the assignedProducts method in app/code/core/Mage/Catalog/Model/Category/Api.php and it worked:
public function assignedProducts($categoryId, $store = null)
{
$category = $this->_initCategory($categoryId);
$storeId = $this->_getStoreId($store);
$collection = $category->setStoreId($storeId)->getProductCollection()
->addAttributeToSelect(array('brand','image','price','description','short_description','name'));
($storeId == 0)? $collection->addOrder('position', 'asc') : $collection->setOrder('position', 'asc');
$result = array();
$type = 'image';
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'),
'price' => $product->getData('price'),
'name' => $product->getData('name'),
'description' => $product->getData('description'),
'short_description' => $product->getData('short_description'),
'image_url' => $product-> getImageUrl()
);
}
return $result;
}
这篇关于如何包括在Magento阿比的产品列表的方法结果的产品图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!