/** * @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; } $orderExternalId = $row[0]; $invoiceExternalId = $row[1]; $amount = $this->convertDollarToCents($row[2]); $checkNumber = $row[3]; $date = $row[4]; $order = $this->orderRepository->findOneByExternalId($orderExternalId); try { if (!empty($checkNumber)) { $payment = new CheckPayment($amount, $checkNumber, new DateTime($date)); } else { $payment = new CashPayment($amount); } $payment->setCreated(new DateTime($date)); $payment->setOrder($order); $this->throwValidationErrors($payment); $this->paymentRepository->persist($payment); $importResult->incrementSuccess(); } catch (KommerceException $e) { $importResult->addFailedRow($row); $importResult->addErrorMessage($e->getMessage()); } } $this->paymentRepository->flush(); return $importResult; }
/** * @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; }
/** * @param UuidInterface $orderId * @param User $user * @param Cart $cart * @param CartCalculatorInterface $cartCalculator * @param string $ip4 * @param OrderAddress $shippingAddress * @param OrderAddress $billingAddress * @param CreditCard $creditCard * @return Order */ public function createOrderFromCart(UuidInterface $orderId, User $user, Cart $cart, CartCalculatorInterface $cartCalculator, $ip4, OrderAddress $shippingAddress, OrderAddress $billingAddress, CreditCard $creditCard) { $this->throwValidationErrors($creditCard); $order = Order::fromCart($orderId, $user, $cart, $cartCalculator, $ip4); $order->setShippingAddress($shippingAddress); $order->setBillingAddress($billingAddress); $this->throwValidationErrors($order); $this->reserveProductsFromInventory($order); $this->addCreditCardPayment($order, $creditCard, $order->getTotal()->total); $this->orderRepository->create($order); $this->eventDispatcher->dispatchEvent(new OrderCreatedFromCartEvent($order->getId())); return $order; }
private function setupOrder($referenceNumber = null) { $uniqueId = crc32($referenceNumber); $product = $this->dummyData->getProduct(); $price = $this->dummyData->getPrice(); $user = $this->dummyData->getUser($uniqueId); $cartTotal = $this->dummyData->getCartTotal(); $taxRate = $this->dummyData->getTaxRate(); $order = $this->dummyData->getOrder($cartTotal); $order->setUser($user); $order->setReferenceNumber($referenceNumber); $order->setTaxRate($taxRate); $orderItem = $this->dummyData->getOrderItem($order, $product, $price); $shipment = $this->dummyData->getShipment(); $shipmentItem = $this->dummyData->getShipmentItem($shipment, $orderItem, 1); $order->addShipment($shipment); $this->entityManager->persist($product); $this->entityManager->persist($user); $this->entityManager->persist($taxRate); $this->orderRepository->create($order); $this->entityManager->flush(); return $order; }