Jump to content

Prestashop create cart programatically and get total value with discounts


KLewi

Recommended Posts

Prestashop 1.6

Hi!

I have to estimate the cart value based on a set of product. For this I have created a custom controller, in which controller I have created a new cart
 

Quote

 

$cart = new Cart();

$cart->id_lang = (int)$this->context->cookie->id_lang;

$cart->id_currency = (int)$this->context->cookie->id_currency;

$cart->id_guest = (int)$this->context->cookie->id_guest;

$cart->id_shop_group = (int)$this->context->shop->id_shop_group;

$cart->id_shop = $this->context->shop->id;

if ($this->context->cookie->id_customer) {

$cart->id_customer = (int)$this->context->cookie->id_customer;

$cart->id_address_delivery = (int)Address::getFirstCustomerAddressId($cart->id_customer);

$cart->id_address_invoice = (int)$cart->id_address_delivery;

} else {

$cart->id_address_delivery = 0;

$cart->id_address_invoice = 0;

}

$cart->save();

$this->context->cart = $cart;

CartRule::autoAddToCart($this->context);

 

How can I add products to this cart to know what the total amount of the basket will be? 
Also, how can I make sure that all cart rules that are valid for this cart are deducted from the total?

 

Edited by KLewi (see edit history)
Link to comment
Share on other sites

$total_discounts_tax_include = $cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS);

$total_discounts_tax_exclude = $cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS);

getSummaryDetails

getOrderTotal

All information can be found at ./classes/Cart.php

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...