且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用模型获取购物车中的商品?(Magento)

更新时间:2023-10-25 14:09:46

获取您的购物车对象(在会话中):

To get your cart object (in session) :

$quote = Mage::getSingleton('checkout/session')->getQuote();

然后,获取购物车中的商品列表:

Then, to get the list of items in the cart :

$cartItems = $quote->getAllVisibleItems();

然后,获取每个项目的计数:

Then, to get the count for each item :

foreach ($cartItems as $item) {
    echo $item->getQty();
}