Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. <?php
  2.  
  3. class masked_class_Model_Order_Export {
  4.  
  5. /**
  6. * Generates an XML file from the order data and places it into
  7. * the var/export directory
  8. *
  9. * @param Mage_Sales_Model_Order $order order object
  10. *
  11. * @return boolean
  12. */
  13.  
  14. public function exportOrder($order) {
  15.  
  16. // Get order Data
  17. $order_id = $order->getData('increment_id');
  18. $first_name = $order->getBillingAddress()->getData("firstname");
  19. $last_name = $order->getBillingAddress()->getData("lastname");
  20. $number = $order->getBillingAddress()->getData("telephone");
  21.  
  22. // Convert phone number to 18765551234 form
  23. $formatted_telephone = preg_replace('~.*(\d{3})[^\d]*(\d{3})[^\d]*(\d{4}).*~', '$1$2$3', $number);
  24. $digit_count = strlen($formatted_telephone);
  25.  
  26. if ($digit_count == 11) {
  27. $telephone = $formatted_telephone;
  28. }
  29. elseif ($digit_count == 10) {
  30. $telephone = "1" . $formatted_telephone;
  31. }
  32. elseif ($digit_count == 7) {
  33. $telephone = "1876" . $formatted_telephone;
  34. }
  35. else {
  36. // send phone number as is.
  37. }
  38.  
  39. // Set current time
  40. date_default_timezone_set('America/Jamaica');
  41. $current_date = date('M d, Y - h:ia', time());
  42.  
  43. // Define SMS message
  44. $sms_message = "Hello " . $first_name . " " . $last_name . ". Thank you for your order from DealBug. Order #" . $order_id . ", placed on " . $current_date;
  45.  
  46. /**
  47. * Connect to DB server and send sms notifications
  48. */
  49.  
  50. // Establish db connection
  51. $host = "masked_host";
  52. $username = "masked_username";
  53. $password = "masked_password";
  54. $dbname = "masked_database";
  55. $con = mysqli_connect($host,$username,$password,$dbname);
  56.  
  57. if (mysqli_connect_errno($con)) {// Check DB connection
  58. $dumpFile = fopen('/@@@/failed.txt', 'w+');
  59. fwrite($dumpFile, "Failed to connect to MySQL: " . mysqli_connect_error());
  60. }
  61. else { // Send notification data to DB
  62. mysqli_query($con,"masked_db_query')");
  63. }
  64.  
  65. mysqli_close($con);
  66. return true;
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement