简体   繁体   English

如何遍历Magento购物车中的所有商品?

[英]How to loop through all items in the Magento cart?

Okay, I have no idea how to do this simple thing. 好吧,我不知道怎么做这个简单的事情。 All I need is to loop through the 3 items that I have currently in the cart, so I can get item information about each one - like product category, item name, blah blah blah. 我只需循环浏览购物车中的3件商品,这样我就可以获得每件商品的商品信息 - 例如商品类别,商品名称,等等等等。 I have googled this for an hour already, and have not found anything on what seems to be such a simple task. 我已经用谷歌搜索了一个小时,并且没有找到任何似乎是如此简单的任务的东西。 Getting quote, and then getAllItems() returns nothing for me. 获取引用,然后getAllItems()为我返回任何内容。 Anybody have any ideas / links? 有人有任何想法/链接?

Thanks. 谢谢。

Are you sure getting the quote doesn't work? 你确定报价不起作用吗? The following code should work: 以下代码应该有效:

$session = Mage::getSingleton('checkout/session');
foreach ($session->getQuote()->getAllItems() as $item) {
    print_r($item->getData());
}

Of course, if you're not doing it from inside a Magento template/controller/model then you'll need to set up the environment appropriately: 当然,如果你没有在Magento模板/控制器/模型中进行,那么你需要适当地设置环境:

require_once 'app/Mage.php';
umask(0);
Mage::app();

/* Then put your code here.. */

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM