Reading list Switch to dark mode

    Order Totals In Opencart

    Updated 2 August 2023

    In Opencart Order total modules are those which decrease or increase the total price of the total order. Some of the order totals which decrease the total price are coupons, store credits, reward points, etc.

    Some of the order totals which increase the total price are Handling fees, low order fees, taxes, etc. When we add a product to the cart then it adds that product to the cart first and then updates the cart pop-up at the front end.

    So today we will learn about how Opencart shows the taxes, shipping, coupon, vouchers, etc (These are called order totals) in the cart popup and updates these totals in each product add through AJAX.

    When we click on the “Add To Cart” button then first Opencart makes an AJAX call to the “add” functions that are present in the “checkout/cart” controller to add the product to the database by checking other Order totals (If present).


    Searching for an experienced
    Opencart Company ?
    Find out More
    * @category Webkul 
    * @package Order Totals In Opencart Blog 
    * @author [Webkul] <[<>]> 
    * @copyright Copyright (c) Webkul Software Private Limited ( 
    * @license 
    if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
        $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);
    $json['total'] = sprintf($this->language->get('text_items'), $this->cart->countProducts() + (isset($this->session->data['vouchers']) ? count($this->session->data['vouchers']) : 0), $this->currency->format($total, $this->session->data['currency']));

    Opencart fetches all the Order totals by call the “getExtensions(‘total)”.


    Then checks each order totals status and calls “getTotal()” function of each enabled Order totals to fetch the amount.


    And return the text for update the cart button text.

    <pre>1 item(s) - $337.99</pre>

    After success of First AJAX call then Opencart calls the second AJAX call to update the cart popup by making an AJAX calls to the “info” function of “common/cart”.


    Info function call the index function of “common/cart” controller

    public function info() {

    Then Open cart does the same things which have been done in the first AJAX call but difference is that here all the elements transfer to the cart.tpl file by data variable to show the details.


    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*

    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home