示例#1
0
文件: Rate.php 项目: kingsj/core
 /**
  * testCreate
  *
  * @return void
  * @access public
  * @see    ____func_see____
  * @since  1.0.0
  */
 public function testCreate()
 {
     // Prepare data for rate
     $method = $this->getMethodByName('Courier');
     $methodName = $method->getName();
     $markups = \XLite\Core\Database::getRepo('XLite\\Model\\Shipping\\Markup')->findAll();
     $this->assertTrue(0 < count($markups), 'markups list length checking');
     $markup = array_shift($markups);
     $markupId = $markup->getMarkupId();
     unset($markups);
     $extraData = new \XLite\Core\CommonCell();
     $extraData->testparam1 = 'test value 1';
     $extraData->testparam2 = 'test value 2';
     $newRate = new \XLite\Model\Shipping\Rate();
     $newRate->setMethod($method);
     $newRate->setBaseRate(100);
     $newRate->setMarkup($markup);
     $newRate->setMarkupRate(200);
     $newRate->setExtraData($extraData);
     // Check all parameters
     $this->assertEquals($markupId, $newRate->getMarkup()->getMarkupId(), 'Markup wrong');
     $this->assertEquals(100, $newRate->getBaseRate(), 'Base rate wrong');
     $this->assertEquals(200, $newRate->getMarkupRate(), 'Markup rate wrong');
     $this->assertEquals(300, $newRate->getTotalRate(), 'Total rate wrong');
     $this->assertEquals('test value 1', $newRate->getExtraData()->testparam1, 'Extra data #1 wrong');
     $this->assertEquals('test value 2', $newRate->getExtraData()->testparam2, 'Extra data #2 wrong');
     $this->assertEquals($methodName, $newRate->getMethodName(), 'getMethodName() returned wrong value');
 }
示例#2
0
 /**
  * Returns offline shipping rates
  *
  * @param \XLite\Logic\Order\Modifier\Shipping $modifier    Shipping order modifier
  * @param boolean                              $ignoreCache Flag: if true then do not get rates from cache (not used in offline processor) OPTIONAL
  *
  * @return array
  */
 public function getRates($modifier, $ignoreCache = false)
 {
     $rates = array();
     if ($modifier instanceof \XLite\Logic\Order\Modifier\Shipping) {
         // Find markups for all enabled offline shipping methods
         $markups = \XLite\Core\Database::getRepo('XLite\\Model\\Shipping\\Markup')->findMarkupsByProcessor($this->getProcessorId(), $modifier);
         if (!empty($markups)) {
             // Create shipping rates list
             foreach ($markups as $markup) {
                 $rate = new \XLite\Model\Shipping\Rate();
                 $rate->setMethod($markup->getShippingMethod());
                 $rate->setBaseRate(self::PROCESSOR_DEFAULT_BASE_RATE);
                 $rate->setMarkup($markup);
                 $rate->setMarkupRate($markup->getMarkupValue());
                 $rates[] = $rate;
             }
         }
     }
     // Return shipping rates list
     return $rates;
 }