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 Answer 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
Marius
199k55 gold badges431 silver badges837 bronze badges
default
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.