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条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化