Prestashop api - How to get the current cart contents

user2142189 picture user2142189 · Mar 7, 2013 · Viewed 7.4k times · Source

I'm new to Prestashop, I cant find examples anywhere of how to get the current cart contents. I can get a list of all carts, but how do I get the current users cart?

Answer

Altaf Hussain picture Altaf Hussain · Mar 9, 2013

it is easy and simple. I am considering you are using PS 1.5.x

In controllers other than cart controller

  $cart = new Cart($this->context->cookie->id_cart); 

or in an class

 $context = new Context();
 $cart = new Cart($context->cookie->id_cart);

Now the $cart is an object, and it has all the current cart data.

You can also get the cart products by calling getProducts like below

 $cartProducts = $cart->getProducts();

Hope this will help.

Please note that code is not tested and is just a sample code for your idea.

Thank you