Menu Close
    Start a Project Request quote Reading list Switch to dark mode

    Create order total in opencart

    In the series of module development tutorial, we have learned about building modules, shipping method in the previous blogs. Now, we will learn about building an order total.

    Order total is one of the major parts of an e-commerce platform. If we need to show any kind of extra cost in the cart or totals and sub-totals then we have to use the order totals. If we need to give some discount or to add up some shipping cost or tax then we need the order total to come into the process. So, here, we will learn to build the order total.

    If you don’t know what are order totals in the Opencart then you must visit Admin->Extensions->Order Totals (Opencart version 2.2.x and lower). With the list visible, you will get an idea of order totals.

    We will begin with the building of language file named ‘test_total.php’ in the admin->language->en-gb->total. Here’s the code for that language file.

    Now, we will progress on to the controller of the order total. We will build a file named ‘test_total.php’ in the admin->controller->total. Here’s the code for controller file:

    The backend(admin) code for the order total files is same as of modules, payment and shipping just the folder get changes accordingly.

    Now, we will proceed to the view file and we will create a view file named ‘test_total.tpl’ in the admin->view->template->total. The code for the view file is here:

    So, the backend part is complete with these codes.

    Now, we have to create the front-end file. So, we will create a file named ‘test_total.php’ in catalog->model->total. There will be no controller or view files for the order total same as of shipping module. The code for the model file is here:

    We can access the order total in Extension->Order totals from the admin panel. Now, we have to install the order total named ‘Test-Total’ and then fill the fee and sort order value and then after enabling the status, click on the save button. The sort order will depict the order of the order total among other order totals.

    Now, on putting some product into the cart, the order total will automatically be added. As I have added 5 as fee from the backend so it’s adding $5 in front as well. See image.

    . . .


    Add Your Comment

    Be the first to comment.

    Back to Top
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again