Hi,
the getTotal() function in system/library/cart/cart.php returns the wrong value. It returns the value _without_ shipping costs. If taxes are zero getSubTotal() and getTotal() return the same value.
To reproduce this:
echo($this->cart->getTotal());
Found this while porting an old payment plugin.
Opencart version: 2.3.0.2
And getTotal() dosen't include coupon values.
There is no function in the cart.php api to calculate the real total value
@gj12 if u had done ur research properly you will know coupon discount comes before tax.
But if I put stuff worth 1€ in the shopping cart and add one -0,20€ coupon, then getTotal returns 1€ not -0,80€. I need the total value that the customer is going to pay, there is no function in the cart API to do that, they all return the useless 1€ Value without coupon and shipping.
I found that there are some extension/total files are they now used instead of this cart API?
// Totals
$this->load->model('extension/extension');
$totals = array();
$taxes = $this->cart->getTaxes();
$total = 0;
// Because __call can not keep var references so we put them into an array.
$total_data = array(
'totals' => &$totals,
'taxes' => &$taxes,
'total' => &$total
);
// Display prices
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$sort_order = array();
$results = $this->model_extension_extension->getExtensions('total');
foreach ($results as $key => $value) {
$sort_order[$key] = $this->config->get($value['code'] . '_sort_order');
}
array_multisort($sort_order, SORT_ASC, $results);
foreach ($results as $result) {
if ($this->config->get($result['code'] . '_status')) {
$this->load->model('extension/total/' . $result['code']);
// We have to put the totals in an array so that they pass by reference.
$this->{'model_extension_total_' . $result['code']}->getTotal($total_data);
}
}
$sort_order = array();
foreach ($totals as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}
array_multisort($sort_order, SORT_ASC, $totals);
}
$data['total'] = $this->currency->format($total, $this->session->data['currency']);
Most helpful comment