0

I have added a form onto the bottom of the cart page, and changed the cart page to redirect to my own custom page.

This custom page currently just outputs the submitted data from the previous page, like so: print_r($_POST);

This produces the following output:

Array
(
    [form_key] => 2AJOmd7GhFVICntG
    [cart] => Array
        (
            [20] => Array
                (
                    [qty] => 1
                )
        )
)

So my question is, how can I get at all the cart data from the form_key.

A solution in pure PHP would be preferable.

  • Quick question, whats stopping you from using Mage::getSingleton('checkout/session')->getQuote()->getAllItems() to get the cart from the users session? – Muzza Aug 4 '15 at 13:40
  • Nothing - and this seems like a much better way of achieving what I was trying to achieve. Please forgive my ignorance - I've been thrown at Magento with zero experience and I'm trying to muddle my way through. Please add this as an answer! – Jimmery Aug 4 '15 at 13:42
  • 1
    No problem, Its a long road ahead Jimmery, good luck and enjoy it! – Muzza Aug 4 '15 at 13:49
3

The easiest way to achieve what you are after is to retrieve the cart from the users session like so:

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

With this in mind you could then get all visible products in the cart:

$visibleItems = $sessionQuote->getAllVisibleItems();

And loop through them to get Item Quantities, names etc:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.