private function process_usps_dom($record) { App::import("Vendor", "UspsApi", array("file" => "UspsApi.php")); $u = new UspsApi(false, $record['Warehouse']); //process_weight $weight = 0; foreach ($record['CanteenOrderItem'] as $item) { $weight += $item['weight']; } $record['CanteenShippingRecord']['weight'] = $record['UserAddress']['weight'] = $weight; $record['UserAddress']['weight_oz'] = floor($record['UserAddress']['weight'] * 16); $record['UserAddress']['shipping_method'] = $record['CanteenShippingRecord']['shipping_method'] = "First Class"; if ($record['UserAddress']['weight_oz'] >= 13) { $record['UserAddress']['shipping_method'] = $record['CanteenShippingRecord']['shipping_method'] = "Parcel Post"; } $res = $u->ship_delcon($record['UserAddress']); //parse xml response $xml = simplexml_load_string($res); if (isset($xml->DeliveryConfirmationNumber)) { //save the label image $this->process_usps_label($xml->DeliveryConfirmationLabel, $record['CanteenShippingRecord']['id']); $record['CanteenShippingRecord']['shipping_status'] = "processing"; $record['CanteenShippingRecord']['shipment_number'] = $xml->Postnet; $record['CanteenShippingRecord']['tracking_number'] = $xml->DeliveryConfirmationNumber; $record['CanteenShippingRecord']['carrier_name'] = "USPS"; $this->create(); $this->id = $record['CanteenShippingRecord']['id']; $this->save($record['CanteenShippingRecord']); $record = $this->read(); } else { // error occurred SysMsg::add(array("category" => "USPSError", "crontab" => 1, "from" => "CanteenShippingRecord", "title" => "USPS DOM Shipping Error: CanteenShippingRecordID: <a href='/canteen_shipping_records/edit/{$record['CanteenShippingRecord']['id']}' target='_blank'>" . $record['CanteenShippingRecord']['id'] . "</a>", "message" => serialize($xml->asXml()))); } return $record; }