Find count of products and total price for added in cart

A

Anonymous

Guest
The solution is for opencart.
Add session variable in catalog/controller/checkout/cart.php like this:

Find this line:
$this->data['products'] = array();

Add this code block
//count no of products added to cart
if(count($this->cart->getProducts())){
$_SESSION['count_2'] = count($this->cart->getProducts());
}

Thanks find this code block:
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$total = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']);
} else {
$total = false;
}


Add this line:
$_SESSION['total_2'] = $total;

Now find this code block:
$this->response->setOutput($this->render());
} else {


Add this code block:
$_SESSION['count_2'] = "";
$_SESSION['total_2'] = "";


Here you can see we are using the opencart function and store values in session.
Now go to your page where you want to display these values and add this code block:

For count of product added in cart:
<?php if(isset($_SESSION['count_2']) && $_SESSION['count_2'] != ""){
echo $_SESSION['count_2'];
} else { echo '0';} ?>


For total price of products added in cart:
<?php if(isset($_SESSION['total_2']) && $_SESSION['total_2'] != ""){
echo $_SESSION['total_2'];
} else { echo '$0.00';} ?>


Problem solved. :)
 
Back
Top