Magento 1.14.2.2在PLP上翻转图像

时间:2018-02-28 15:20:30

标签: php magento

嘿我最近添加了一行代码,可以在产品列表页面中滚动图像时显示缩略图。

onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize($_imgSize) ?>';" onmouseout="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize($_imgSize) ?>';"/>

此行已添加到/template/catalog/product/list.phtml文件中,因此现在它的图像代码如下:

 <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(283, null)->keepFrame(false); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" 
        onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize($_imgSize) ?>';" onmouseout="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize($_imgSize) ?>';"/>
        </a>

检查我的system.log文件时,收到以下错误消息:

注意:未定义的变量:/ var / www / deploy / releases / 20180227152715 / app / design / frontend / my theme / my theme / template / catalog / product / list.phtml第56行中的_imgSize

我知道必须在这里定义_imgSize变量

<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
 $_imgSize = null;//not defining rollover image deminsions
?>

我只是不知道_imgSize将被定义为什么。有人能指出我正确的方向吗?

谢谢

1 个答案:

答案 0 :(得分:0)

您为此功能提供的参数是以像素为单位的尺寸。 这是它的定义:

/**
 * Schedule resize of the image
 * $width *or* $height can be null - in this case, lacking dimension will be calculated.
 *
 * @see Mage_Catalog_Model_Product_Image
 * @param int $width
 * @param int $height
 * @return Mage_Catalog_Helper_Image
 */
public function resize($width, $height = null)
{
    $this->_getModel()->setWidth($width)->setHeight($height);
    $this->_scheduleResize = true;
    return $this;
}
相关问题