/** * @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 Iterator $iterator * @return ImportResult */ public function import(Iterator $iterator) { $importResult = new ImportResult(); foreach ($iterator as $key => $row) { if ($key < 2 && $row[0] === 'id') { continue; } $externalId = $this->extractNull($row[0]); $name = $this->extractNull($row[1]); $address = $this->extractNull($row[2]); $zip5 = $this->extractNull($row[3]); $city = $this->extractNull($row[4]); $phone = $this->extractNull($row[5]); $fax = $this->extractNull($row[6]); $url = $this->extractNull($row[7]); $email = $this->extractNull($row[8]); $firstName = $this->parseFirstName($name); $lastName = $this->parseLastName($name); $user = new User(); $user->setExternalId($externalId); $user->setFirstName($firstName); $user->setLastName($lastName); if (!empty($email)) { $user->setEmail($email); } try { $this->throwValidationErrors($user); $this->userRepository->create($user); $importResult->incrementSuccess(); } catch (KommerceException $e) { $importResult->addFailedRow($row); $importResult->addErrorMessage($e->getMessage()); } } return $importResult; }