Search code examples
phpsortingopencart-3

openCart 3 - How to get total price at checkout page?


I need to find out how to get total price at checkout page (confirm.php) to plus my own price. I need to check total and if it's more then 5K then delivery service is free, otherwise delivery service has a fixed price.

$this->$cart->getTotal(); // it returns totals not including coupons
$this->$cart->getSubTotal(); // it returns products totals not including coupons

Does anyone know how to get total including coupons/vouchers...?


Solution

  • $this->load->model('setting/extension');
    $sort_order = array();
    $results = $this->model_setting_extension->getExtensions('total');
    foreach ($results as $key => $value) {
        $sort_order[$key] = $this->config->get('total_' . $value['code'] . '_sort_order');
    }
    array_multisort($sort_order, SORT_ASC, $results);
    foreach ($results as $result) {
        if ($this->config->get('total_' . $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);
    

    here in $totals you will have all total data, and you can use that to get total as desired by calculating that array values

    This you will fine in confirm.php

    Just print $totals and check then you got the data and calculate total with voucher too by adding both data