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();
 }
asked Aug 6, 2014 at 13:43
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();
answered Aug 6, 2014 at 13:48
2
  • it does not work. gives blank page. script does not even export anything Commented Aug 6, 2014 at 14:09
  • Try turning on the error reporting to see what's wrong. Commented Aug 6, 2014 at 14:12

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.