<?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/

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. 【CF 453A】 A. Little Pony and Expected Maximum(期望、快速幂)

    A. Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megabytes ...

  2. Opencv学习笔记5:Opencv处理彩虹图、铜色图、灰度反转图

    一.概述: 人类能够观察到的光的波长范围是有限的,并且人类视觉有一个特点,只能分辨出二十几种灰度,也就是说即使采集到的灰度图像分辨率超级高,有上百个灰度级,但是很遗憾,人们只能看出二十几个,也就是说信 ...

  3. 希尔排序之C++实现(高级版)

    希尔排序之C++实现(高级版) 一.源代码:ShellSortHigh.cpp /*希尔排序基本思想: 先取一个小于n的整数d1作为第一个增量,把文件的全部记录分组. 所有距离为d1的倍数的记录放在同 ...

  4. [BZOJ4571][SCOI2016]美味(贪心+主席树)

    经典问题,按位贪心,每次需要知道的是”在这一位之前的位都以确定的情况下,能否找到这一位是0/1的数”,这就是在询问[L,R]内某个值域区间是否有数,主席树即可. #include<cstdio& ...

  5. hdu 4277 USACO ORZ DFS

    USACO ORZ Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  6. Python学习笔记(七)—字典的学习

    总结内容: 1.字典的定义 2.字典的好处 3.字典的增删改查 4.字典常用方法及内置函数 5.字典的多层嵌套 6.字典的循环 7.字典小练习 1.字典的定义 字典是另一种可变容器模型,且可存储任意类 ...

  7. Notepad++源代码阅读——窗口封装与继承

    引言 近期在看Notepad++的源代码,学习学习Win32 原生API的开发技巧. 本文以Notepad++ 1.0版本的源代码为例讲解如何封装windows窗口,实现面向对象开发,如何通过窗口的继 ...

  8. Vue基础知识简介

    基础知识: vue的生命周期: beforeCreate/created.beforeMount/mounted.beforeUpdate/updated.beforeDestory/destorye ...

  9. java基础学习总结——开篇

    java是我学习的第一门编程语言,当初学习java基础的时候下了不少功夫,趁着这段时间找工作之际,好好整理一下以前学习java基础时记录的笔记,当作是对java基础学习的一个总结吧,将每一个java的 ...

  10. 为 UITextField 增加键盘偏移的模板化写法

    .h代码 #import <UIKit/UIKit.h> @interface ViewController : UIViewController<UITextFieldDelega ...