用鼠标在magento中的类别产品列表中显示默认图像的另一个图像


show another image on mouse over of the default image in category product list in magento

我正在开发一个magento网站。在我的类别产品列表页面(catalog/products/list.phtml)中。我需要在默认图像上的鼠标上实现交换图像功能。。。(这里每个产品都有2个或更多的图像,当鼠标悬停在默认图像上时,应该显示任何其他图像)

我是这幅漫画的新手。。

有人帮我吗。。

根据我所知,magento默认情况下只在类别页面上加载1个图像,即"small_image"。如果你想显示任何其他图像,你必须创建产品的完整实例

$_product = Mage::getModel('catalog/product')->load([product id]);

然后循环浏览媒体库:

foreach ($_product->getMediaGalleryImages() as $image) {
  // assign the image you want to the product object
  $_product->setImage($image->getFile());
} 

一旦你完成了,你可以使用访问新的图像

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

以上将返回200x350的图像的缓存版本的图像url
将其分配给图像的数据属性,并使用javascript更改mouseover上的img src
您可能需要考虑使用javascript预加载所有这些鼠标悬停图像,为用户提供最佳体验