1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Academic Free License (AFL 3.0)
  8. * that is bundled with this package in the file LICENSE_AFL.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/afl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category   design_default
  22. * @package    Mage
  23. * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
  24. * @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
  25. * @author        Nick Cron
  26. * @authorweb  www.njcmedia.com
  27. */
  28. ?>
  29. <?php
  30. $_related = $this->getProduct();
  31.  
  32. // get the parent id to skip
  33. $_parentid = $_related->getId();
  34.  
  35. if ($_related) {
  36. // get collection of categories this product is associated with
  37. $categories =$_related->getCategoryCollection()->addFieldToFilter('level','3') ->setPage(1, 1)->load();
  38.  
  39. // if the product is associated with any category
  40. if ($categories->count())
  41. foreach ($categories as $_category)
  42. {
  43.  
  44. ?>
  45.  
  46. <div class="box-collateral box-up-sell">
  47. <h2><?php echo $this->__('Related Product') ?></h2>
  48. <table cellspacing="0" id="upsell-product-table">
  49.  
  50. <tr>
  51.  
  52. <?php
  53.  
  54. $visibility = array(
  55. Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
  56. Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
  57. );
  58.  
  59. $products = Mage::getResourceModel('catalog/product_collection')
  60. ->addCategoryFilter($_category)
  61. ->addAttributeToSelect('small_image')
  62. ->addAttributeToFilter('visibility', $visibility);
  63.  
  64. // Limiting to In Stock
  65. Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($products);
  66.  
  67. $products->getSelect()->order(new Zend_Db_Expr('RAND()'));
  68. $products->getSelect()->limit(6);
  69.  
  70. // count the number of displayed products
  71. $_i=0;
  72.  
  73. foreach ( $products as $productModel ){
  74. $_related = Mage::getModel('catalog/product')->load($productModel->getId());
  75. $_realtedid = $_related->getId();
  76.  
  77. // prevents displaying the same product your are already on
  78. if ($_realtedid != $_parentid && $_i<7):
  79.  
  80. ?>
  81.  
  82. <td style="padding-right:15px;">
  83. <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>
  84.  
  85. <?php echo $this->getPriceHtml($_related, true) ?>
  86. <?php echo $this->getReviewsSummaryHtml($_related) ?>
  87. </td>
  88.  
  89. <?php
  90. // increment displayed products
  91. $_i++;
  92. endif;
  93. }
  94. ?>
  95.  
  96. </tr>
  97.  
  98. <?php }
  99. }
  100. ?>
  101. </table>
  102. <script type="text/javascript">decorateTable('upsell-product-table')</script>
  103. </div>

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

magento upsell from cur_category的更多相关文章

  1. magento问题集

    magento产品页面价格出现2遍 In app\design\frontend\default\default\template\catalog\product\view\type\Simple.p ...

  2. LNMP环境magento常见错误

    一.安装报404错误 git clone 下最新代码,跳转到index/install 安装时出现404错误 需要把伪静态规则加到nginx配置文件中: # # The default server ...

  3. Magento 新增字段的值读写丢失原因

    某实体新增字段handreturn_status,欲操作之: $order_info = Mage::getModel('sales/order')->load($order_id); //se ...

  4. MAGENTO - APACHE SOLR INTEGRATION - PART II (SETUP)

    MAGENTO - APACHE SOLR INTEGRATION - PART II (SETUP) Tue, 03/01/2011 - 18:30 Tweet Development E-Comm ...

  5. Magento学习第一课——目录结构介绍

    Magento学习第一课--目录结构介绍 一.Magento为何强大 Magento是在Zend框架基础上建立起来的,这点保证了代码的安全性及稳定性.选择Zend的原因有很多,但是最基本的是因为zen ...

  6. magento事件(event)的dispatchEvent(分发)和catchEvent(获取)

    当你需要扩展Magento的核心的功能时有两个选择: (1)重写(override)Magento的core classes (2)使用Magento的event-driven 机制 由于你只能重写一 ...

  7. Magento table rates表运费设置

    在magento中集成了Table rate表运费,这种运输方式.表运费就是我们自己写个运费表,根据距离和商品重量设置运费,制做成一张csv格式的表,导入到magento中,来实现运费的控制. 在我的 ...

  8. magento搬家

    将原来网站文件中的var文件中的cache和session文件删除,将media中的缓存文件删除.然后将所有文件制作成一个压缩包,以减少文件体积,方便转移. 将压缩包转移到新的服务器域名指向的文件夹, ...

  9. magento后台paypal设置

    如何在magento后台设置paypal呢? 这边把整理的简单跟大家分享一下. 1.system->config-paypel1.1 Merchant Country 设置国家1.2 Email ...

随机推荐

  1. 深入解释yield和Generators

    生成器和yield关键字可能是Python里面最强大的最难理解的概念之一(或许没有之一), 但是并不妨碍yield成为Python里面最强大的关键字,对于初学者来讲确实非常难于理解,来看一篇关于yie ...

  2. Django框架(一)-Django初识

    Django初识 一.Web框架本质—自己实现Web框架 1.所有的Web应用本质上就是一个socket服务端,而用户的浏览器就是一个socket客户端 import socket sk = sock ...

  3. 直接插入排序(初级版)之C++实现

    直接插入排序(初级版)之C++实现 一.源代码:InsertSortLow.cpp /*直接插入排序思想: 假设待排序的记录存放在数组R[1..n]中.初始时,R[1]自成1个有序区,无序区为R[2. ...

  4. 排序算法之快速排序Java实现

    排序算法之快速排序 舞蹈演示排序: 冒泡排序: http://t.cn/hrf58M 希尔排序:http://t.cn/hrosvb  选择排序:http://t.cn/hros6e  插入排序:ht ...

  5. [Luogu5105]不强制在线的动态快速排序

    首先集合去重不影响答案,然后打表易得连续自然数平方差异或前缀和的规律,于是问题就变为在线维护区间求并同时更新答案,set记录所有区间,每次暴力插入删除即可.由于每个区间至多只会插入删除一次,故均摊复杂 ...

  6. [BZOJ4557][JLOI2016]侦察守卫(树形DP)

    首先可以确定是树形DP,但这里存在跨子树的信息传递问题,这里就需要“借”的思想. f[i][j]表示i子树内所有点都被覆盖到,且i以外j层内的点都能被覆盖到 的方案数. g[i][j]表示i子树内离i ...

  7. 汇编代码中db,dw,dd的区别

    db定义字节类型变量,一个字节数据占1个字节单元,读完一个,偏移量加1 dw定义字类型变量,一个字数据占2个字节单元,读完一个,偏移量加2 dd定义双字类型变量,一个双字数据占4个字节单元,读完一个, ...

  8. php curl 发送get和post请求示例

    <?php final class HttpClient { const TIME_OUT = 10; static function get($url) { $ch = curl_init() ...

  9. 关于List Map Set的线程安全的问题

    常见的ArrayList  LinkedList  HashMap TreeMap LinkedHashMap HashSet TreeSet LinkedHashSet 都是线程不安全的.如果要使用 ...

  10. 【spark系列3】spark开发简单指南

    分布式数据集创建之textFile         文本文件的RDDs能够通过SparkContext的textFile方法创建,该方法接受文件的URI地址(或者机器上的文件本地路径,或者一个hdfs ...