public function postProcess() { /* PrestaShop demo mode */ if (_PS_MODE_DEMO_) { $this->errors[] = $this->trans('This functionality has been disabled.', array(), 'Admin.Notifications.Error'); return; } if (Tools::isSubmit('import')) { $this->importByGroups(); } elseif ($filename = Tools::getValue('csvfilename')) { $filename = urldecode($filename); $file = AdminImportController::getPath(basename($filename)); if (realpath(dirname($file)) != realpath(AdminImportController::getPath())) { exit; } if (!empty($filename)) { $b_name = basename($filename); if (Tools::getValue('delete') && file_exists($file)) { @unlink($file); } elseif (file_exists($file)) { $b_name = explode('.', $b_name); $b_name = strtolower($b_name[count($b_name) - 1]); $mime_types = array('csv' => 'text/csv'); if (isset($mime_types[$b_name])) { $mime_type = $mime_types[$b_name]; } else { $mime_type = 'application/octet-stream'; } if (ob_get_level() && ob_get_length() > 0) { ob_end_clean(); } header('Content-Transfer-Encoding: binary'); header('Content-Type: ' . $mime_type); header('Content-Length: ' . filesize($file)); header('Content-Disposition: attachment; filename="' . $filename . '"'); $fp = fopen($file, 'rb'); while (is_resource($fp) && !feof($fp)) { echo fgets($fp, 16384); } exit; } } } Db::getInstance()->enableCache(); return parent::postProcess(); }
public function postProcess() { /* PrestaShop demo mode */ if (_PS_MODE_DEMO_) { $this->errors[] = Tools::displayError('This functionality has been disabled.'); return; } if (Tools::isSubmit('import')) { // Check if the CSV file exist if (Tools::getValue('csv')) { // If i am a superadmin, i can truncate table if ((Shop::isFeatureActive() && $this->context->employee->isSuperAdmin() || !Shop::isFeatureActive()) && Tools::getValue('truncate')) { $this->truncateTables((int) Tools::getValue('entity')); } $import_type = false; switch ((int) Tools::getValue('entity')) { case $this->entities[$import_type = $this->l('Categories')]: $this->categoryImport(); $this->clearSmartyCache(); break; case $this->entities[$import_type = $this->l('Products')]: $this->productImport(); $this->clearSmartyCache(); break; case $this->entities[$import_type = $this->l('Customers')]: $this->customerImport(); break; case $this->entities[$import_type = $this->l('Addresses')]: $this->addressImport(); break; case $this->entities[$import_type = $this->l('Combinations')]: $this->attributeImport(); $this->clearSmartyCache(); break; case $this->entities[$import_type = $this->l('Manufacturers')]: $this->manufacturerImport(); $this->clearSmartyCache(); break; case $this->entities[$import_type = $this->l('Suppliers')]: $this->supplierImport(); $this->clearSmartyCache(); break; case $this->entities[$import_type = $this->l('Alias')]: $this->aliasImport(); break; } // @since 1.5.0 if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { switch ((int) Tools::getValue('entity')) { case $this->entities[$import_type = $this->l('Supply Orders')]: if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { $this->supplyOrdersImport(); } break; case $this->entities[$import_type = $this->l('Supply Order Details')]: if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { $this->supplyOrdersDetailsImport(); } break; } } if ($import_type !== false) { $log_message = sprintf($this->l('%s import', 'AdminTab', false, false), $import_type); if (Tools::getValue('truncate')) { $log_message .= ' ' . $this->l('with truncate', 'AdminTab', false, false); } PrestaShopLogger::addLog($log_message, 1, null, $import_type, null, true, (int) $this->context->employee->id); } } else { $this->errors[] = $this->l('You must upload a file in order to proceed to the next step'); } } elseif ($filename = Tools::getValue('csvfilename')) { $filename = urldecode($filename); $file = AdminImportController::getPath(basename($filename)); if (realpath(dirname($file)) != realpath(AdminImportController::getPath())) { exit; } if (!empty($filename)) { $b_name = basename($filename); if (Tools::getValue('delete') && file_exists($file)) { @unlink($file); } elseif (file_exists($file)) { $b_name = explode('.', $b_name); $b_name = strtolower($b_name[count($b_name) - 1]); $mime_types = array('csv' => 'text/csv'); if (isset($mime_types[$b_name])) { $mime_type = $mime_types[$b_name]; } else { $mime_type = 'application/octet-stream'; } if (ob_get_level() && ob_get_length() > 0) { ob_end_clean(); } header('Content-Transfer-Encoding: binary'); header('Content-Type: ' . $mime_type); header('Content-Length: ' . filesize($file)); header('Content-Disposition: attachment; filename="' . $filename . '"'); $fp = fopen($file, 'rb'); while (is_resource($fp) && !feof($fp)) { echo fgets($fp, 16384); } exit; } } } return parent::postProcess(); }