예제 #1
0
 /**
  * Get order
  *
  * @return \XLite\Model\Order
  */
 public function getOrder()
 {
     if (is_null($this->order)) {
         $this->order = false;
         if ($this->getParam(self::PARAM_ORDER) instanceof \XLite\Model\Order) {
             // order based
             $this->order = $this->getParam(self::PARAM_ORDER);
         } elseif (0 < $this->getRequestParamValue(self::PARAM_ORDER_ID)) {
             // order id based
             $order = new \XLite\Model\Order($this->getRequestParamValue(self::PARAM_ORDER_ID));
             if ($order->isPersistent()) {
                 $this->order = $order;
             }
         }
     }
     return $this->order;
 }
예제 #2
0
파일: Order.php 프로젝트: kingsj/core
 public function testAddItem()
 {
     $order = new \XLite\Model\Order();
     $profiles = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findAll();
     $profile = array_shift($profiles);
     unset($profiles);
     $order->map($this->testOrder);
     $order->setCurrency(\XLite\Core\Database::getRepo('XLite\\Model\\Currency')->find(840));
     $order->setDate(time());
     $item = new \XLite\Model\OrderItem();
     $item->setProduct($this->getProduct());
     $item->setAmount(1);
     $item->setPrice($this->getProduct()->getPrice());
     $this->assertTrue($order->addItem($item), 'check add item');
     $this->assertEquals(1, $order->getItems()->count(), 'check items length');
     $this->assertEquals(1, $order->getItems()->get(0)->getAmount(), 'check item amount');
     $item = new \XLite\Model\OrderItem();
     $item->setProduct($this->getProduct());
     $item->setAmount(1);
     $item->setPrice($this->getProduct()->getPrice());
     $this->assertTrue($order->addItem($item), 'check add item #2');
     $this->assertEquals(1, $order->getItems()->count(), 'check items length #2');
     $this->assertEquals(2, $order->getItems()->get(0)->getAmount(), 'check item amount #2');
     \XLite\Core\Database::getEM()->persist($order);
     \XLite\Core\Database::getEM()->flush();
     $item = new \XLite\Model\FakeOrderItem();
     $item->setProduct($this->getProduct());
     $item->setAmount(1);
     $item->setPrice($this->getProduct()->getPrice());
     $item->setInvalidFake();
     $this->assertFalse($order->addItem($item), 'check add item #3');
     $this->assertEquals($order::NOT_VALID_ERROR, $order->getAddItemError(), 'check error text');
     \XLite\Core\Database::getEM()->remove($order);
     \XLite\Core\Database::getEM()->flush();
 }