资源描述
以下是我修改后的代码,效果图在代码下面:
<!--for show other product-->
<?php $categories = $_product->getCategoryIds(); ?>
<?php
$result = array();
foreach($categories as $cat_id) {
$category = Mage::getModel('catalog/category');
$category->load($cat_id);
$collection = $category->getProductCollection();
foreach ($collection as $product) {
$result[] = $product->getId();
}
}
?>
<div class="box-others-also-like">
<h2>You May Also Like</h2>
<div class="like-left">
<ul>
<?php
if(sizeof($result) >= 4)
{
$ourneed = array_rand($result,4);
foreach($ourneed as $cc)
{
$thisproduct= Mage::getModel('catalog/product')->load($result[$cc]);
?>
<li>
<div class="like-image"><a href="<?php echo $thisproduct->getProductUrl(); ?>" title="<?php echo $thisproduct->getName(); ?>" ><img src="<?php echo $this->helper('catalog/image')->init($thisproduct, 'small_image')->resize(150) ?>" width="150" height="150" alt="<?php echo $thisproduct->getName(); ?>" /></a></div>
<div class="like-word">
<div class="like-word-a"><a href="<?php echo $thisproduct->getProductUrl(); ?>" title="<?php echo $thisproduct->getName(); ?>"><?php echo $thisproduct->getName(); ?></a></div>
<?php echo $this->getPriceHtml($thisproduct, true, '-new') ?></div>
</li>
<?php } ?>
<?php
}else
{
foreach($result as $cc)
{
$thisproduct= Mage::getModel('catalog/product')->load($cc);
?>
<li>
<a href="<?php echo $thisproduct->getProductUrl(); ?>" title="<?php echo $thisproduct->getName(); ?>" ><img src="<?php echo $this->helper('catalog/image')->init($thisproduct, 'small_image')->resize(150) ?>" width="150" height="150" alt="<?php echo $thisproduct->getName(); ?>" /></a>
<p><?php echo $thisproduct->getName(); ?></p>
</li>
<?php
}
}
?>
</ul>
</div>
<div class="like-right">
<ul>
<?php
if(sizeof($result) >= 4)
{
$ourneed = array_rand($result,4);
foreach($ourneed as $cc)
{
$thisproduct= Mage::getModel('catalog/product')->load($result[$cc]);
?>
<li>
<div class="like-image"><a href="<?php echo $thisproduct->getProductUrl(); ?>" title="<?php echo $thisproduct->getName(); ?>" ><img src="<?php echo $this->helper('catalog/image')->init($thisproduct, 'small_image')->resize(150) ?>" width="150" height="150" alt="<?php echo $thisproduct->getName(); ?>" /></a></div>
<div class="like-word">
<div class="like-word-a"><a href="<?php echo $thisproduct->getProductUrl(); ?>" title="<?php echo $thisproduct->getName(); ?>"><?php echo $thisproduct->getName(); ?></a></div>
<?php echo $this->getPriceHtml($thisproduct, true, '-new') ?></div>
</li>
<?php } ?>
<?php
}else
{
foreach($result as $cc)
{
$thisproduct= Mage::getModel('catalog/product')->load($cc);
?>
<li>
<a href="<?php echo $thisproduct->getProductUrl(); ?>" title="<?php echo $thisproduct->getName(); ?>" ><img src="<?php echo $this->helper('catalog/image')->init($thisproduct, 'small_image')->resize(150) ?>" width="150" height="150" alt="<?php echo $thisproduct->getName(); ?>" /></a>
<p><?php echo $thisproduct->getName(); ?></p>
</li>
<?php
}
}
?>
</ul>
</div>
</div>
<!--for show other product-->
P.S:
20120426修订版,修复了推荐产品价格与当前产品价格一样的BUG,主要将原来的语句
<?php echo $this->getPriceHtml($_product, true, '-new') ?>
修改为以下语句
<?php echo $this->getPriceHtml($thisproduct, true, '-new') ?>
相应的CSS样式:
/************************详细页推荐产品*******************/
.box-others-also-like { height:670px; }
.like-left { float:left; width:49%; }
.like-right { float:right; width:49%; }
.like-left li, .like-right li { height:150px; margin-bottom:10px; border:1px #bbbbbb solid; }
.like-image { float:left; width:150px; }
.like-word { float:right; width:150px; margin:0 10px; }
.like-word-a { font-size:14px; margin-top:5px; height:80px; }
展开阅读全文