コード例 #1
0
ファイル: Aupost.php プロジェクト: kingsj/core
 /**
  * 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;
 }
コード例 #2
0
ファイル: post_rebuild.php プロジェクト: kirkbauer2/kirkxc
    $values = array();
    foreach ($fields as $fieldName) {
        $values[$fieldName] = isset($booleanFields[$fieldName]) ? 'Y' === $config->{$fieldName} || 1 === (int) $config->{$fieldName} : $config->{$fieldName};
    }
    $values['dimensions'] = serialize(array($config->length, $config->width, $config->height));
    $yamlFile = __DIR__ . LC_DS . 'post_rebuild.yaml';
    \XLite\Core\Database::getInstance()->loadFixturesFromYaml($yamlFile);
    /** @var \XLite\Model\Repo\Config $repo */
    $repo = \XLite\Core\Database::getRepo('XLite\\Model\\Config');
    $category = 'CDev\\AustraliaPost';
    foreach ($values as $name => $value) {
        $repo->createOption(array('category' => $category, 'name' => $name, 'value' => $value));
    }
    foreach (array('length', 'width', 'height') as $name) {
        $option = $repo->findOneBy(array('name' => $name, 'category' => $category));
        if ($option) {
            \XLite\Core\Database::getEM()->remove($option);
        }
    }
    \XLite\Core\Database::getEM()->flush();
    \XLite\Core\Config::updateInstance();
    /** @var \XLite\Model\Repo\Shipping\Method $repo */
    $repo = \XLite\Core\Database::getRepo('XLite\\Model\\Shipping\\Method');
    $carrier = $repo->findOnlineCarrier('aupost');
    $processor = new \XLite\Module\CDev\AustraliaPost\Model\Shipping\Processor\AustraliaPost();
    if ($processor->isConfigured()) {
        $carrier->setAdded(true);
        $carrier->setEnabled(true);
    }
    \XLite\Core\Database::getEM()->flush();
};
コード例 #3
0
ファイル: AustraliaPost.php プロジェクト: kingsj/core
 /**
  * testGetRates
  *
  * @return void
  * @access public
  * @see    ____func_see____
  * @since  1.0.0
  */
 public function testGetRates()
 {
     $processor = new XLite\Module\CDev\AustraliaPost\Model\Shipping\Processor\AustraliaPost();
     // Test on anonymous order
     $tmpConfig = \XLite\Base::getInstance()->config->Company;
     \XLite\Base::getInstance()->config->Company->location_country = 'AU';
     \XLite\Base::getInstance()->config->Company->location_zipcode = '3146';
     $m = $this->getTestOrder(false)->getModifier('shipping', 'SHIPPING')->getModifier();
     $rates = $processor->getRates($m);
     $ratesCached = $processor->getRates($m);
     \XLite\Base::getInstance()->config->Company = $tmpConfig;
     $this->assertTrue(is_array($rates), 'getRates() must return an array (#1)');
     $this->assertEquals(5, count($rates), 'Count of rates is not match with an expected value (#1)');
     $this->assertEquals($rates, $ratesCached, 'Cached rates does not match an original rates (#1)');
     foreach ($rates as $rate) {
         $this->assertTrue($rate instanceof \XLite\Model\Shipping\Rate, 'getRates() must return an array of \\XLite\\Model\\Shipping\\Rate instances (#1)');
         $this->assertTrue($rate->getMethod() instanceof \XLite\Model\Shipping\Method, 'Wrong method object returned (#1)');
         $this->assertEquals('aupost', $rate->getMethod()->getProcessor(), 'Wrong method returned (processor does not match) (#1)');
         $this->assertNotEquals(0, $rate->getBaseRate(), 'Base rate is zero (#1)');
         $this->assertEquals(0, $rate->getMarkupRate(), 'Markup rate is not zero (#1)');
     }
     // Test on an array with input data
     $data = array('weight' => 250, 'srcAddress' => array('zipcode' => 3146), 'dstAddress' => array('zipcode' => '2154', 'country' => 'AU'));
     $rates = $processor->getRates($data, true);
     $this->assertTrue(is_array($rates), 'getRates() must return an array (#2)');
     $this->assertEquals(2, count($rates), 'Count of rates is not match with an expected value (#2)');
     foreach ($rates as $rate) {
         $this->assertTrue($rate instanceof \XLite\Model\Shipping\Rate, 'getRates() must return an array of \\XLite\\Model\\Shipping\\Rate instances (#2)');
         $this->assertTrue($rate->getMethod() instanceof \XLite\Model\Shipping\Method, 'Wrong method object returned (#2)');
         $this->assertEquals('aupost', $rate->getMethod()->getProcessor(), 'Wrong method returned (processor does not match) (#2)');
         $this->assertNotEquals(0, $rate->getBaseRate(), 'Base rate is zero (#2)');
         $this->assertEquals(0, $rate->getMarkupRate(), 'Markup rate is not zero (#2)');
     }
     // Test on anonymous order if config.Company.location_country != 'AU'
     $tmpConfig = \XLite\Base::getInstance()->config->Company;
     \XLite\Base::getInstance()->config->Company->location_country = 'US';
     $m = $this->getTestOrder(false)->getModifier('shipping', 'SHIPPING')->getModifier();
     $rates = $processor->getRates($m);
     \XLite\Base::getInstance()->config->Company = $tmpConfig;
     $this->assertTrue(is_array($rates), 'getRates() must return an array (#3)');
     $this->assertEquals(0, count($rates), 'Count of rates is not match with an expected value (#3)');
 }