예제 #1
0
 /**
  * Download CSV report (SKU)
  *
  * @return     void
  */
 public function downloadSkuTask()
 {
     // Get filters
     $filters = array('sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'dDownloaded'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC'));
     $rowsRaw = CartDownload::getDownloadsSku('array', $filters);
     $rows = array();
     foreach ($rowsRaw as $row) {
         $rows[] = array($row['pName'], $row['sSku'], $row['downloaded']);
     }
     $date = date('d-m-Y');
     header("Content-Type: text/csv");
     header("Content-Disposition: attachment; filename=cart-downloads-sku-" . $date . ".csv");
     // Disable caching
     header("Cache-Control: no-cache, no-store, must-revalidate");
     // HTTP 1.1
     header("Pragma: no-cache");
     // HTTP 1.0
     header("Expires: 0");
     // Proxies
     $output = fopen("php://output", "w");
     $row = array('Product', 'SKU', 'Downloaded (times)');
     fputcsv($output, $row);
     foreach ($rows as $row) {
         // replace($row) empty vals with n/a
         foreach ($row as $k => $val) {
             if (empty($val)) {
                 $row[$k] = 'n/a';
             }
         }
         fputcsv($output, $row);
     }
     fclose($output);
     die;
 }