<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category   design_default
* @package    Mage
* @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
* @author        Nick Cron
* @authorweb  www.njcmedia.com
*/
?>
<?php
$_related = $this->getProduct(); // get the parent id to skip
$_parentid = $_related->getId(); if ($_related) {
// get collection of categories this product is associated with
$categories =$_related->getCategoryCollection()->addFieldToFilter('level','3') ->setPage(1, 1)->load(); // if the product is associated with any category
if ($categories->count())
foreach ($categories as $_category)
{ ?> <div class="box-collateral box-up-sell">
<h2><?php echo $this->__('Related Product') ?></h2>
<table cellspacing="0" id="upsell-product-table"> <tr> <?php $visibility = array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
); $products = Mage::getResourceModel('catalog/product_collection')
->addCategoryFilter($_category)
->addAttributeToSelect('small_image')
->addAttributeToFilter('visibility', $visibility); // Limiting to In Stock
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($products); $products->getSelect()->order(new Zend_Db_Expr('RAND()'));
$products->getSelect()->limit(6); // count the number of displayed products
$_i=0; foreach ( $products as $productModel ){
$_related = Mage::getModel('catalog/product')->load($productModel->getId());
$_realtedid = $_related->getId(); // prevents displaying the same product your are already on
if ($_realtedid != $_parentid && $_i<7): ?> <td style="padding-right:15px;">
<a href="<?php echo $_related->getProductUrl() ?>"><img src="<?php echo $this->helper('catalog/image')->init($_related, 'small_image')->resize(100) ?>" width="100" height="100" alt="<?php echo $this->htmlEscape($_related->getName()) ?>" /></a> <?php echo $this->getPriceHtml($_related, true) ?>
<?php echo $this->getReviewsSummaryHtml($_related) ?>
</td> <?php
// increment displayed products
$_i++;
endif;
}
?> </tr> <?php }
}
?>
</table>
<script type="text/javascript">decorateTable('upsell-product-table')</script>
</div>

http://www.njcmedia.com/2011/04/auto-populate-cross-sell-with-products-from-current-category-magento/

最新文章

  1. Leetcode 笔记 35 - Valid Soduko
  2. Python中两种处理错误方法的比较
  3. C# 设置word文档页面大小
  4. Linux系统有7个运行级别(runlevel)
  5. SQLServer数据库监控代码
  6. ctype.h库函数----字符操作函数
  7. 小谈pointer和relation
  8. 1.PHP内核探索:从SAPI接口开始
  9. armv8(aarch64)linux内核中flush_dcache_all函数详细分析【转】
  10. gpg --verify之&quot;Can&#39;t check signature: No public key&quot;
  11. 深入浅出Nodejs读书笔记(转)
  12. plot的实践。
  13. vsim生成VCD波形文件(verilog)
  14. Effective Java2读书笔记-创建和销毁对象(四)
  15. ASP.NET MVC C#知识点提要
  16. Git协作流程
  17. Django ORM多表操作
  18. jQuery使用(十二):工具方法之type()之类型判断
  19. expdp和impdp导入导出用法【转】
  20. [04-01]css组合选择器

热门文章

  1. Servlet的基本架构
  2. android 安全退出 activity
  3. POJ2104 K-th Number 不带修改的主席树 线段树
  4. [IOI2007]Miners
  5. bzoj 3611
  6. Vue集成微信开发趟坑:公众号以及JSSDK相关
  7. python类型比较的3种方式(转)
  8. 在Hadoop中重写FileInputFormat类以处理二进制格式存储的整数
  9. MEF(Managed Extensibility Framework)有选择性地使用扩展组件
  10. jvm执行流程