/**
  * Some special errors must be sent to users.
  * If not applicable, the default error will be sent.
  * 
  * @param array $errorList Error List
  * 
  * @return boolean
  */
 protected function _appendShippingErrors($errorList)
 {
     $output = false;
     $successCode = '0';
     $hasValidQuote = array_key_exists($successCode, $errorList);
     if (!$hasValidQuote) {
         $displayErrorList = explode(',', $this->getConfigData('hard_errors'));
         if ($this->getConfigFlag('show_soft_errors')) {
             $softErrorList = explode(',', $this->getConfigData('soft_errors'));
             $displayErrorList = array_merge($displayErrorList, $softErrorList);
         }
         foreach ($errorList as $errorCode => $errorMsg) {
             $isDisplayError = in_array($errorCode, $displayErrorList);
             if ($isDisplayError) {
                 $error = Mage::getModel('shipping/rate_result_error');
                 $error->setCarrier($this->_code);
                 $error->setErrorMessage($errorMsg);
                 $this->_result->append($error);
                 $output = true;
             }
         }
         if (!$output) {
             $logMsg = implode(',', $errorList);
             Mage::log("{$this->_code}: Warning! There is no valid quotes, and no one error was throwed: {$logMsg}");
         }
     }
     return $output;
 }
Example #2
0
 /**
  * Adds the error message in the result
  *
  * @param Mage_Shipping_Model_Rate_Result $result
  * @param string $message
  * @return Storm_Correios_Model_Carrier_Shipping
  */
 protected function _appendError(Mage_Shipping_Model_Rate_Result &$result, $message)
 {
     $this->_getHelper()->log($message);
     $error = Mage::getModel('shipping/rate_result_error');
     $error->setCarrier($this->_code)->setCarrierTitle($this->getConfigData('title'))->setErrorMessage($message);
     $result->append($error);
     return $this;
 }
 /**
  * Add a warning message at the top of the shipping method list.
  *
  * @param SimpleXMLElement $servico Post Method
  *
  * @return boolean
  */
 protected function _appendShippingWarning(SimpleXMLElement $servico)
 {
     $id = (string) $servico->Erro;
     $ids = explode(',', $this->getConfigData('soft_errors'));
     if (in_array($id, $ids)) {
         $error = Mage::getModel('shipping/rate_result_error');
         $error->setCarrier($this->_code);
         $error->setErrorMessage($servico->MsgErro);
         $this->_result->append($error);
         return true;
     }
     return false;
 }
 /**
  * Protected Get Tracking, opens the request to Correios
  *
  * @param string $code Code
  *
  * @return bool
  */
 protected function _getTracking($code)
 {
     $error = Mage::getModel('shipping/tracking_result_error');
     $error->setTracking($code);
     $error->setCarrier($this->_code);
     $error->setCarrierTitle($this->getConfigData('title'));
     $error->setErrorMessage($this->getConfigData('urlerror'));
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, "https://fastshipping.ciawn.com.br/v1/tracking/" . $code . "?token=" . $this->_token);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
     $response = curl_exec($curl);
     curl_close($curl);
     $response = json_decode($response)->result;
     $progress = array();
     foreach ($response as $key => $item) {
         $datetime = explode(' ', $item->data);
         $locale = new Zend_Locale('pt_BR');
         $date = '';
         $date = new Zend_Date($datetime[0], 'dd/MM/YYYY', $locale);
         $track = array('deliverydate' => $date->toString('YYYY-MM-dd'), 'deliverytime' => $datetime[1] . ':00', 'deliverylocation' => $item->local, 'status' => $item->acao, 'activity' => $item->detalhes);
         $progress[] = $track;
     }
     if (!empty($progress)) {
         $track = $progress[0];
         $track['progressdetail'] = $progress;
         $tracking = Mage::getModel('shipping/tracking_result_status');
         $tracking->setTracking($code);
         $tracking->setCarrier($this->_code);
         $tracking->setCarrierTitle($this->getConfigData('title'));
         $tracking->addData($track);
         $this->_result->append($tracking);
         return true;
     } else {
         $this->_result->append($error);
         return false;
     }
 }
Example #5
0
 /**
  * Parse xml tracking response
  *
  * @deprecated after 1.6.0.0 see _parseTrackingResponse()
  * @param array $trackingvalue
  * @param string $response
  * @return void
  */
 protected function _parseXmlTrackingResponse($trackingvalue, $response)
 {
     $resultArr = array();
     if (strlen(trim($response)) > 0) {
         if ($xml = $this->_parseXml($response)) {
             if (is_object($xml->Error) && is_object($xml->Error->Message)) {
                 $errorTitle = (string) $xml->Error->Message;
             } elseif (is_object($xml->SoftError) && is_object($xml->SoftError->Message)) {
                 $errorTitle = (string) $xml->SoftError->Message;
             }
             if (!isset($errorTitle)) {
                 $resultArr['status'] = (string) $xml->Package->StatusDescription;
                 $resultArr['service'] = (string) $xml->Package->Service;
                 $resultArr['deliverydate'] = (string) $xml->Package->DeliveredDate;
                 $resultArr['deliverytime'] = (string) $xml->Package->DeliveredTime;
                 $resultArr['deliverylocation'] = (string) $xml->TrackProfile->DeliveredLocationDescription;
                 $resultArr['signedby'] = (string) $xml->Package->SignedForBy;
                 $resultArr['shippeddate'] = (string) $xml->Package->ShipDate;
                 $weight = (string) $xml->Package->Weight;
                 $unit = (string) $xml->Package->WeightUnits;
                 $resultArr['weight'] = "{$weight} {$unit}";
                 $packageProgress = array();
                 if (isset($xml->Package->Event)) {
                     foreach ($xml->Package->Event as $event) {
                         $tempArr = array();
                         $tempArr['activity'] = (string) $event->Description;
                         $tempArr['deliverydate'] = (string) $event->Date;
                         //YYYY-MM-DD
                         $tempArr['deliverytime'] = (string) $event->Time;
                         //HH:MM:ss
                         $addArr = array();
                         if (isset($event->Address->City)) {
                             $addArr[] = (string) $event->Address->City;
                         }
                         if (isset($event->Address->StateProvinceCode)) {
                             $addArr[] = (string) $event->Address->StateProvinceCode;
                         }
                         if (isset($event->Address->CountryCode)) {
                             $addArr[] = (string) $event->Address->CountryCode;
                         }
                         if ($addArr) {
                             $tempArr['deliverylocation'] = implode(', ', $addArr);
                         }
                         $packageProgress[] = $tempArr;
                     }
                 }
                 $resultArr['progressdetail'] = $packageProgress;
             }
         } else {
             $errorTitle = 'Response is in the wrong format';
         }
     } else {
         $errorTitle = false;
     }
     if (!$this->_result) {
         $this->_result = Mage::getModel('shipping/tracking_result');
     }
     if ($resultArr) {
         $tracking = Mage::getModel('shipping/tracking_result_status');
         $tracking->setCarrier('fedex');
         $tracking->setCarrierTitle($this->getConfigData('title'));
         $tracking->setTracking($trackingvalue);
         $tracking->addData($resultArr);
         $this->_result->append($tracking);
     } else {
         $error = Mage::getModel('shipping/tracking_result_error');
         $error->setCarrier('fedex');
         $error->setCarrierTitle($this->getConfigData('title'));
         $error->setTracking($trackingvalue);
         $error->setErrorMessage($errorTitle ? $errorTitle : Mage::helper('usa')->__('Unable to retrieve tracking'));
         $this->_result->append($error);
     }
 }
Example #6
0
 /**
  * Parse xml tracking response
  *
  * @param array $trackingValue
  * @param string $response
  * @return null
  */
 protected function _parseXmlTrackingResponse($trackingValue, $response)
 {
     $errorTitle = Mage::helper('usa')->__('Unable to retrieve tracking');
     $resultArr = array();
     if (strlen(trim($response)) > 0) {
         if (strpos(trim($response), '<?xml') === 0) {
             $xml = simplexml_load_string($response);
             if (is_object($xml)) {
                 if (isset($xml->Number) && isset($xml->Description) && (string) $xml->Description != '') {
                     $errorTitle = (string) $xml->Description;
                 } elseif (isset($xml->TrackInfo) && isset($xml->TrackInfo->Error) && isset($xml->TrackInfo->Error->Description) && (string) $xml->TrackInfo->Error->Description != '') {
                     $errorTitle = (string) $xml->TrackInfo->Error->Description;
                 } else {
                     $errorTitle = Mage::helper('usa')->__('Unknown error');
                 }
                 if (isset($xml->TrackInfo) && isset($xml->TrackInfo->TrackSummary)) {
                     $resultArr['tracksummary'] = (string) $xml->TrackInfo->TrackSummary;
                 }
             }
         }
     }
     if (!$this->_result) {
         $this->_result = Mage::getModel('shipping/tracking_result');
     }
     if ($resultArr) {
         $tracking = Mage::getModel('shipping/tracking_result_status');
         $tracking->setCarrier('usps');
         $tracking->setCarrierTitle($this->getConfigData('title'));
         $tracking->setTracking($trackingValue);
         $tracking->setTrackSummary($resultArr['tracksummary']);
         $this->_result->append($tracking);
     } else {
         $error = Mage::getModel('shipping/tracking_result_error');
         $error->setCarrier('usps');
         $error->setCarrierTitle($this->getConfigData('title'));
         $error->setTracking($trackingValue);
         $error->setErrorMessage($errorTitle);
         $this->_result->append($error);
     }
 }
Example #7
0
 /**
  * Parse xml tracking response
  *
  * @param string $trackingvalue
  * @param string $response
  * @return null
  */
 protected function _parseXmlTrackingResponse($trackingvalue, $xmlResponse)
 {
     $errorTitle = 'Unable to retrieve tracking';
     $resultArr = array();
     $packageProgress = array();
     if ($xmlResponse) {
         $xml = new Varien_Simplexml_Config();
         $xml->loadString($xmlResponse);
         $arr = $xml->getXpath("//TrackResponse/Response/ResponseStatusCode/text()");
         $success = (int) $arr[0][0];
         if ($success === 1) {
             $arr = $xml->getXpath("//TrackResponse/Shipment/Service/Description/text()");
             $resultArr['service'] = (string) $arr[0];
             $arr = $xml->getXpath("//TrackResponse/Shipment/PickupDate/text()");
             $resultArr['shippeddate'] = (string) $arr[0];
             $arr = $xml->getXpath("//TrackResponse/Shipment/Package/PackageWeight/Weight/text()");
             $weight = (string) $arr[0];
             $arr = $xml->getXpath("//TrackResponse/Shipment/Package/PackageWeight/UnitOfMeasurement/Code/text()");
             $unit = (string) $arr[0];
             $resultArr['weight'] = "{$weight} {$unit}";
             $activityTags = $xml->getXpath("//TrackResponse/Shipment/Package/Activity");
             if ($activityTags) {
                 $i = 1;
                 foreach ($activityTags as $activityTag) {
                     $addArr = array();
                     if (isset($activityTag->ActivityLocation->Address->City)) {
                         $addArr[] = (string) $activityTag->ActivityLocation->Address->City;
                     }
                     if (isset($activityTag->ActivityLocation->Address->StateProvinceCode)) {
                         $addArr[] = (string) $activityTag->ActivityLocation->Address->StateProvinceCode;
                     }
                     if (isset($activityTag->ActivityLocation->Address->CountryCode)) {
                         $addArr[] = (string) $activityTag->ActivityLocation->Address->CountryCode;
                     }
                     $dateArr = array();
                     $date = (string) $activityTag->Date;
                     //YYYYMMDD
                     $dateArr[] = substr($date, 0, 4);
                     $dateArr[] = substr($date, 4, 2);
                     $dateArr[] = substr($date, -2, 2);
                     $timeArr = array();
                     $time = (string) $activityTag->Time;
                     //HHMMSS
                     $timeArr[] = substr($time, 0, 2);
                     $timeArr[] = substr($time, 2, 2);
                     $timeArr[] = substr($time, -2, 2);
                     if ($i == 1) {
                         $resultArr['status'] = (string) $activityTag->Status->StatusType->Description;
                         $resultArr['deliverydate'] = implode('-', $dateArr);
                         //YYYY-MM-DD
                         $resultArr['deliverytime'] = implode(':', $timeArr);
                         //HH:MM:SS
                         $resultArr['deliverylocation'] = (string) $activityTag->ActivityLocation->Description;
                         $resultArr['signedby'] = (string) $activityTag->ActivityLocation->SignedForByName;
                         if ($addArr) {
                             $resultArr['deliveryto'] = implode(', ', $addArr);
                         }
                     } else {
                         $tempArr = array();
                         $tempArr['activity'] = (string) $activityTag->Status->StatusType->Description;
                         $tempArr['deliverydate'] = implode('-', $dateArr);
                         //YYYY-MM-DD
                         $tempArr['deliverytime'] = implode(':', $timeArr);
                         //HH:MM:SS
                         if ($addArr) {
                             $tempArr['deliverylocation'] = implode(', ', $addArr);
                         }
                         $packageProgress[] = $tempArr;
                     }
                     $i++;
                 }
                 $resultArr['progressdetail'] = $packageProgress;
             }
         } else {
             $arr = $xml->getXpath("//TrackResponse/Response/Error/ErrorDescription/text()");
             $errorTitle = (string) $arr[0][0];
         }
     }
     if (!$this->_result) {
         $this->_result = Mage::getModel('shipping/tracking_result');
     }
     $defaults = $this->getDefaults();
     if ($resultArr) {
         $tracking = Mage::getModel('shipping/tracking_result_status');
         $tracking->setCarrier('ups');
         $tracking->setCarrierTitle($this->getConfigData('title'));
         $tracking->setTracking($trackingvalue);
         $tracking->addData($resultArr);
         $this->_result->append($tracking);
     } else {
         $error = Mage::getModel('shipping/tracking_result_error');
         $error->setCarrier('ups');
         $error->setCarrierTitle($this->getConfigData('title'));
         $error->setTracking($trackingvalue);
         $error->setErrorMessage($errorTitle);
         $this->_result->append($error);
     }
     return $this->_result;
 }
 protected function _getQuotes($extraCover, $config)
 {
     $destCountry = $config['country_code'];
     try {
         if ($destCountry == Fontis_Australia_Helper_Data::AUSTRALIA_COUNTRY_CODE) {
             $services = $this->_client->listDomesticParcelServices($config);
         } else {
             $services = $this->_client->listInternationalParcelServices($config);
         }
     } catch (Exception $e) {
         Mage::logException($e);
         return;
     }
     // TODO: Clean up this logic
     $allowedMethods = $this->getAllowedMethods();
     $extraCoverParent = $this->getCode('extra_cover');
     foreach ($services['services']['service'] as $service) {
         $serviceCode = $service['code'];
         // e.g. AUS_PARCEL_REGULAR
         if (in_array($serviceCode, $allowedMethods)) {
             $serviceName = $service['name'];
             // e.g. Parcel Post
             $servicePrice = $service['price'];
             // Just add the shipping method if the call to Australia Post
             // returns no options for that method
             if (!isset($service['options']['option']) && $this->_isAvailableShippingMethod($serviceName, $destCountry)) {
                 $method = $this->createMethod($serviceCode, $serviceName, $servicePrice);
                 $this->_result->append($method);
                 // If a shipping method has a bunch of options, we will have to
                 // create a specific method for each of the variants
             } else {
                 $serviceOption = $service['options']['option'];
                 // Unlike domestic shipping methods where the "default"
                 // method is listed as simply another service option (this
                 // allows us to simply loop through each one), we have to
                 // extrapolate the default international shipping method
                 // from what we know about the service itself
                 if ($destCountry != Fontis_Australia_Helper_Data::AUSTRALIA_COUNTRY_CODE && $this->_isAvailableShippingMethod($serviceName, $destCountry)) {
                     $method = $this->createMethod($serviceCode, $serviceName, $servicePrice);
                     $this->_result->append($method);
                 }
                 // Checks to see if the API has returned either a single
                 // service option or an array of them. If it is a single
                 // option then turn it into an array.
                 if (isset($serviceOption['name'])) {
                     $serviceOption = array($serviceOption);
                 }
                 foreach ($serviceOption as $option) {
                     $serviceOptionName = $option['name'];
                     $serviceOptionCode = $option['code'];
                     $config = array_merge($config, array('service_code' => $serviceCode, 'option_code' => $serviceOptionCode, 'extra_cover' => $extraCover));
                     try {
                         if ($destCountry == Fontis_Australia_Helper_Data::AUSTRALIA_COUNTRY_CODE) {
                             $postage = $this->_client->calculateDomesticParcelPostage($config);
                         } else {
                             $postage = $this->_client->calculateInternationalParcelPostage($config);
                         }
                     } catch (Exception $e) {
                         continue;
                     }
                     $servicePrice = $postage['postage_result']['total_cost'];
                     /** @var Fontis_Australia_Helper_Clickandsend $clickandsendHelper */
                     $clickandsendHelper = Mage::helper('australia/clickandsend');
                     // Create a shipping method with only the top-level options
                     $_finalCode = $serviceCode . '_' . $serviceOptionCode;
                     $_finalName = $serviceName . ' (' . $serviceOptionName . ')';
                     if ($this->_isAvailableShippingMethod($_finalName, $destCountry) && !(in_array($serviceOptionCode, $clickandsendHelper->getDisallowedServiceOptions()) && in_array($serviceCode, $clickandsendHelper->getDisallowedServiceCodes()) && $clickandsendHelper->isClickAndSendEnabled() && $clickandsendHelper->isFilterShippingMethods())) {
                         $method = $this->createMethod($_finalCode, $_finalName, $servicePrice);
                         $this->_result->append($method);
                     }
                     // Add the extra cover options (these are suboptions of
                     // the top-level options)
                     if (array_key_exists($serviceOptionCode, $extraCoverParent) && !($clickandsendHelper->isClickAndSendEnabled() && $clickandsendHelper->isFilterShippingMethods())) {
                         try {
                             if ($destCountry == Fontis_Australia_Helper_Data::AUSTRALIA_COUNTRY_CODE) {
                                 $config = array_merge($config, array('suboption_code' => ServiceOption::AUS_SERVICE_OPTION_EXTRA_COVER));
                                 $postageWithExtraCover = $this->_client->calculateDomesticParcelPostage($config);
                             } else {
                                 $postageWithExtraCover = $this->_client->calculateInternationalParcelPostage($config);
                             }
                             unset($config['suboption_code']);
                         } catch (Exception $e) {
                             continue;
                         }
                         if ($serviceOptionName == 'Signature on Delivery') {
                             $serviceOptionName = $serviceOptionName . ' + Extra Cover';
                         } else {
                             $serviceOptionName = 'Extra Cover';
                         }
                         if ($serviceOptionCode == ServiceOption::AUS_SERVICE_OPTION_SIGNATURE_ON_DELIVERY) {
                             $serviceOptionCode = 'FULL_PACKAGE';
                         } else {
                             $serviceOptionCode = 'EXTRA_COVER';
                         }
                         $servicePrice = $postageWithExtraCover['postage_result']['total_cost'];
                         $_finalCode = $serviceCode . '_' . $serviceOptionCode;
                         $_finalName = $serviceName . ' (' . $serviceOptionName . ')';
                         if ($this->_isAvailableShippingMethod($_finalName, $destCountry)) {
                             $method = $this->createMethod($_finalCode, $_finalName, $servicePrice);
                             $this->_result->append($method);
                         }
                     }
                 }
             }
         }
     }
 }
Example #9
0
 /**
  * Parse tracking response
  *
  * @param array $trackingValue
  * @param stdClass $response
  */
 protected function _parseTrackingResponse($trackingValue, $response)
 {
     if (is_object($response)) {
         if ($response->HighestSeverity == 'FAILURE' || $response->HighestSeverity == 'ERROR') {
             $errorTitle = (string) $response->Notifications->Message;
         } elseif (isset($response->TrackDetails)) {
             $trackInfo = $response->TrackDetails;
             $resultArray['status'] = (string) $trackInfo->StatusDescription;
             $resultArray['service'] = (string) $trackInfo->ServiceInfo;
             $timestamp = isset($trackInfo->EstimatedDeliveryTimestamp) ? $trackInfo->EstimatedDeliveryTimestamp : $trackInfo->ActualDeliveryTimestamp;
             $timestamp = strtotime((string) $timestamp);
             if ($timestamp) {
                 $resultArray['deliverydate'] = date('Y-m-d', $timestamp);
                 $resultArray['deliverytime'] = date('H:i:s', $timestamp);
             }
             $deliveryLocation = isset($trackInfo->EstimatedDeliveryAddress) ? $trackInfo->EstimatedDeliveryAddress : $trackInfo->ActualDeliveryAddress;
             $deliveryLocationArray = array();
             if (isset($deliveryLocation->City)) {
                 $deliveryLocationArray[] = (string) $deliveryLocation->City;
             }
             if (isset($deliveryLocation->StateOrProvinceCode)) {
                 $deliveryLocationArray[] = (string) $deliveryLocation->StateOrProvinceCode;
             }
             if (isset($deliveryLocation->CountryCode)) {
                 $deliveryLocationArray[] = (string) $deliveryLocation->CountryCode;
             }
             if ($deliveryLocationArray) {
                 $resultArray['deliverylocation'] = implode(', ', $deliveryLocationArray);
             }
             $resultArray['signedby'] = (string) $trackInfo->DeliverySignatureName;
             $resultArray['shippeddate'] = date('Y-m-d', (int) $trackInfo->ShipTimestamp);
             if (isset($trackInfo->PackageWeight) && isset($trackInfo->Units)) {
                 $weight = (string) $trackInfo->PackageWeight;
                 $unit = (string) $trackInfo->Units;
                 $resultArray['weight'] = "{$weight} {$unit}";
             }
             $packageProgress = array();
             if (isset($trackInfo->Events)) {
                 $events = $trackInfo->Events;
                 if (isset($events->Address)) {
                     $events = array($events);
                 }
                 foreach ($events as $event) {
                     $tempArray = array();
                     $tempArray['activity'] = (string) $event->EventDescription;
                     $timestamp = strtotime((string) $event->Timestamp);
                     if ($timestamp) {
                         $tempArray['deliverydate'] = date('Y-m-d', $timestamp);
                         $tempArray['deliverytime'] = date('H:i:s', $timestamp);
                     }
                     if (isset($event->Address)) {
                         $addressArray = array();
                         $address = $event->Address;
                         if (isset($address->City)) {
                             $addressArray[] = (string) $address->City;
                         }
                         if (isset($address->StateOrProvinceCode)) {
                             $addressArray[] = (string) $address->StateOrProvinceCode;
                         }
                         if (isset($address->CountryCode)) {
                             $addressArray[] = (string) $address->CountryCode;
                         }
                         if ($addressArray) {
                             $tempArray['deliverylocation'] = implode(', ', $addressArray);
                         }
                     }
                     $packageProgress[] = $tempArray;
                 }
             }
             $resultArray['progressdetail'] = $packageProgress;
         }
     }
     if (!$this->_result) {
         $this->_result = Mage::getModel('Mage_Shipping_Model_Tracking_Result');
     }
     if (isset($resultArray)) {
         $tracking = Mage::getModel('Mage_Shipping_Model_Tracking_Result_Status');
         $tracking->setCarrier('fedex');
         $tracking->setCarrierTitle($this->getConfigData('title'));
         $tracking->setTracking($trackingValue);
         $tracking->addData($resultArray);
         $this->_result->append($tracking);
     } else {
         $error = Mage::getModel('Mage_Shipping_Model_Tracking_Result_Error');
         $error->setCarrier('fedex');
         $error->setCarrierTitle($this->getConfigData('title'));
         $error->setTracking($trackingValue);
         $error->setErrorMessage($errorTitle ? $errorTitle : Mage::helper('Mage_Usa_Helper_Data')->__('Unable to retrieve tracking'));
         $this->_result->append($error);
     }
 }
 /**
  * Protected Get Tracking, opens the request to Correios
  *
  * @param string $code
  *
  * @return bool
  */
 protected function _getTracking($code)
 {
     $error = Mage::getModel('shipping/tracking_result_error');
     $error->setTracking($code);
     $error->setCarrier($this->_code);
     $error->setCarrierTitle($this->getConfigData('title'));
     $error->setErrorMessage($this->getConfigData('urlerror'));
     $url = 'http://websro.correios.com.br/sro_bin/txect01$.QueryList';
     $url .= '?P_LINGUA=001&P_TIPO=001&P_COD_UNI=' . $code;
     try {
         $client = new Zend_Http_Client();
         $client->setUri($url);
         $content = $client->request();
         $body = $content->getBody();
     } catch (Exception $e) {
         $this->_result->append($error);
         return false;
     }
     if (!preg_match('#<table ([^>]+)>(.*?)</table>#is', $body, $matches)) {
         $this->_result->append($error);
         return false;
     }
     $table = $matches[2];
     if (!preg_match_all('/<tr>(.*)<\\/tr>/i', $table, $columns, PREG_SET_ORDER)) {
         $this->_result->append($error);
         return false;
     }
     $progress = array();
     for ($i = 0; $i < count($columns); $i++) {
         $column = $columns[$i][1];
         $description = '';
         $found = false;
         if (preg_match('/<td rowspan="?2"?/i', $column) && preg_match('/<td rowspan="?2"?>(.*)<\\/td><td>(.*)<\\/td><td><font color="[A-Z0-9]{6}">(.*)<\\/font><\\/td>/i', $column, $matches)) {
             if (preg_match('/<td colspan="?2"?>(.*)<\\/td>/i', $columns[$i + 1][1], $matchesDescription)) {
                 $description = str_replace('  ', '', $matchesDescription[1]);
             }
             $found = true;
         } elseif (preg_match('/<td rowspan="?1"?>(.*)<\\/td><td>(.*)<\\/td><td><font color="[A-Z0-9]{6}">(.*)<\\/font><\\/td>/i', $column, $matches)) {
             $found = true;
         }
         if ($found) {
             $datetime = explode(' ', $matches[1]);
             $locale = new Zend_Locale('pt_BR');
             $date = '';
             $date = new Zend_Date($datetime[0], 'dd/MM/YYYY', $locale);
             $track = array('deliverydate' => $date->toString('YYYY-MM-dd'), 'deliverytime' => $datetime[1] . ':00', 'deliverylocation' => htmlentities($matches[2]), 'status' => htmlentities($matches[3]), 'activity' => htmlentities($matches[3]));
             if ($description !== '') {
                 $track['activity'] = $matches[3] . ' - ' . htmlentities($description);
             }
             $progress[] = $track;
         }
     }
     if (!empty($progress)) {
         $track = $progress[0];
         $track['progressdetail'] = $progress;
         $tracking = Mage::getModel('shipping/tracking_result_status');
         $tracking->setTracking($code);
         $tracking->setCarrier('correios');
         $tracking->setCarrierTitle($this->getConfigData('title'));
         $tracking->addData($track);
         $this->_result->append($tracking);
         return true;
     } else {
         $this->_result->append($error);
         return false;
     }
 }