Exemplo n.º 1
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());
 }
Exemplo n.º 2
0
 /**
  * This method creates a Order given a Cart.
  *
  * If cart has a order, this one is taken as order to be used, otherwise
  * new order will be created from the scratch
  *
  * This method dispatches these events
  *
  * ElcodiPurchaseEvents::ORDER_PRECREATED
  * ElcodiPurchaseEvents::ORDER_ONCREATED
  * ElcodiPurchaseEvents::ORDER_POSTCREATED
  *
  * @param CartInterface $cart Cart to create order from
  *
  * @return OrderInterface the created order
  */
 public function createOrderFromCart(CartInterface $cart)
 {
     $this->orderEventDispatcher->dispatchOrderPreCreatedEvent($cart);
     $order = $cart->getOrder() instanceof OrderInterface ? $cart->getOrder() : $this->orderFactory->create();
     $cart->setOrder($order);
     $orderLines = $this->cartLineOrderLineTransformer->createOrderLinesByCartLines($order, $cart->getCartLines());
     $order->setCustomer($cart->getCustomer())->setCart($cart)->setQuantity($cart->getQuantity())->setProductAmount($cart->getProductAmount())->setAmount($cart->getAmount())->setOrderLines($orderLines);
     $this->orderEventDispatcher->dispatchOrderOnCreatedEvent($cart, $order);
     return $order;
 }
 /**
  * Test dimensions transformation.
  *
  * @group Order
  */
 public function testCreateOrderFromCartDimensions()
 {
     /**
      * @var OrderInterface    $order
      * @var CurrencyInterface $currency
      */
     $order = $this->getMock('Elcodi\\Component\\Cart\\Entity\\Order', null);
     $currency = $this->getMock('Elcodi\\Component\\Currency\\Entity\\Currency', null);
     $currency->setIso('EUR');
     $this->orderFactory->expects($this->once())->method('create')->will($this->returnValue($order));
     $this->cartLineOrderLineTransformer->expects($this->any())->method('createOrderLinesByCartLines')->will($this->returnValue(new ArrayCollection()));
     $cart = $this->getMock('Elcodi\\Component\\Cart\\Entity\\Cart');
     $cart->expects($this->any())->method('getCartLines')->will($this->returnValue(new ArrayCollection()));
     $cart->expects($this->any())->method('getShippingAmount')->will($this->returnValue($this->getMock('Elcodi\\Component\\Currency\\Entity\\Interfaces\\MoneyInterface')));
     $cart->expects($this->any())->method('getCustomer')->will($this->returnValue(new Customer()));
     $cart->expects($this->any())->method('getPurchasableAmount')->will($this->returnValue(Money::create(10, $currency)));
     $cart->expects($this->any())->method('getCouponAmount')->will($this->returnValue(Money::create(0, $currency)));
     $cart->expects($this->any())->method('getAmount')->will($this->returnValue(Money::create(10, $currency)));
     $cart->expects($this->any())->method('getWeight')->will($this->returnValue(10));
     $cart->expects($this->any())->method('getHeight')->will($this->returnValue(11));
     $cart->expects($this->any())->method('getWidth')->will($this->returnValue(12));
     $cart->expects($this->any())->method('getDepth')->will($this->returnValue(13));
     $order = $this->cartOrderTransformer->createOrderFromCart($cart);
     $this->assertEquals(10, $order->getWeight());
     $this->assertEquals(11, $order->getHeight());
     $this->assertEquals(12, $order->getWidth());
     $this->assertEquals(13, $order->getDepth());
 }
Exemplo n.º 4
0
 /**
  * This method creates a Order given a Cart.
  *
  * If cart has a order, this one is taken as order to be used, otherwise
  * new order will be created from the scratch
  *
  * This method dispatches these events
  *
  * ElcodiPurchaseEvents::ORDER_PRECREATED
  * ElcodiPurchaseEvents::ORDER_ONCREATED
  * ElcodiPurchaseEvents::ORDER_POSTCREATED
  *
  * @param CartInterface $cart Cart to create order from
  *
  * @return OrderInterface the created order
  */
 public function createOrderFromCart(CartInterface $cart)
 {
     $this->orderEventDispatcher->dispatchOrderPreCreatedEvent($cart);
     $order = $cart->getOrder() instanceof OrderInterface ? $cart->getOrder() : $this->orderFactory->create();
     $cart->setOrder($order);
     $orderLines = $this->cartLineOrderLineTransformer->createOrderLinesByCartLines($order, $cart->getCartLines());
     /**
      * @var OrderInterface $order
      */
     $order->setCustomer($cart->getCustomer())->setCart($cart)->setQuantity($cart->getQuantity())->setProductAmount($cart->getProductAmount())->setShippingAmount($cart->getShippingAmount())->setAmount($cart->getAmount())->setHeight($cart->getHeight())->setWidth($cart->getWidth())->setDepth($cart->getDepth())->setWeight($cart->getWeight())->setBillingAddress($cart->getBillingAddress())->setDeliveryAddress($cart->getDeliveryAddress())->setOrderLines($orderLines);
     $couponAmount = $cart->getCouponAmount();
     if ($couponAmount instanceof MoneyInterface) {
         $order->setCouponAmount($couponAmount);
     }
     $this->orderEventDispatcher->dispatchOrderOnCreatedEvent($cart, $order);
     return $order;
 }
Exemplo n.º 5
0
 /**
  * test Create Order from Cart
  *
  * @group order
  */
 public function testCreateOrderFromCartNewOrderExistingOrder()
 {
     /**
      * @var OrderInterface    $order
      * @var CurrencyInterface $currency
      */
     $order = $this->getMock('Elcodi\\Component\\Cart\\Entity\\Order', null);
     $currency = $this->getMock('Elcodi\\Component\\Currency\\Entity\\Currency', null);
     $currency->setIso('EUR');
     $this->orderFactory->expects($this->never())->method('create')->will($this->returnValue($order));
     $this->cartLineOrderLineTransformer->expects($this->any())->method('createOrderLinesByCartLines')->will($this->returnValue(new ArrayCollection()));
     $customer = new Customer();
     $cart = new Cart();
     $cart->setCustomer($customer)->setQuantity(10)->setProductAmount(Money::create(20, $currency))->setOrder($order)->setAmount(Money::create(20, $currency))->setCartLines(new ArrayCollection());
     $this->cartOrderTransformer->createOrderFromCart($cart);
 }
Exemplo n.º 6
0
 /**
  * This method creates a Order given a Cart.
  *
  * If cart has a order, this one is taken as order to be used, otherwise
  * new order will be created from the scratch
  *
  * This method dispatches these events
  *
  * ElcodiPurchaseEvents::ORDER_PRECREATED
  * ElcodiPurchaseEvents::ORDER_ONCREATED
  * ElcodiPurchaseEvents::ORDER_POSTCREATED
  *
  * @param CartInterface $cart Cart to create order from
  *
  * @return OrderInterface the created order
  */
 public function createOrderFromCart(CartInterface $cart)
 {
     $this->orderEventDispatcher->dispatchOrderPreCreatedEvent($cart);
     $order = $cart->getOrder() instanceof OrderInterface ? $cart->getOrder() : $this->orderFactory->create();
     $cart->setOrder($order);
     $orderLines = $this->cartLineOrderLineTransformer->createOrderLinesByCartLines($order, $cart->getCartLines());
     /**
      * @var OrderInterface $order
      */
     $order->setCustomer($cart->getCustomer())->setCart($cart)->setQuantity($cart->getTotalItemNumber())->setPurchasableAmount($cart->getPurchasableAmount())->setShippingAmount($cart->getShippingAmount())->setAmount($cart->getAmount())->setHeight($cart->getHeight())->setWidth($cart->getWidth())->setDepth($cart->getDepth())->setWeight($cart->getWeight())->setBillingAddress($cart->getBillingAddress())->setDeliveryAddress($cart->getDeliveryAddress())->setOrderLines($orderLines);
     $couponAmount = $cart->getCouponAmount();
     if ($couponAmount instanceof MoneyInterface) {
         $order->setCouponAmount($couponAmount);
     }
     $this->orderEventDispatcher->dispatchOrderOnCreatedEvent($cart, $order);
     // Salvataggio per fare in modo che rimanga collegato orderLineId al cartLine
     foreach ($cart->getCartLines() as $cartLine) {
         $this->cartLineObjectManager->persist($cartLine);
     }
     $this->cartLineObjectManager->flush();
     return $order;
 }