Magento get product images in shoppping cart

限于喜欢 提交于 2019-12-12 04:53:17

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!