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

            // -- if this is the start, put the header in.
            if($count == 0){
                $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']).'","'.

                    if(!$used = Mage::getModel('core/session')->getUsedPids()){     
                        $used = array();
                    $used[] = $product['entity_id'];
            if($count==0){ $start_file = true; } else { $start_file = false; }
            $start = $start+$limit;
            $file = $this->toFile('csv', 'PaidOnResults', $txt, $start_file);
            $txt = '';
  • 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. Aug 6 '14 at 13:49

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();
  • it does not work. gives blank page. script does not even export anything
    – Erdem Ece
    Aug 6 '14 at 14:09
  • Try turning on the error reporting to see what's wrong.
    – Marius
    Aug 6 '14 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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