How to get a product's image in Magento?

后端 未结 12 1109
慢半拍i
慢半拍i 2020-12-01 06:32

I\'m running on version 1.3.2.1, but on my client\'s server they had Magento 1.3.0 so my previous code to display images for my local copy,

echo $this->he         


        
相关标签:
12条回答
  • 2020-12-01 06:35
    echo $_product->getImageUrl();
    

    This method of the Product class should do the trick for you.

    0 讨论(0)
  • 2020-12-01 06:37

    If you have the product collection object like:

    $collection = Mage::getModel('catalog/product')->getCollection(); 
    

    Now you can get product sku using $_product->getSku() if you can't get image path with

    echo $this->helper('catalog/image')->init($_product,'small_image')->resize(135);
    

    Or

    $_product->getImageUrl();
    

    Then you can add a little code

    $productModel = Mage::getModel('catalog/product');
    $_prod = $productModel->loadByAttribute('sku', $_product->getSku()); 
    $_prod->getImageUrl();
    
    0 讨论(0)
  • 2020-12-01 06:41

    I recently needed to do this as well... here's how I got to it:

    $_product->getMediaGalleryImages()->getItemByColumnValue('label', 'LABEL_NAME')->getUrl();
    

    Hope that helps you!

    0 讨论(0)
  • 2020-12-01 06:41

    First You need to verify the base, small and thumbnail image are selected in Magento admin.

    admin->catalog->manage product->product->image

    Then select your image roles(base,small,thumbnail)enter image description here

    Then you call the image using

    echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(163, 100);

    Hope this helps you.

    0 讨论(0)
  • 2020-12-01 06:49
    (string)Mage::helper('catalog/image')->init($product, 'image');
    

    this will give you image url, even if image hosted on CDN.

    0 讨论(0)
  • 2020-12-01 06:50
    <img src='.$this->helper('catalog/image')->init($product, 'small_image')->resize(225, 225).' width=\'225\' height=\'225\'/>
    
    0 讨论(0)
提交回复
热议问题