【发布时间】:2013-12-22 19:20:54
【问题描述】:
我想尽量减少连接到基于 Magento 的商店以展示产品的移动应用程序的 Api 调用次数。现在我们必须为每个产品调用catalog_product_attribute_media.list 方法来获取图片网址,这确实会降低应用程序的速度。
我在answer 中发现可以通过编辑某些脚本来扩展 Api 调用的结果。我尝试使用相同的方法通过编辑 app/code/core/Mage/Catalog/Model/Category/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/app/code/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类型还是别的?
【问题讨论】:
标签: php api magento soap-client