开发者

Get shopping cart details in Magento

I want to get the shopping cart details, by using Magento's getQuote function. How c开发者_如何学Goan I do this?

$cart = Mage::getModel('checkout/cart')->getQuote();

When I print the $cart Page stops execution and blank page is shown. But when I write

$cart = Mage::getModel('checkout/cart')->getQuote()->getData();

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?


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. 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.


Get shopping cart items using getQuote() method

$cart = Mage::getModel('checkout/cart')->getQuote()->getItemsCollection();
echo "<pre>";
print_r($cart->getData());

Get Shopping Cart items without getQuote() method

$cart = Mage::getModel('checkout/cart')->getItems();
echo "<pre>";print_r($cart->getData());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜