/** * Generate CSV * * @todo include stores */ public function csvAction() { $post = $this->getRequest()->getPost(); $file = ''; if ($post['countPost'] > 0) { //preparo l'elenco degli iscritti da salvare nel csv $mailupCustomerIds = Mage::getSingleton('core/session')->getMailupCustomerIds(); //require_once(dirname(__FILE__) . '/../Helper/Data.php'); $customersData = MailUp_MailUpSync_Helper_Data::getCustomersData(); //CSV Column names $file = '"Email","First Name","Last Name"'; if (Mage::getStoreConfig('mailup_newsletter/mailup/enable_mailup_synchro') == 1) { $file .= ',"Company","City","Province","Zip code","Region","Country code","Address","Fax","Phone","Customer id"'; $file .= ',"Last Order id","Last Order date","Last Order total","Last order product ids","Last order category ids"'; $file .= ',"Last sent order date","Last sent order id"'; $file .= ',"Last abandoned cart date","Last abandoned cart total","Last abandoned cart id"'; $file .= ',"Total orders amount","Last 12 months amount","Last 30 days amount","All products ids"'; } $file .= ';'; foreach ($mailupCustomerIds as $customerId) { foreach ($customersData as $subscriber) { if ($subscriber['email'] == $customerId['email']) { $file .= "\n"; $file .= '"' . $subscriber['email'] . '"'; $file .= ',"' . (!empty($subscriber['nome']) ? $subscriber['nome'] : '') . '"'; $file .= ',"' . (!empty($subscriber['cognome']) ? $subscriber['cognome'] : '') . '"'; $synchroConfig = Mage::getStoreConfig('mailup_newsletter/mailup/enable_mailup_synchro') == 1; $file .= ',"' . ($synchroConfig && !empty($subscriber['azienda']) ? $subscriber['azienda'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['città']) ? $subscriber['città'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['provincia']) ? $subscriber['provincia'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['cap']) ? $subscriber['cap'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['regione']) ? $subscriber['regione'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['paese']) ? $subscriber['paese'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['indirizzo']) ? $subscriber['indirizzo'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['fax']) ? $subscriber['fax'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['telefono']) ? $subscriber['telefono'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['IDCliente']) ? $subscriber['IDCliente'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['IDUltimoOrdine']) ? $subscriber['IDUltimoOrdine'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['DataUltimoOrdine']) ? $subscriber['DataUltimoOrdine'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['TotaleUltimoOrdine']) ? $subscriber['TotaleUltimoOrdine'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['IDProdottiUltimoOrdine']) ? $subscriber['IDProdottiUltimoOrdine'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['IDCategorieUltimoOrdine']) ? $subscriber['IDCategorieUltimoOrdine'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['DataUltimoOrdineSpedito']) ? $subscriber['DataUltimoOrdineSpedito'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['IDUltimoOrdineSpedito']) ? $subscriber['IDUltimoOrdineSpedito'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['DataCarrelloAbbandonato']) ? $subscriber['DataCarrelloAbbandonato'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['TotaleCarrelloAbbandonato']) ? $subscriber['TotaleCarrelloAbbandonato'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['IDCarrelloAbbandonato']) ? $subscriber['IDCarrelloAbbandonato'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['TotaleFatturato']) ? $subscriber['TotaleFatturato'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['TotaleFatturatoUltimi12Mesi']) ? $subscriber['TotaleFatturatoUltimi12Mesi'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['TotaleFatturatoUltimi30gg']) ? $subscriber['TotaleFatturatoUltimi30gg'] : '') . '"'; $file .= ',"' . ($synchroConfig && !empty($subscriber['IDTuttiProdottiAcquistati']) ? $subscriber['IDTuttiProdottiAcquistati'] : '') . '"'; $file .= ';'; continue 2; } } } } //lancio il download del file header("Content-type: application/csv"); header("Content-Disposition: attachment;Filename=filtered_customers.csv"); echo $file; }