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/

  • 相关阅读:
    水平触发与边缘触发
    Leetcode935 骑士拨号器
    leetcodeF47 礼物的最大价值
    leetcodeF42 连续子数组的最大和
    leetcode12 矩阵中的路径 回溯算法
    leetcode14-II 剪绳子II DP 解法配合快速乘取模
    leetcode17.16 按摩师DP
    leetcode530 二叉树的最小绝对差
    PCB genesis大孔加小孔(即卸力孔)实现方法
    PCB genesis短槽加引导孔实现方法
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3402447.html
Copyright © 2011-2022 走看看