Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 105 Vote(s) - 3.34 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prestashop api - How to get the current cart contents

#1
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?
Reply

#2
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
Reply

#3
For **PS 1.4.X** you can get using `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;
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through