skip to Main Content

I need to display product details on my custom page,

Code:

  <?php 
set_time_limit(0); //THIS SCRIPT JUST INITIALS THE PROFILE TO BE RUN VIA MAGENTO ADMIN "RUN PROFILE IN POPUP". Its the same thing as click just via this file that you can run via cron 
$profileId = 1; // SYSTEM - IMPORT/EXPORT - DATAFLOW PROFILES PROFILES <-- you need to go into your magento admin and grab the exact profile ID 
require_once 'app/Mage.php'; 

umask(0); 
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 
$sku = 10; //this sku you get it from your text box. 
$_product = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect(array(
    'name',
    'sku',
    'price',
    'thumbnail' 
))->addAttributeToFilter('status', 1)->addAttributeToFilter('sku', array(
    'in' => $sku 
)); 
$imageHelper = Mage::helper('catalog/image'); 

foreach($_product as $prod) 
{
    $name = $prod->getName();
    $price = $prod->getPrice();
    $thumbnail = $imageHelper->init($prod, 'thumbnail')->resize(150, 220); 
} 

echo "Name: ", $name; 
echo "<br />";
echo "Sku: ", $sku; 
echo "<br />";
echo "Price: ", $price; 
echo "<br />";
echo "Image: ", $thumbnail; ?>

How can I display product image instead of image path.

2

Answers


  1. I saw your original question with the code and I think you’re using Magento
    So you can do it like this

    Load product by ID

    Mage::getModel('catalog/product')->load(.....)
    

    Or get all products

    Mage::getModel('catalog/product')->getCollection() .....
    

    Get product image

    Mage::helper('catalog/image')->init($_product, 'image') // You can change to another image code
    

    Or get all media images

    $_product->getMediaGalleryImages() // It's array, you need to loop through it to get image detail
    

    Display like image instead a url

    <img src="<?php echo $image_url ?>">
    

    Take your time and read about this HTML Images

    Login or Signup to reply.
  2. Here is my answer:

    echo "<img src='".$thumbnail ."'>";
    

    Thank You @Hung Vo

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search