获取Magento的购物车详细信息 [英] Get shopping cart details in Magento
问题描述
我想通过使用Magento的getQuote
函数来获取购物车的详细信息.我该怎么办?
I want to get the shopping cart details, by using Magento's getQuote
function. How can I do this?
$cart = Mage::getModel('checkout/cart')->getQuote();
当我打印$cart
页面时,将停止执行并显示空白页面.
但是当我写
When I print the $cart
Page stops execution and blank page is shown.
But when I write
$cart = Mage::getModel('checkout/cart')->getQuote()->getData();
并打印将显示的$cart
数组.但是我想跟踪完整的购物车数据(产品ID,产品价格和所有信息一样).
and print the $cart
an array will show. But I want to track the complete cart data (product Id,Product price like all information).
还有其他方法可以找到购物卡数据吗?
Is there any other method by which I can find the shopping card data?
推荐答案
getQuote
返回的对象是 getAllItems
,该方法反过来返回 Mage_Sales_Model_Quote_Item
对象.
The object returned by getQuote
is a Mage_Sales_Model_Quote
. It has a method getAllItems
which in turn returns a collection of Mage_Sales_Model_Quote_Item
objects.
所有这些意味着您可以检查以下产品:
All this means you can inspect products like this:
$cart = Mage::getModel('checkout/cart')->getQuote();
foreach ($cart->getAllItems() as $item) {
$productId = $item->getProduct()->getId();
$productPrice = $item->getProduct()->getPrice();
}
PS.您得到空白页的原因是因为转储整个对象可能会导致递归并且页面超时,或者PHP内存不足.使用getData
或debug
较为安全,但是如您所见,不会返回受保护/私有变量.
PS. The reason you get a blank page is because dumping a whole object likely fell into recursion and the page timed out, or PHP ran out of memory. Using getData
or debug
is safer but, as you saw, doesn't return the protected/private variables.
这篇关于获取Magento的购物车详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!