/**
  * Given a cart line, creates a new order line
  *
  * @param OrderInterface    $order    Order
  * @param CartLineInterface $cartLine Cart Line
  *
  * @return OrderLineInterface OrderLine created
  */
 public function createOrderLineByCartLine(OrderInterface $order, CartLineInterface $cartLine)
 {
     $orderLine = $cartLine->getOrderLine() instanceof OrderLineInterface ? $cartLine->getOrderLine() : $this->orderLineFactory->create();
     $orderLine->setOrder($order)->setPurchasable($cartLine->getPurchasable())->setQuantity($cartLine->getQuantity())->setProductAmount($cartLine->getProductAmount())->setAmount($cartLine->getAmount());
     $this->orderLineEventDispatcher->dispatchOrderLineOnCreatedEvent($order, $cartLine, $orderLine);
     return $orderLine;
 }
示例#2
0
 /**
  * Test object creation
  *
  * @group order
  */
 public function testCreate()
 {
     $orderLineHistoryFactory = new OrderLineHistoryFactory();
     $orderLineHistoryFactory->setEntityNamespace('Elcodi\\Component\\Cart\\Entity\\OrderLineHistory');
     $orderLineFactory = new OrderLineFactory();
     $orderLineFactory->setOrderLineHistoryFactory($orderLineHistoryFactory)->setInitialOrderHistoryState('new')->setEntityNamespace('Elcodi\\Component\\Cart\\Entity\\OrderLine');
     $orderLine = $orderLineFactory->create();
     $orderHistoryFactory = new OrderHistoryFactory();
     $orderHistoryFactory->setEntityNamespace('Elcodi\\Component\\Cart\\Entity\\OrderHistory');
     $orderFactory = new OrderFactory();
     $orderFactory->setOrderHistoryFactory($orderHistoryFactory)->setInitialOrderHistoryState('new')->setEntityNamespace('Elcodi\\Component\\Cart\\Entity\\Order');
     $order = $orderFactory->create();
     $order->addOrderLine($orderLine);
     $this->assertCount(1, $order->getOrderHistories());
     $this->assertInstanceOf('Elcodi\\Component\\Cart\\Entity\\Interfaces\\OrderHistoryInterface', $order->getOrderHistories()->first());
     $this->assertEquals('new', $order->getOrderHistories()->first()->getState());
     $this->assertInstanceOf('Elcodi\\Component\\Cart\\Entity\\Interfaces\\OrderHistoryInterface', $order->getLastOrderHistory());
     $this->assertSame($order->getOrderHistories()->first(), $order->getLastOrderHistory());
     $this->assertCount(1, $order->getOrderLines());
     $orderLine = $order->getOrderLines()->first();
     $this->assertCount(1, $orderLine->getOrderLineHistories());
     $this->assertInstanceOf('Elcodi\\Component\\Cart\\Entity\\Interfaces\\OrderLineHistoryInterface', $orderLine->getOrderLineHistories()->first());
     $this->assertEquals($orderLine->getOrderLineHistories()->first()->getState(), 'new');
     $this->assertInstanceOf('Elcodi\\Component\\Cart\\Entity\\Interfaces\\OrderLineHistoryInterface', $orderLine->getLastOrderLineHistory());
     $this->assertSame($orderLine->getOrderLineHistories()->first(), $orderLine->getLastOrderLineHistory());
 }