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
Here is the way I've found to load all image data for all products in a collection. I am not sure at the moment why its needed to switch from Mage::getModel to Mage::helper and reload the product, but it must be done. I've reverse engineered this code from the magento image soap api, so I'm pretty sure its correct.
I have it set to load products with a vendor code equal to '39' but you could change that to any attribute, or just load all the products, or load whatever collection you want (including the collections in the phtml files showing products currently on the screen!)
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addFieldToFilter(array(
array('attribute'=>'vendor_code','eq'=>'39'),
));
$collection->addAttributeToSelect('*');
foreach ($collection as $product) {
$prod = Mage::helper('catalog/product')->getProduct($product->getId(), null, null);
$attributes = $prod->getTypeInstance(true)->getSetAttributes($prod);
$galleryData = $prod->getData('media_gallery');
foreach ($galleryData['images'] as &$image) {
var_dump($image);
}
}
get product images in magento using product id
$product_id = $_POST['product_id'];
$storeId = Mage::app()->getStore()->getId();
$loadpro = Mage::getModel('catalog/product')->load($product_id);
$mediaApi = Mage::getModel("catalog/product_attribute_media_api");
$mediaApiItems = $mediaApi->items($loadpro->getId());
foreach ($mediaApiItems as $item) {
//for getting existing Images
echo $item['file'];
}
You can try to replace $this->
by Mage::
in some cases. You need to convert to string.
In my case i'm using DirectResize extension (direct link), so my code is like this:
(string)Mage::helper('catalog/image')->init($_product, 'image')->directResize(150,150,3)
The ratio options (3rd param) are :
Update: other info and versions here
The common way, without plugin would be:
(string)Mage::helper('catalog/image')->init($_product, 'image')->resize(150)
You can replace 'image' with 'small_image' or 'thumbnail'.
// Let's load the category Model and grab the product collection of that category
$product_collection = Mage::getModel('catalog/category')->load($categoryId)->getProductCollection();
// Now let's loop through the product collection and print the ID of every product
foreach($product_collection as $product) {
// Get the product ID
$product_id = $product->getId();
// Load the full product model based on the product ID
$full_product = Mage::getModel('catalog/product')->load($product_id);
// Now that we loaded the full product model, let's access all of it's data
// Let's get the Product Name
$product_name = $full_product->getName();
// Let's get the Product URL path
$product_url = $full_product->getProductUrl();
// Let's get the Product Image URL
$product_image_url = $full_product->getImageUrl();
// Let's print the product information we gathered and continue onto the next one
echo $product_name;
echo $product_image_url;
}
$model = Mage::getModel('catalog/product'); //getting product model
$_products = $model->getCollection(); //getting product object for particular product id
foreach($_products as $_product) { ?>
<a href = '<?php echo $model->load($_product->getData("entity_id"))->getUrl_path(); ?>'> <img src= '<?php echo $model->load($_product->getData("entity_id"))->getImageUrl(); ?>' width="75px" height="75px"/></a>
<?php echo "<br/>".$model->load($_product->getData("entity_id"))->getPrice()."<br/>". $model->load($_product->getData("entity_id"))->getSpecial_price()."<br/>".$model->load($_product->getData("entity_id"))->getName()?>
<?php
You need set image type :small_image or image
echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(163, 100);