Cannot create Order History CSV download for customers in Prestashop-Collection of common programming errors

Have been stuck with this issue since the last 4 days and checked everywhere but I cannot find a solution.

In Prestashop, I need to offer customers (for a b2b site) csv downloads for each of their order histories. This is what I have done:

1- Overridden OrderDetailController.php and written the following code under initContent():

if ( !array_key_exists('csv_download', $_GET) ) {
    parent::initContent();
} else if ( array_key_exists('csv_download', $_GET) ) {
    header('Content-type: text/csv');
    header('Content-Type: application/force-download; charset=UTF-8');
    header('Cache-Control: no-store, no-cache');
    header('Content-disposition: attachment; filename="'.'abc'.'_'.date('Y-m-d_His').'.csv"');
    $this->context->smarty->display(_PS_THEME_DIR_.'order-detail-csv.tpl');
}

The order-detail-csv.tpl is:

col1, col2, col3, col4
1,2,3,4
5,6,7,8

(I’ve have hardcoded values in the template for testing purposes)

The problem is, when the link is clicked to access this, the following is appended at the bottom of the CSV:

col1, col2, col3, col4
1,2,3,4
5,6,7,8



Information

    Notice: Undefined index: PS_CATALOG_MODE in D:\Program_Files\xampp\htdocs \prestashop\cache\smarty\compile\66\40\fc\6640fcf250c9a844925d45d85c39618c4233b46e.file.blockcms.tpl.phpon line 93

    Notice: Trying to get property of non-object in D:\Program_Files\xampp\htdocs\prestashop\cache\smarty\compile\66\40\fc\6640fcf250c9a844925d45d85c39618c4233b46e.file.blockcms.tpl.phpon line 93