Quantcast
Channel: Webkul Blog
Viewing all articles
Browse latest Browse all 5553

Order Totals In Opencart

$
0
0

In Opencart when we add a product in the cart then it adds that product to the cart first then update 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 as 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 which presents in the “checkout/cart” controller to add the product in the database by checking other Order totals (If present).

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

/**
 * @category Webkul
 * @package Order Totals In Opencart Blog
 * @author [Webkul] <[<http://webkul.com/>]>
 * @copyright Copyright (c) 2010-2017 Webkul Software Private Limited (https://webkul.com)
 * @license https://store.webkul.com/license.html
 */
<pre>Array
(
    [0] => Array
        (
            [extension_id] => 10
            [type] => total
            [code] => handling
        )

    [1] => Array
        (
            [extension_id] => 11
            [type] => total
            [code] => low_order_fee
        )

    [2] => Array
        (
            [extension_id] => 3
            [type] => total
            [code] => sub_total
        )

    [3] => Array
        (
            [extension_id] => 15
            [type] => total
            [code] => reward
        )

    [4] => Array
        (
            [extension_id] => 2
            [type] => total
            [code] => shipping
        )

    [5] => Array
        (
            [extension_id] => 12
            [type] => total
            [code] => coupon
        )

    [6] => Array
        (
            [extension_id] => 4
            [type] => total
            [code] => tax
        )

    [7] => Array
        (
            [extension_id] => 8
            [type] => total
            [code] => credit
        )

    [8] => Array
        (
            [extension_id] => 16
            [type] => total
            [code] => voucher
        )

    [9] => Array
        (
            [extension_id] => 5
            [type] => total
            [code] => total
        )

)
</pre>

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

/**
 * @category Webkul
 * @package Order Totals In Opencart Blog
 * @author [Webkul] <[<http://webkul.com/>]>
 * @copyright Copyright (c) 2010-2017 Webkul Software Private Limited (https://webkul.com)
 * @license https://store.webkul.com/license.html
 */
<pre>Array
(
    [0] => Array
        (
            [code] => sub_total
            [title] => Sub-Total
            [value] => 1959.93
            [sort_order] => 1
        )

    [1] => Array
        (
            [code] => tax
            [title] => VAT (20%)
            [value] => 391.986
            [sort_order] => 5
        )

    [2] => Array
        (
            [code] => tax
            [title] => Eco Tax (-2.00)
            [value] => 14
            [sort_order] => 5
        )

    [3] => Array
        (
            [code] => total
            [title] => Total
            [value] => 2365.916
            [sort_order] => 9
        )

)
</pre>

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

Then Opencart 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.


Viewing all articles
Browse latest Browse all 5553

Trending Articles