doujiena0025 2012-08-31 07:13
浏览 65
已采纳

如何编辑Magento API函数“items()”以获取产品的Image Url

I am trying to get the Image URL of the products by editing the Magento's API items() function. I have used $product-> getImageUrl() to get the URL but I am getting wrong URL.

The URL that I am getting is of the default Image which we place for the products which do not have image(Image Comming Soon like Image's url).

I am calling the function from Android Client using XML-RPC.
I am getting other details of the product correct,but the URL that I am getting for the products is wrong. And, all the URLs of the different products I am getting are same.

FYI, The URL that I am getting in the response is like :

http://192.168.1.237/machinetest/media/catalog/product/cache/0/image/265x/9df78eab33525d08d6e5fb8d27136e95/images/catalog/product/placeholder/image.jpg

The function that I am editing is as followed :

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

    if (is_array($filters)) {
        try {
            foreach ($filters as $field => $value) {
                if (isset($this->_filtersMap[$field])) {
                    $field = $this->_filtersMap[$field];
                }
                $collection->addFieldToFilter($field, $value);
            }
        } catch (Mage_Core_Exception $e) {
            $this->_fault('filters_invalid', $e->getMessage());
        }
    }
    $result = array();

    foreach ($collection as $product) {
         //$result[] = $product->getData();
           $result[] = array( // Basic product data
            'product_id' => $product->getId(),
            'sku'        => $product->getSku(),
            'name'       => $product->getName(),
            'set'        => $product->getAttributeSetId(),
            'type'       => $product->getTypeId(),
           'category_ids'=> $product->getCategoryIds(),
             'url_path'  =>  $product-> getImageUrl() // Added the Method here 
        );
    }
    return $result;
}
  • 写回答

3条回答 默认 最新

  • dongtun3259 2012-09-03 05:15
    关注

    Just write that please try this way..you will get the Solution on the Top

    You can able to get Images using this code just go through it and you will get images

    public function items($filters = null, $store = null)
    {
        $collection = Mage::getModel('catalog/product')->getCollection()
            ->addStoreFilter($this->_getStoreId($store))
            ->addAttributeToSelect('name');
    
        if (is_array($filters)) {
            try {
                foreach ($filters as $field => $value) {
                    if (isset($this->_filtersMap[$field])) {
                        $field = $this->_filtersMap[$field];
                    }
    
                    $collection->addFieldToFilter($field, $value);
                }
            } catch (Mage_Core_Exception $e) {
                $this->_fault('filters_invalid', $e->getMessage());
            }
        }
    
        $result = array();
    
        foreach ($collection as $product) {
    //            $result[] = $product->getData();
    
            $_product = Mage::getModel('catalog/product')->load($product->getId());
            $_image=$_product->getImageUrl();
    
            $result[] = array( // Basic product data
                'product_id' => $product->getId(),
                'sku'        => $product->getSku(),
    
                'name'       => $product->getName(),
                'set'        => $product->getAttributeSetId(),
                'type'       => $product->getTypeId(),
               'category_ids'=> $product->getCategoryIds(),
                'image_url_path' =>  $_image
            );
        }
    
        return $result;
    }
    

    hope it's work if you have any queries tell me i will help you!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路