
Originally Posted by
DrByte
Without looking in great detail, I suspect you will need to "global" the $shipping_weight variable in order to use it in your notifier class.
Also global the $insert_id if you want the number of the current order.
Thanks Dr. Byte!
'global'ling $insert_id worked. However, I still can't get the $shipping_weight to work, which I suspect that my observer is attached so well only to class order.php. Perhaps use a different notifier than NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL?
Below is the code:
Code:
<?php
class xml_generate extends base {
function xml_generate() {
global $zco_notifier;
$zco_notifier->attach($this, array('NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL'));
}
function xml_config_switch() {
if ( defined('GENERATE_XML') && (GENERATE_XML == 'false') ) {
return false;
}
return true;
}
function update(&$callingClass, $eventID) {
if (!$this->xml_config_switch()) return;
global $order, $shipping_weight, $insert_id;
//Begin USPS Domestic clause
if (strpos($order->info['shipping_module_code'], 'usps') !== FALSE) {
$xml_msg = "<DAZzle Layout='c:\endicia\dazzle7\Zebra Label.lyt' OutputFile='C:\endicia\dazzle7\xmlout\domestic" . strftime('%Y%b%d-%H%M%S') . ".xml' Start='PRINTING' Test='YES' Prompt='NO' AutoClose='NO'>" . "\r\n";
$xml_msg .= "<Package ID='1'>\r\n";
if (strpos($order->info['shipping_method'], 'Parcel') !== FALSE) {$xml_msg .= "<MailClass>PARCELPOST</MailClass>\r\n";}
if (strpos($order->info['shipping_method'], 'First') !== FALSE) {$xml_msg .= "<MailClass>FIRST</MailClass>\r\n";}
if (strpos($order->info['shipping_method'], 'Priority') !== FALSE) {$xml_msg .= "<MailClass>PRIORITY</MailClass>\r\n";}
if (strpos($order->info['shipping_method'], 'Express') !== FALSE) {$xml_msg .= "<MailClass>EXPRESS</MailClass>\r\n";}
$xml_msg .= "<DateAdvance>0</DateAdvance>\r\n";
$xml_msg .= "<PackageType>NONRECTPARCEL</PackageType>\r\n";
$xml_msg .= "<Oversize>FALSE</Oversize>\r\n";
$xml_msg .= "<WeightOz>" . ($order->total_weight * 16) . "</WeightOz>\r\n"; //works without handling charge
$xml_msg .= "<WeightOz>" . ($shipping->shipping_weight * 16) . "</WeightOz>\r\n"; //returns 0
$xml_msg .= "<WeightOz>" . ($shipping_weight * 16) . "</WeightOz>\r\n"; //returns 0
$xml_msg .= "<Services>CertifiedMail='OFF' DeliveryConfirmation='OFF' ></Services>\r\n";
$xml_msg .= "<Value>" . $order->info['total'] . "</Value>\r\n";
$xml_msg .= "<Description>" . $order->products_ordered . "</Description>\r\n";
$xml_msg .= "<ReferenceID>" . $insert_id . "</ReferenceID>\r\n";
$xml_msg .= "<ToName>" . $order->delivery['firstname'] . " " . $order->delivery['lastname'] . " - " . $order->delivery['company'] . "</ToName>\r\n";
$xml_msg .= "<ToAddress1>" . $order->delivery['street_address'] . "</ToAddress1>\r\n";
$xml_msg .= "<ToCity>" . $order->delivery['city'] . "</ToCity>\r\n";
$xml_msg .= "<ToState>" . $order->delivery['state'] . "</ToState>\r\n";
$xml_msg .= "<ToPostalCode>" . $order->delivery['postcode'] . "</ToPostalCode>\r\n";
$xml_msg .= "<ToEMail>" . $order->customer['email_address'] . "</ToEMail>\r\n";
$xml_msg .= "</Package>\r\n</DAZzle>\r\n";
$OutFile = "includes/xml/usps/domestic" . strftime('%Y%b%d-%H%M%S') . ".xml"; //Setting path n file name to USPS domestic
} //End if USPS Domestic clause
//Generate XML File
$fp = fopen($OutFile, 'a');
$fout = fwrite( $fp , $xml_msg );
fclose($fp);
}
}
?>
Notice I'm trying 3 possible weight (in oz)?
Bookmarks