Beispiel #1
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;
 }
Beispiel #2
0
 public function testCreate()
 {
     $shippingAddress = $this->dummyData->getOrderAddress();
     $billingAddress = clone $shippingAddress;
     $user = $this->dummyData->getUser();
     $coupon = $this->dummyData->getCoupon();
     $shipment = $this->dummyData->getShipment();
     $cartTotal = $this->dummyData->getCartTotal();
     $payment = $this->dummyData->getCashPayment();
     $shipmentRate = $this->dummyData->getShipmentRate();
     $taxRate = $this->dummyData->getTaxRate();
     $order = new Order();
     $order->setExternalId('CO1102-0016');
     $order->setReferenceNumber('xxx-xxxxxxx-xxxxxxx');
     $order->setIp4('10.0.0.1');
     $order->setShippingAddress($shippingAddress);
     $order->setBillingAddress($billingAddress);
     $order->setUser($user);
     $order->addCoupon($coupon);
     $order->setTaxRate($taxRate);
     $order->setTotal($cartTotal);
     $order->addShipment($shipment);
     $order->setShipmentRate($shipmentRate);
     $order->addPayment($payment);
     $product = $this->dummyData->getProduct();
     $orderItem = $this->dummyData->getOrderItem($order, $product);
     $orderItem->setQuantity(2);
     $this->assertEntityValid($order);
     $this->assertSame('CO1102-0016', $order->getExternalId());
     $this->assertSame('xxx-xxxxxxx-xxxxxxx', $order->getReferenceNumber());
     $this->assertSame('10.0.0.1', $order->getIp4());
     $this->assertTrue($order->getStatus()->isShipped());
     $this->assertSame(1, $order->totalItems());
     $this->assertSame(2, $order->totalQuantity());
     $this->assertSame($cartTotal, $order->getTotal());
     $this->assertSame($shippingAddress, $order->getShippingAddress());
     $this->assertSame($billingAddress, $order->getBillingAddress());
     $this->assertSame($user, $order->getUser());
     $this->assertSame($coupon, $order->getCoupons()[0]);
     $this->assertSame($orderItem, $order->getOrderItem(0));
     $this->assertSame($orderItem, $order->getOrderItems()[0]);
     $this->assertSame($payment, $order->getPayments()[0]);
     $this->assertSame($shipmentRate, $order->getShipmentRate());
     $this->assertSame($taxRate, $order->getTaxRate());
     $this->assertSame($product, $order->getProducts()[0]);
     $this->assertSame($shipment, $order->getShipments()[0]);
 }
 /**
  * @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 #4
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;
 }