Heesang Posted November 15, 2017 Share Posted November 15, 2017 Hi, It's 1.6.1.15 I would like to receive my export CSV file delimited by comma "," instead of semicolon ";". Are there any way to by modify PHP code or DB entry? When I import, I can choose what delimiter to use, but there is no option when export. Thank you advance for any suggestion 1 Link to comment Share on other sites More sharing options...
bellini13 Posted November 15, 2017 Share Posted November 15, 2017 This appears to be hardcoded in a template file in 2 places (one for the header row, and then one for all other rows). You will see the semi-colon towards the end of each line. \admin\themes\default\template\layout-export.tpl {$export_precontent}{foreach from=$export_headers item=header}{$text_delimiter}{$header}{$text_delimiter};{/foreach} {foreach from=$line item=content}{$text_delimiter}{$content}{$text_delimiter};{/foreach} 1 Link to comment Share on other sites More sharing options...
Heesang Posted November 18, 2017 Author Share Posted November 18, 2017 Thanks bellini13! It wasn't working so I also changed classes/CSV.php public function __construct($collection, $filename, $delimiter = ';') However it still won't work. still delimited by ";" when file exported even I cleared the cache. Any idea? Link to comment Share on other sites More sharing options...
bellini13 Posted November 18, 2017 Share Posted November 18, 2017 the delimiter in the function parameter is not what you think it is. I have already provided you the solution to change the delimiter when exporting Link to comment Share on other sites More sharing options...
Heesang Posted November 18, 2017 Author Share Posted November 18, 2017 Hi bellini13 Yes, I have changed code on layout-export.tpl that ";" to "," however its still export ";" delimited to CSV {$export_precontent}{foreach from=$export_headers item=header}{$text_delimiter}{$header}{$text_delimiter},{/foreach} {foreach from=$export_content item=line} {foreach from=$line item=content}{$text_delimiter}{$content}{$text_delimiter},{/foreach} I have flushed cache but it still do same. My template compile option is set on Recompile templates if the files have been updated And the cache is set ON Do I have to do something else? Thanks in advance! Link to comment Share on other sites More sharing options...
bellini13 Posted November 18, 2017 Share Posted November 18, 2017 what are you trying to export? and from what page in the back office? Link to comment Share on other sites More sharing options...
Heesang Posted November 18, 2017 Author Share Posted November 18, 2017 Hi bellini13 It's on BO Stat -> Best-selling products Thank you for advance! Link to comment Share on other sites More sharing options...
bellini13 Posted November 19, 2017 Share Posted November 19, 2017 This is within the class ModuleGrid. Since we are talking about Stats pages which is produced by a module (statsbestproducts), then we need to start with "statsbestproducts.php" If we look inside statsbestproducts.php, we see a function named hookAdminStatsModules, with this code if (Tools::getValue('export')) $this->csvExport($engine_params); This module does not have csvExport, so we look at the parent class ModuleGrid and see the csvExport being used below protected function csvExport($datas) { $this->_sort = $datas['defaultSortColumn']; $this->setLang(Context::getContext()->language->id); $this->getData(); $layers = isset($datas['layers']) ? $datas['layers'] : 1; if (isset($datas['option'])) { $this->setOption($datas['option'], $layers); } if (count($datas['columns'])) { foreach ($datas['columns'] as $column) { $this->_csv .= $column['header'].';'; } $this->_csv = rtrim($this->_csv, ';')."\n"; foreach ($this->_values as $value) { foreach ($datas['columns'] as $column) { $this->_csv .= $value[$column['dataIndex']].';'; } $this->_csv = rtrim($this->_csv, ';')."\n"; } } $this->_displayCsv(); } And as you can see, semi-colon is once again hardcoded So you can be tactical about this and define csvExport function in statsbestproducts.php and change the delimeter Or you can change the Core ModuleGrid class directly (I wouldn't) Or you can override the ModuleGrid class and create your own csvExport function so it affects all stat pages Link to comment Share on other sites More sharing options...
Heesang Posted November 20, 2017 Author Share Posted November 20, 2017 Thank you bellini13! You are a life saver! Now I have made a override file under /override/classes/module ModuleGrid.php <?php abstract class ModuleGridCoreOverride extends Module { protected function csvExport($datas) { $this->_sort = $datas['defaultSortColumn']; $this->setLang(Context::getContext()->language->id); $this->getData(); $layers = isset($datas['layers']) ? $datas['layers'] : 1; if (isset($datas['option'])) { $this->setOption($datas['option'], $layers); } if (count($datas['columns'])) { foreach ($datas['columns'] as $column) { $this->_csv .= $column['header'].','; } $this->_csv = rtrim($this->_csv, ',')."\n"; foreach ($this->_values as $value) { foreach ($datas['columns'] as $column) { $this->_csv .= $value[$column['dataIndex']].','; } $this->_csv = rtrim($this->_csv, ',')."\n"; } } $this->_displayCsv(); } } I have set Disable all overrides to NO Clear the cache and removed cache/class_index.php However the result was the same that it is still delimited with ";" May I know what I did wrong? Thank you in advance! Link to comment Share on other sites More sharing options...
bellini13 Posted November 20, 2017 Share Posted November 20, 2017 This line does not look right abstract class ModuleGridCoreOverride extends Module I believe it should be this abstract class ModuleGrid extends ModuleGridCore You can also add a die statement in the first line of your function to confirm that you override is being executed protected function csvExport($datas) { die('my override file'); $this->_sort = $datas['defaultSortColumn']; $this->setLang(Context::getContext()->language->id); $this->getData(); ... Link to comment Share on other sites More sharing options...
Heesang Posted November 23, 2017 Author Share Posted November 23, 2017 Thank you bellini13! You are a life saver! Now it runs beautifully! Link to comment Share on other sites More sharing options...
pause4paws Posted January 4, 2018 Share Posted January 4, 2018 @Bellini13 I have a sort of similar problem. I have updated the code for the form.tpl file here: admin folder \themes\default\template\controllers\import\helpers\form\form.tpl to change the field separator and multiple value separator but they don’t change in the csv import section in the back office. The screenshot shows what I’m trying to do. Can you please tell me what other file must be edited? Thank you. Link to comment Share on other sites More sharing options...
bellini13 Posted January 4, 2018 Share Posted January 4, 2018 there is a good deal of discussion and code changes already documented above Link to comment Share on other sites More sharing options...
pause4paws Posted January 4, 2018 Share Posted January 4, 2018 (edited) I am trying to change the defaults for importing. Which files or code above should I use? My screenshot shows what I hope to do. I use transformer v3 for PS1.6. Thanks. Edited January 4, 2018 by pause4paws Wrong reference (see edit history) Link to comment Share on other sites More sharing options...
pause4paws Posted January 5, 2018 Share Posted January 5, 2018 (edited) I was shown how to update my default CSV separators in the back office by a thirty bees member. Edited this file: /controllers/admin/AdminImportController.php Line 568 Changed the comma to a caret (^) Line 570 Changed the semicolon to a comma as follows $this->separator = ($separator = Tools::substr(strval(trim(Tools::getValue('separator'))), 0, 1)) ? $separator : '^'; $this->convert = false; $this->multiple_value_separator = ($separator = Tools::substr(strval(trim(Tools::getValue('multiple_value_separator'))), 0, 1)) ? $separator : ','; } Edited January 5, 2018 by pause4paws to add how to fix my issue (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now