zoukankan      html  css  js  c++  java
  • magento upsell from cur_category

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

  • 相关阅读:
    ObjecT4:On-line multiple instance learning (MIL)学习
    目标跟踪ObjectT综述介绍
    CV与IP:基础,经典以及最近发展
    PythonGIS可视化—Matplot basemap工具箱
    SciPy和Numpy处理能力
    mwArray与C++接口
    使用QT的一些小Tipster
    C++调用Matlab 注意事项
    Qwt--散点图/函数图
    **PCL:嵌入VTK/QT显示(Code^_^)
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3402447.html
Copyright © 2011-2022 走看看