3
<?php
include 'app/Mage.php';
Mage::app();
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$writeConnection = $resource->getConnection('core_write');

 $productCollection = Mage::getModel('catalog/product')
->getCollection() 
->addAttributeToFilter('name', array('like' => '%hp%'))
->addAttributeToSelect('*');

foreach ($productCollection as $product) {
//echo $product->getSku();
echo "<ul><li>".$product->getName()."</li>
        <li>".$product->getDescription()."</li> </ul>";
echo '<a href="'.Mage::getStoreConfig(Mage_Core_Model_Url::XML_PATH_SECURE_URL).'index.php/'.$product->getUrlPath().'"> <img src="'.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product/'.$product->getImage().'"></a>';
    }
?>

When I write this code it gives me this output. See the snapshot.. How should I get the image path?

enter image description here

1
  • Look at what is done in app/design/frontend/base/default/template/catalog/product/view/media.phtml Dec 13 '16 at 8:29
4

You can take it from the helper class

Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(100);
2
  • lose the resize to get the full size image path, and use image instead of thumbnail because that's what the OP requested.
    – Marius
    Dec 13 '16 at 8:40
  • The path of my image is magento/media/catalog/product/then h/2/_/hp.jpg. how shoul i get this url ?
    – Afzal Khan
    Dec 13 '16 at 10:34
4
Mage::getModel('catalog/product_media_config')->getMediaUrl( $product->getImage());
1
  • 1
    had a similar need, this worked perfectly for me.
    – Irfan Khan
    Dec 13 '16 at 9:05

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.