Beispiel #1
0
 public function __construct(Order $order)
 {
     $this->setId();
     $this->setCreated();
     $this->catalogPromotions = new ArrayCollection();
     $this->productQuantityDiscounts = new ArrayCollection();
     $this->orderItemOptionProducts = new ArrayCollection();
     $this->orderItemOptionValues = new ArrayCollection();
     $this->orderItemTextOptionValues = new ArrayCollection();
     $this->attachments = new ArrayCollection();
     $this->order = $order;
     $order->addOrderItem($this);
 }
Beispiel #2
0
 /**
  * @param UuidInterface $orderId
  * @param User $user
  * @param Cart $cart
  * @param CartCalculatorInterface $cartCalculator
  * @param string $ip4
  * @return Order
  */
 public static function fromCart(UuidInterface $orderId, User $user, Cart $cart, CartCalculatorInterface $cartCalculator, $ip4)
 {
     $order = new Order($orderId);
     $order->setIp4($ip4);
     foreach ($cart->getCartItems() as $item) {
         $order->addOrderItem($item->getOrderItem($order, $cartCalculator->getPricing()));
     }
     foreach ($cart->getCoupons() as $coupon) {
         $order->addCoupon($coupon);
     }
     $order->setUser($user);
     $order->setTaxRate($cart->getTaxRate());
     $order->setShipmentRate($cart->getShipmentRate());
     $order->setTotal($cart->getTotal($cartCalculator));
     return $order;
 }
 /**
  * @return static
  */
 public function withCoupons()
 {
     foreach ($this->entity->getCoupons() as $coupon) {
         $this->entityDTO->coupons[] = $this->dtoBuilderFactory->getCouponDTOBuilder($coupon)->build();
     }
     return $this;
 }
 /**
  * @param Iterator $iterator
  * @return ImportResult
  */
 public function import(Iterator $iterator)
 {
     $importResult = new ImportResult();
     foreach ($iterator as $key => $row) {
         if ($key < 2 && $row[0] === 'order_ref') {
             continue;
         }
         $externalId = $row[0];
         $date = $row[1];
         $userExternalId = $row[2];
         $subtotal = $this->convertDollarToCents($row[3]);
         $tax = $this->convertDollarToCents($row[4]);
         $total = $this->convertDollarToCents($row[5]);
         $cartTotal = new CartTotal();
         $cartTotal->subtotal = $subtotal;
         $cartTotal->tax = $tax;
         $cartTotal->total = $total;
         $order = new Order();
         $order->setIp4(null);
         $order->setExternalId($externalId);
         $order->setTotal($cartTotal);
         $order->setCreated(new DateTime($date));
         if ($userExternalId !== null) {
             $user = $this->userRepository->findOneByExternalId($userExternalId);
             if ($user !== null) {
                 $order->setUser($user);
             }
         }
         try {
             $this->throwValidationErrors($order);
             $this->orderRepository->create($order);
             $importResult->incrementSuccess();
         } catch (KommerceException $e) {
             $importResult->addFailedRow($row);
             $importResult->addErrorMessage($e->getMessage());
         }
     }
     return $importResult;
 }
Beispiel #5
0
 /**
  * @param CartTotal $cartTotal
  * @return Order
  */
 public function getOrder(CartTotal $cartTotal = null)
 {
     if ($cartTotal === null) {
         $cartTotal = $this->getCartTotal();
     }
     $orderAddress = $this->getOrderAddress();
     $order = new Order();
     $order->setIp4('10.0.0.1');
     $order->setTotal($cartTotal);
     $order->setShippingAddress($orderAddress);
     $order->setBillingAddress($orderAddress);
     return $order;
 }
Beispiel #6
0
 public function testAddShipmentChangesOrderStatusToPartiallyShipped()
 {
     $orderItem = $this->dummyData->getOrderItem();
     $orderItem->setQuantity(2);
     $shipment = $this->dummyData->getShipment();
     $this->dummyData->getShipmentItem($shipment, $orderItem, 1);
     $order = new Order();
     $order->addOrderItem($orderItem);
     $this->assertFalse($order->getStatus()->isPartiallyShipped());
     $order->addShipment($shipment);
     $this->assertTrue($order->getStatus()->isPartiallyShipped());
 }
Beispiel #7
0
 private function reserveProductsFromInventory(Order $order)
 {
     foreach ($order->getOrderItems() as $orderItem) {
         $this->inventoryService->reserveProduct($orderItem->getProduct(), $orderItem->getQuantity());
         foreach ($orderItem->getOrderItemOptionProducts() as $orderItemOptionProduct) {
             $this->inventoryService->reserveProduct($orderItemOptionProduct->getOptionProduct()->getProduct(), $orderItem->getQuantity());
         }
     }
 }
Beispiel #8
0
 public function addOrder(Order $order)
 {
     $order->setUser($this);
     $this->orders[] = $order;
 }
 private function assertOrderShippedEventIsDispatched(Order $order, Shipment $shipment)
 {
     /** @var OrderShippedEvent $event */
     $event = $this->fakeEventDispatcher->getDispatchedEvents(OrderShippedEvent::class)[0];
     $this->assertTrue($event instanceof OrderShippedEvent);
     $this->assertEquals($order->getId(), $event->getOrderId());
     $this->assertSame($shipment->getId(), $event->getShipmentId());
 }