Exemplo n.º 1
0
 /**
  * doActionTest
  *
  * @return void
  */
 protected function doActionTest()
 {
     $postedData = \XLite\Core\Request::getInstance()->getData();
     // Generate input data array for rates calculator
     $data = array();
     $errorFields = array();
     if (isset($postedData['weight']) && 0 < doubleval($postedData['weight'])) {
         $data['weight'] = doubleval($postedData['weight']);
     } else {
         $data['weight'] = 1;
     }
     if (isset($postedData['sourceZipcode']) && !empty($postedData['sourceZipcode'])) {
         $data['srcAddress']['zipcode'] = $postedData['sourceZipcode'];
     } else {
         $data['srcAddress']['zipcode'] = \XLite\Core\Config::getInstance()->Company->location_zipcode;
     }
     if (isset($postedData['destinationZipcode']) && !empty($postedData['destinationZipcode'])) {
         $data['dstAddress']['zipcode'] = $postedData['destinationZipcode'];
     } else {
         $errorFields[] = 'destinationZipcode';
     }
     if (isset($postedData['destinationCountry']) && !empty($postedData['destinationCountry'])) {
         $data['dstAddress']['country'] = $postedData['destinationCountry'];
     } else {
         $errorFields[] = 'destinationCountry';
     }
     echo '<h2>Input data</h2>';
     ob_start();
     print_r($data);
     $dataStr = '<pre>' . ob_get_contents() . '</pre>';
     ob_clean();
     echo $dataStr;
     if (empty($errorFields)) {
         // Get rates
         $aupost = new \XLite\Module\CDev\AustraliaPost\Model\Shipping\Processor\AustraliaPost();
         $startTime = microtime(true);
         $rates = $aupost->getRates($data, true);
         $proceedTime = microtime(true) - $startTime;
         $errorMsg = $aupost->getErrorMsg();
         if (!isset($errorMsg)) {
             if (!empty($rates)) {
                 // Rates have been successfully calculated, display them
                 echo '<h2>Rates:</h2>';
                 foreach ($rates as $rate) {
                     echo sprintf('%s (%0.2f)<br>', $rate->getMethodName(), $rate->getBaseRate());
                 }
                 echo sprintf('<br /><i>Time elapsed: %0.3f seconds</i>', $proceedTime);
             } else {
                 $errorMsg = static::t('There are no rates available for specified source/destination and/or package measurements/weight.');
             }
         }
     } else {
         $errorMsg = static::t('The following expected input data have wrong format or empty: ' . implode(', ', $errorFields));
     }
     if (!empty($errorMsg)) {
         echo '<h3>' . $errorMsg . '</h3>';
     }
     if (isset($aupost)) {
         $cmLog = $aupost->getApiCommunicationLog();
     }
     if (isset($cmLog)) {
         echo '<h2>Communication log</h2>';
         ob_start();
         echo 'API URL: ' . $aupost->getApiURL() . PHP_EOL . PHP_EOL;
         foreach ($cmLog as $log) {
             print_r($log);
             echo PHP_EOL . '<hr />' . PHP_EOL;
         }
         $msg = '<pre>' . ob_get_contents() . '</pre>';
         ob_clean();
         echo $msg;
     }
     die;
 }
Exemplo n.º 2
0
 /**
  * testGetApiUrl
  *
  * @return void
  * @access public
  * @see    ____func_see____
  * @since  1.0.0
  */
 public function testGetApiUrl()
 {
     $processor = new XLite\Module\CDev\AustraliaPost\Model\Shipping\Processor\AustraliaPost();
     $this->assertEquals('http://drc.edeliver.com.au/ratecalc.asp', $processor->getApiURL());
 }