Skip to content

Instantly share code, notes, and snippets.

@howardhenry
Last active February 14, 2016 14:03
Show Gist options
  • Save howardhenry/1a70b1a923d4467612d7 to your computer and use it in GitHub Desktop.
Save howardhenry/1a70b1a923d4467612d7 to your computer and use it in GitHub Desktop.
<?php
class masked_class_Model_Order_Export {
/**
* Generates an XML file from the order data and places it into
* the var/export directory
*
* @param Mage_Sales_Model_Order $order order object
*
* @return boolean
*/
public function exportOrder($order) {
// Get order Data
$order_id = $order->getData('increment_id');
$first_name = $order->getBillingAddress()->getData("firstname");
$last_name = $order->getBillingAddress()->getData("lastname");
$number = $order->getBillingAddress()->getData("telephone");
// Convert phone number to 18765551234 form
$formatted_telephone = preg_replace('~.*(\d{3})[^\d]*(\d{3})[^\d]*(\d{4}).*~', '$1$2$3', $number);
$digit_count = strlen($formatted_telephone);
if ($digit_count == 11) {
$telephone = $formatted_telephone;
}
elseif ($digit_count == 10) {
$telephone = "1" . $formatted_telephone;
}
elseif ($digit_count == 7) {
$telephone = "1876" . $formatted_telephone;
}
else {
// send phone number as is.
}
// Set current time
date_default_timezone_set('America/Jamaica');
$current_date = date('M d, Y - h:ia', time());
// Define SMS message
$sms_message = "Hello " . $first_name . " " . $last_name . ". Thank you for your order from DealBug. Order #" . $order_id . ", placed on " . $current_date;
/**
* Connect to DB server and send sms notifications
*/
// Establish db connection
$host = "masked_host";
$username = "masked_username";
$password = "masked_password";
$dbname = "masked_database";
$con = mysqli_connect($host,$username,$password,$dbname);
if (mysqli_connect_errno($con)) {// Check DB connection
$dumpFile = fopen('/@@@/failed.txt', 'w+');
fwrite($dumpFile, "Failed to connect to MySQL: " . mysqli_connect_error());
}
else { // Send notification data to DB
mysqli_query($con,"masked_db_query')");
}
mysqli_close($con);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment