Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. ini_set('display_errors', 1);
  4. set_time_limit(0);
  5. ini_set('memory_limit','1024M');
  6. define("MAGE_ROOT", __DIR__);
  7. require_once __DIR__ . '/app/Mage.php';
  8. umask(0);
  9. Mage::app('default');
  10. Mage::setIsDeveloperMode(true);
  11. Varien_Profiler::enable();
  12.  
  13. $coreMySQLi = connectMySQLiDb(MAGE_ROOT . "/app/etc/local.xml");
  14. setMySQLiCharset($coreMySQLi, "utf8");
  15. setMySQLiCharset($coreMySQLi, "utf8mb4");
  16. $mageCoreHelper = Mage::helper('core');
  17. # var_dump(mysqli_get_charset($coreMySQLi));
  18.  
  19. $orders = Mage::getModel('sales/order')
  20. ->getCollection()
  21. ->addFieldToFilter('applied_rule_ids', array('eq' => array('[rule_id]')))
  22. ->addFieldToSelect('*');
  23. $ordersToExport = array();
  24. $itr = 0;
  25. foreach($orders as $order) {
  26. $ordersToExport[$itr]['Order Id'] = $order->getIncrementId();
  27. # $ordersToExport[$itr]['applied_rule_ids'] = $order->getAppliedRuleIds();
  28. $ordersToExport[$itr]['Customer First Name'] = $mageCoreHelper->__($order->getCustomerFirstname());
  29. $ordersToExport[$itr]['Customer Last Name'] = $mageCoreHelper->__($order->getCustomerLastname());
  30. $ordersToExport[$itr]['Customer Email'] = $order->getCustomerEmail();
  31. $ordersToExport[$itr]['Order Created On'] = $order->getCreatedAt();
  32. $itr++;
  33. }
  34.  
  35. header("Content-Type: application/csv; charset=utf-8");
  36. header('Content-Disposition: attachment; filename=IndependenceDayDiscountOrders.csv');
  37. $headers = array_keys($ordersToExport[0]);
  38. $fp = fopen("php://output", "w+");
  39. fputcsv($fp, $headers, ",");
  40. foreach($ordersToExport as $row) {
  41. fputcsv($fp, $row, ",");
  42. }
  43. fclose($fp);
  44.  
  45. function setMySQLiCharset($mysqliConnObj, $charSet) {
  46. mysqli_set_charset($mysqliConnObj, "{$charSet}");
  47. mysqli_query($mysqliConnObj, "SET character_set_results={$charSet}");
  48. mysqli_query($mysqliConnObj, "SET names={$charSet}");
  49. mysqli_query($mysqliConnObj, "SET NAMES {$charSet}");
  50. mysqli_query($mysqliConnObj, "SET character_set_client={$charSet}");
  51. mysqli_query($mysqliConnObj, "SET character_set_connection={$charSet}");
  52. mysqli_query($mysqliConnObj, "SET collation_connection={$charSet}_general_ci");
  53. mysqli_query($mysqliConnObj, "SET collation_connection={$charSet}_unicode_ci");
  54. return true;
  55. }
  56.  
  57. function connectMySQLiDb($configFilePath, $configParams = array()) {
  58. $xml = simplexml_load_file($configFilePath);
  59. $host = $xml->global->resources->default_setup->connection->host;
  60. $username = $xml->global->resources->default_setup->connection->username;
  61. $password = $xml->global->resources->default_setup->connection->password;
  62. $dbname = $xml->global->resources->default_setup->connection->dbname;
  63. $coreMySQLi = new mysqli($host, $username, $password, $dbname);
  64. if(mysqli_connect_errno()) {
  65. printf("Connect failed: %sn", mysqli_connect_error());
  66. exit();
  67. }
  68. return $coreMySQLi;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement