收藏 分销(赏)

magento产品详细页随机显示产品.doc

上传人:pc****0 文档编号:7444072 上传时间:2025-01-04 格式:DOC 页数:4 大小:254KB 下载积分:10 金币
下载 相关 举报
magento产品详细页随机显示产品.doc_第1页
第1页 / 共4页
magento产品详细页随机显示产品.doc_第2页
第2页 / 共4页


点击查看更多>>
资源描述
以下是我修改后的代码,效果图在代码下面: <!--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; }
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 百科休闲 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服