diff --git a/classes/CSV.php b/classes/CSV.php index bb75087eb..a1f785087 100644 --- a/classes/CSV.php +++ b/classes/CSV.php @@ -31,6 +31,9 @@ */ class CSVCore { + const QLO_EXPORT_FIELDS_ALL = 0; + const QLO_EXPORT_FIELDS_SELECTED = 1; + public $filename; public $collection; public $delimiter; diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php index 9166f1750..55e37d4c4 100644 --- a/classes/controller/AdminController.php +++ b/classes/controller/AdminController.php @@ -1216,6 +1216,20 @@ class AdminControllerCore extends Controller return; } + if ((int)Configuration::get('PS_EXPORT_FIELDS_TYPE') === CSV::QLO_EXPORT_FIELDS_SELECTED) { + $list_visibility = json_decode($this->context->cookie->{'list_visibility_'.$this->context->controller->controller_name}); + foreach ($this->fields_list as $key => $field) { + if (!isset($field['optional']) || !$field['optional']) { + continue; + } + $is_selected = (!is_array($list_visibility) && isset($field['visible_default']) && $field['visible_default']) + || ($list_visibility && in_array($key, $list_visibility)); + if (!$is_selected) { + unset($this->fields_list[$key]); + } + } + } + header('Content-type: text/csv'); header('Content-Type: application/force-download; charset=UTF-8'); header('Cache-Control: no-store, no-cache'); diff --git a/controllers/admin/AdminPreferencesController.php b/controllers/admin/AdminPreferencesController.php index a97ec7b54..3b6e866e9 100644 --- a/controllers/admin/AdminPreferencesController.php +++ b/controllers/admin/AdminPreferencesController.php @@ -195,6 +195,19 @@ class AdminPreferencesControllerCore extends AdminController 'class' => 'fixed-width-xl', 'desc' => sprintf($this->l('If set to 0, the maximum limit will be %d characters.'), Configuration::PS_SHORT_DESC_LIMIT) ), + 'PS_EXPORT_FIELDS_TYPE' => array( + 'title' => $this->l('CSV export fields'), + 'desc' => $this->l('Choose whether list CSV exports include all fields, or only the fields currently checked in the "Available Fields" selector of the list being exported.'), + 'validation' => 'isInt', + 'cast' => 'intval', + 'type' => 'select', + 'list' => array( + array('id' => CSV::QLO_EXPORT_FIELDS_ALL, 'name' => $this->l('All Fields')), + array('id' => CSV::QLO_EXPORT_FIELDS_SELECTED, 'name' => $this->l('Selected Fields')), + ), + 'identifier' => 'id', + 'defaultValue' => CSV::QLO_EXPORT_FIELDS_ALL, + ), // 'PS_DISPLAY_SUPPLIERS' => array( // 'title' => $this->l('Display suppliers and manufacturers'), // 'desc' => $this->l('Enable suppliers and manufacturers pages on your front office even when their respective modules are disabled.'),