Magento 1.14.2.2 在 PLP 上翻转图像
Magento 1.14.2.2 Roll over image on PLP
嘿,我最近添加了一行代码,可以在产品列表页面滚动图像时显示缩略图。
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 文件时,我收到以下错误消息:
注意:未定义变量:_imgSize in /var/www/deploy/releases/20180227152715/app/design/frontend/my theme/my theme/template/catalog/product/list.phtml on line 56
我知道这里必须定义 _imgSize 变量
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
$_imgSize = null;//not defining rollover image deminsions
?>
我只是不知道 _imgSize 会被定义为什么。有人能指出我正确的方向吗?
谢谢
您为该函数提供的参数是像素大小。
这是它的定义:
/**
* 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;
}
嘿,我最近添加了一行代码,可以在产品列表页面滚动图像时显示缩略图。
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 文件时,我收到以下错误消息:
注意:未定义变量:_imgSize in /var/www/deploy/releases/20180227152715/app/design/frontend/my theme/my theme/template/catalog/product/list.phtml on line 56
我知道这里必须定义 _imgSize 变量
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
$_imgSize = null;//not defining rollover image deminsions
?>
我只是不知道 _imgSize 会被定义为什么。有人能指出我正确的方向吗?
谢谢
您为该函数提供的参数是像素大小。 这是它的定义:
/**
* 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;
}