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