Search code examples
phpmysqltwigopencartopencart-3

displaying an extra field added to the database in opencart on the order page


I have added an extra field to the oc_order table in an Opencart database.

However, when I try and check if it exists or displays the data in that filed, I see nothing.

I have updated the catalogue/view/theme/account/order_info.twig file with the following to test both displaying the new field and using an if statement...

{{ newfield }} {% if newfield == true %}
                WORKS
                {% else %}
                NOT WORKING
            {% endif %}

I have a '1' inset in the database but I always get the 'NOT WORKING' displayed.

Any help much appreciated.


Solution

  • to retrieve data from db and show it on your template you should First, in corresponding controller file retrieve data from DB

    $query = "SELECT newfield FROM " . DB_PREFIX . "table_name ";
    

    Than you should declare it in the same controller file

    if ($query->rows) {
        $data['newfield'] = $query->row['newfield'];
    } else {
     $data['newfield'] = '';
    }
    

    Now you can retrieve it in your template

    {% if newfield %}
      WORKS {{ newfield }}
    {% else %}
      NOT WORKING
    {% endif %}