Magento如何在购物车页面下方显示向上销售的产品

时间:2015-01-28 21:37:37

标签: magento cart

我想在购物车页面下显示加售产品,但我无法找到我们如何做到这一点。我可以在购物车页面下调用upsell文件。但产品没有..文件内的代码是:

<?php if(count($this->getItemCollection()->getItems())): ?>
<div class="box-collateral box-up-sell">
    <div class="box-title">
        <h2><?php echo $this->__('You may also be interested in the following product(s)') ?></h2>
    </div>
    <ul class="products-grid" id="upsell-product-list">
    <?php // $this->setColumnCount(5); // uncomment this line if you want to have another number of columns. also can be changed in layout ?>
    <?php $this->resetItemsIterator() ?>
    <?php for($_i=0;$_i<$this->getRowCount();$_i++): ?>
        <?php for($_j=0;$_j<$this->getColumnCount();$_j++): ?>
            <?php if($_link=$this->getIterableItem()): ?>
            <li class="item">
                <a href="<?php echo $_link->getProductUrl() ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_link, 'small_image')->resize(135) ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($_link->getName()) ?>" title="<?php echo $this->htmlEscape($_link->getName()) ?>" /></a>
                <h3 class="product-name"><a href="<?php echo $_link->getProductUrl() ?>"><?php echo $this->htmlEscape($_link->getName()) ?></a></h3>
                <?php echo $this->getReviewsSummaryHtml($_link) ?>
                <?php echo $this->getPriceHtml($_link, true, '-upsell') ?>
            </li>
            <?php endif; ?>
        <?php endfor; ?>
    <?php endfor; ?>
    </ul>
    <script type="text/javascript">decorateList('upsell-product-list', 'none-recursive')</script>
</div>
<?php endif ?>

如果有人有任何想法请发信息。我

1 个答案:

答案 0 :(得分:0)

Magento默认会在购物车页面上显示交叉销售产品。如果您检查checkout.xml文件,您将看到它。

<block type="checkout/cart_crosssell" name="checkout.cart.crosssell" as="crosssell" template="checkout/cart/crosssell.phtml"/>

如果您想在购物车页面上显示追加销售,则需要创建一个自Mage_Checkout_Block_Cart_Crosssell类扩展的自定义块。在您的自定义版块中,更新_getCollection方法以使用向上销售,而不是像这样的交叉销售产品:

 protected function _getCollection()
    {
        $collection = Mage::getModel('catalog/product_link')->useUpSellLinks()
            ->getProductCollection()
            ->setStoreId(Mage::app()->getStore()->getId())
            ->addStoreFilter()
            ->setPageSize($this->_maxItemCount);
        $this->_addProductAttributesAndPrices($collection);

        Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
        Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);

        return $collection;
    }

最后通过布局更新添加您的向上销售区块。您可以将相同的模板文件保留为交叉销售块。

<checkout_cart_index>
    <reference name="content">
        <block type="module_namespace/upsell" name="checkout.cart.upsell" as="upsell" template="checkout/cart/crosssell.phtml"/>
    </reference>
</checkout_cart_index>