/** * 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; }
/** * 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; } }
/** * 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; } }