问题
I'm trying to get all the product images of all the products in the shopping cart. I've used the following code:
$_item = $this->getItem();
$_product = Mage::getModel('catalog/product')->load($_item->getProductId());
foreach ($_product->getMediaGalleryImages() as $image) {
echo var_export($image->getUrl());
echo "<br>";
}
But this only displays all the images of the first produuct in the shopping cart. I've tried it this way:
foreach ($this->getMediaGalleryImages() as $image) {
echo var_export($image->getUrl());
echo "<br>";
}
But this doesn't return anything. How can I get all the images of all the products?
回答1:
Use $this->getProductThumbnail()->resize(50,50)
to retrieve the thumbnail image.
Use this example to get a different kind of image from the product:
$_product = $this->getItem()->getProduct();
Mage::helper('catalog/image')->init($_product, 'small_image')->resize(100,100);
来源:https://stackoverflow.com/questions/27035017/magento-get-product-images-in-shoppping-cart