cikcak Posted September 8, 2014 Share Posted September 8, 2014 (edited) Hello, I really need hel p, how to export products in CSV format with HTML tags? Its important to description. Long descriptions with <p> </p> <strong> </strong> and etc... Any ideas? Edited September 8, 2014 by cikcak (see edit history) Link to comment Share on other sites More sharing options...
irrelevant Posted September 9, 2014 Share Posted September 9, 2014 (edited) This is for 1.6.0.9 - Add a new file ./override/controllers/admin/AdminRequestSqlController.php <?php class AdminRequestSqlController extends AdminRequestSqlControllerCore { public function generateExport() { $id = Tools::getValue($this->identifier); if (!Validate::isFileName($id)) die(Tools::displayError()); if (Configuration::get('PS_CSV_SEPARATOR')) $csvsep = stripslashes(Configuration::get('PS_CSV_SEPARATOR')); else $csvsep = ';'; if (Configuration::get('PS_CSV_STRIPTAGS')) $csvstrip = Configuration::get('PS_CSV_STRIPTAGS'); else $csvstrip = true; $file = 'request_sql_'.$id.'.csv'; if ($csv = fopen(_PS_ADMIN_DIR_.'/export/'.$file, 'w')) { $sql = RequestSql::getRequestSqlById($id); if ($sql) { $results = Db::getInstance()->executeS($sql[0]['sql']); foreach (array_keys($results[0]) as $key) { $tab_key[] = $key; fputs($csv, $key.$csvsep); } foreach ($results as $result) { fputs($csv, "\n"); foreach ($tab_key as $name) fputs($csv, '"'.($csvstrip ? strip_tags($result[$name]) : $result[$name]).'"'.$csvsep); } if (file_exists(_PS_ADMIN_DIR_.'/export/'.$file)) { $filesize = filesize(_PS_ADMIN_DIR_.'/export/'.$file); $upload_max_filesize = Tools::convertBytes(ini_get('upload_max_filesize')); if ($filesize < $upload_max_filesize) { if (Configuration::get('PS_ENCODING_FILE_MANAGER_SQL')) $charset = Configuration::get('PS_ENCODING_FILE_MANAGER_SQL'); else $charset = self::$encoding_file[0]['name']; header('Content-Type: text/csv; charset='.$charset); header('Cache-Control: no-store, no-cache'); header('Content-Disposition: attachment; filename="'.$file.'"'); header('Content-Length: '.$filesize); readfile(_PS_ADMIN_DIR_.'/export/'.$file); die(); } else $this->errors[] = Tools::DisplayError('The file is too large and can not be downloaded. Please use the clause "LIMIT" in this query.'); } } } } } Now use phpmyadmin, mysqlcc or whatever to add a new record to ps_configuration, PS_CSV_STRIPTAGS value of "0" (i.e.: off!) (You could also add PS_CSV_SEPARATOR in case you need something other than ";" between fields!) PS: Being an override, this should for the most part survive prestashop updates... Edited September 9, 2014 by irrelevant (see edit history) Link to comment Share on other sites More sharing options...
cikcak Posted September 10, 2014 Author Share Posted September 10, 2014 This is for 1.6.0.9 - Add a new file ./override/controllers/admin/AdminRequestSqlController.php <?php class AdminRequestSqlController extends AdminRequestSqlControllerCore { public function generateExport() { $id = Tools::getValue($this->identifier); if (!Validate::isFileName($id)) die(Tools::displayError()); if (Configuration::get('PS_CSV_SEPARATOR')) $csvsep = stripslashes(Configuration::get('PS_CSV_SEPARATOR')); else $csvsep = ';'; if (Configuration::get('PS_CSV_STRIPTAGS')) $csvstrip = Configuration::get('PS_CSV_STRIPTAGS'); else $csvstrip = true; $file = 'request_sql_'.$id.'.csv'; if ($csv = fopen(_PS_ADMIN_DIR_.'/export/'.$file, 'w')) { $sql = RequestSql::getRequestSqlById($id); if ($sql) { $results = Db::getInstance()->executeS($sql[0]['sql']); foreach (array_keys($results[0]) as $key) { $tab_key[] = $key; fputs($csv, $key.$csvsep); } foreach ($results as $result) { fputs($csv, "\n"); foreach ($tab_key as $name) fputs($csv, '"'.($csvstrip ? strip_tags($result[$name]) : $result[$name]).'"'.$csvsep); } if (file_exists(_PS_ADMIN_DIR_.'/export/'.$file)) { $filesize = filesize(_PS_ADMIN_DIR_.'/export/'.$file); $upload_max_filesize = Tools::convertBytes(ini_get('upload_max_filesize')); if ($filesize < $upload_max_filesize) { if (Configuration::get('PS_ENCODING_FILE_MANAGER_SQL')) $charset = Configuration::get('PS_ENCODING_FILE_MANAGER_SQL'); else $charset = self::$encoding_file[0]['name']; header('Content-Type: text/csv; charset='.$charset); header('Cache-Control: no-store, no-cache'); header('Content-Disposition: attachment; filename="'.$file.'"'); header('Content-Length: '.$filesize); readfile(_PS_ADMIN_DIR_.'/export/'.$file); die(); } else $this->errors[] = Tools::DisplayError('The file is too large and can not be downloaded. Please use the clause "LIMIT" in this query.'); } } } } } Now use phpmyadmin, mysqlcc or whatever to add a new record to ps_configuration, PS_CSV_STRIPTAGS value of "0" (i.e.: off!) (You could also add PS_CSV_SEPARATOR in case you need something other than ";" between fields!) PS: Being an override, this should for the most part survive prestashop updates... I tryed for 1.5 PS version, doesnt work.. But thank you for help, maybe it will be usefull for somebody. Any ideas for 1.5 PS? Link to comment Share on other sites More sharing options...
musicmaster Posted September 10, 2014 Share Posted September 10, 2014 You can do that with this script: http://www.prestashop.com/forums/topic/185401-free-script-product-mass-edit-category-multi-edit-order-edit/ @irrelevant: if you write your own code I would suggest using the fputcsv() function. It is part of PHP. Link to comment Share on other sites More sharing options...
irrelevant Posted September 11, 2014 Share Posted September 11, 2014 I tryed for 1.5 PS version, doesnt work.. But thank you for help, maybe it will be usefull for somebody. Any ideas for 1.5 PS? Just remove the word "strip_tags" from AdminRequestSqlController.php .... @musicmaster .. not my code, that's prestashop core code with a few tweaks.. Yep, I'd probably look at fputcsv if I was writing from scratch. 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