0

Hi there I use this script to get product list to csv file but the product image path does not come right. It gives the url but not the actual image path.

It exports like this http://dev.com/media/catalog/product the problem is $product['image'] is empty

Can you please help me about this? Thanks.

magento versiong is 8.1.0

while($pages>=$count){
            // -- if this is the start, put the header in.
            if($count == 0){
                Mage::getModel('core/session')->setUsedPids(array());
                $txt .= "Product ID,Product Name,Product Price,Product URL,Product Description,Product Image URL,Product Category\n";
            }
            echo 'Pages: '.$pages.' Count: '.$count.' Start: '.$start.' Limit: '.$limit.'<Br />';
            $products = $this->getProductsData($limit, $start);
            foreach($products as $product){
                if(!in_array($product['entity_id'], Mage::getModel('core/session')->getUsedPids())){
                    $txt .= '"'.str_replace('"', '', $product['entity_id']).'","'.
                                str_replace('"', '', $product['name']).'","'.
                                str_replace('"', '', $product['final_price']).'","'.
                                str_replace('"', '', Mage::getBaseUrl().$product['url_path']).'","'.
                                str_replace(array('"', "\n", "\r"), '', $product['description']).'","'.
                                str_replace('"', '', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog'.DS.'product'.$product['image']).'","'.
                                $product['category'][0]['category']['category_name'].'",'."\n";


                    if(!$used = Mage::getModel('core/session')->getUsedPids()){     
                        $used = array();
                    }
                    $used[] = $product['entity_id'];
                    Mage::getModel('core/session')->setUsedPids($used);
                }
            }
            if($count==0){ $start_file = true; } else { $start_file = false; }
            $count++;
            $start = $start+$limit;
            $file = $this->toFile('csv', 'PaidOnResults', $txt, $start_file);
            $txt = '';
            ob_flush();
            flush();
        }
1
  • try Mage::getBaseDir('media'), if it doesn't work, feed it no arguments, and it'll give Magento's root directory, you'll just have to add the additional image path. Commented Aug 6, 2014 at 13:49

1 Answer 1

1

Try to get the image url liks this:

$imageUrl = Mage::helper('catalog/image')->init($product, 'image')->__toString();

You can even resize it if you want:

$imageUrl = Mage::helper('catalog/image')->init($product, 'image')->resize(100, 120)->__toString();
2
  • it does not work. gives blank page. script does not even export anything
    – Erdem Ece
    Commented Aug 6, 2014 at 14:09
  • Try turning on the error reporting to see what's wrong.
    – Marius
    Commented Aug 6, 2014 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.