Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prestashop api - How to get the current cart contents

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?

like image 235
user2142189 Avatar asked Dec 21 '22 08:12

user2142189


1 Answers

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

like image 175
Altaf Hussain Avatar answered Jan 02 '23 11:01

Altaf Hussain