Magento获取购物车中的所有产品而非最新产品

问题描述 投票:8回答:3

我正在调整现代主题来创建一个新主题。

我需要在客户购物篮中显示所有产品。我有这个代码,目前它最多只能显示三个项目。是否有一个不同的命令我可以使用而不是getRecentItems()来显示他们篮子里的所有物品?我尝试使用getAllItems(),但这似乎没有做任何事情。

 <?php $items = $this->getRecentItems();?>
        <?php if(count($items)): ?>
            <ol id="cart-header" class="mini-products-list">
                <?php foreach($items as $item): ?>
                    <?php echo $this->getItemHtml($item) ?>
                <?php endforeach; ?>
            </ol>
        <?php else: ?>
            <?php echo $this->__('There are no items in your shopping Basket.') ?>
        <?php endif ?>

有任何想法吗 ?

php magento e-commerce magento-1.7
3个回答
19
投票

入住System > Configuration > Checkout > Shopping Cart Side Bar

有一个设置可以设置迷你购物车中可见的产品数量。

最大显示最近添加的项目默认为3.将其增加到您想要的值,或者更确切地说是一个高数字,以便始终显示购物车中的所有产品。

编辑:要根据您的评论覆盖默认的magento行为,您可以使用以下内容。

<?php
    $session= Mage::getSingleton('checkout/session');
    $items = $session->getQuote()->getAllItems();
?>
        <?php if(count($items)): ?>
            <ol id="cart-header" class="mini-products-list">
                <?php foreach($items as $item): ?>
                    <?php echo $this->getItemHtml($item) ?>
                <?php endforeach; ?>
            </ol>
        <?php else: ?>
            <?php echo $this->__('There are no items in your shopping Basket.') ?>
        <?php endif ?>

1
投票

Mage_Checkout_Block_Cart_Sidebar方法getRecentItems()接受一个计数参数,只需以这种方式调用它来检索完整的购物车项目。

<?php $items = $this->getRecentItems(10000);?>

0
投票

我同意实用性。感谢您分享购物车侧栏部分。我有一个模块,列出了结帐页面中的购物车项目。这是我的代码供您参考。

$quoteObject = $this->getQuote();
foreach($quoteObject->getAllItems() as $item)
{
  //do what you want here.
}

希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.