Prestashop api - How to get the current cart contents

prestashop, shopping-cart, web-services

Solution

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

Problem

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?

Original source