Prestashop api - How to get the current contents of the basket

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

+4
source share
2 answers

simply and easily. I consider that you are using PS 1.5.x

In controllers other than the cart controller

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

or in class

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

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

You can also get items in the basket by calling getProducts, as shown below.

  $cartProducts = $cart->getProducts(); 

Hope this helps.

Please note that the code is untested and is just a sample code for your idea.

thanks

+11
source

For PS 1.4.X you can use getProducts()

 $product_array = $this->getProducts(); print_r($product_array); 

Example:

 public function getSubTotal() { $product_array = $this->getProducts(); foreach($product_array as $product_item) { $sub_total += $product_item['price'] * $product_item['cart_quantity']; } return $sub_total; } 
0
source

All Articles