/**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing orders:');
     foreach ($this->fixtures as $file) {
         $fileName = $this->fixtureHelper->getPath($file);
         $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
         $isFirst = true;
         foreach ($csvReader as $row) {
             if ($isFirst) {
                 $customer = $this->customerRepository->get($row['customer_email']);
                 if (!$customer->getId()) {
                     continue;
                 }
                 /** @var \Magento\Sales\Model\Resource\Collection $orderCollection */
                 $orderCollection = $this->orderCollectionFactory->create();
                 $orderCollection->addFilter('customer_id', $customer->getId());
                 if ($orderCollection->count() > 0) {
                     break;
                 }
             }
             $isFirst = false;
             $orderData = $this->converter->convertRow($row);
             $this->orderProcessor->createOrder($orderData);
             $this->logger->logInline('.');
         }
     }
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function install(array $fixtures)
 {
     foreach ($fixtures as $file) {
         $fileName = $this->fixtureManager->getFixture($file);
         if (!file_exists($fileName)) {
             continue;
         }
         $rows = $this->csvReader->getData($fileName);
         $header = array_shift($rows);
         $isFirst = true;
         foreach ($rows as $row) {
             $data = [];
             foreach ($row as $key => $value) {
                 $data[$header[$key]] = $value;
             }
             $row = $data;
             if ($isFirst) {
                 $customer = $this->customerRepository->get($row['customer_email']);
                 if (!$customer->getId()) {
                     continue;
                 }
                 /** @var \Magento\Sales\Model\ResourceModel\Collection $orderCollection */
                 $orderCollection = $this->orderCollectionFactory->create();
                 $orderCollection->addFilter('customer_id', $customer->getId());
                 if ($orderCollection->count() > 0) {
                     break;
                 }
             }
             $isFirst = false;
             $orderData = $this->converter->convertRow($row);
             $this->orderProcessor->createOrder($orderData);
         }
     }
 }
 /**
  * Customer locking implementation
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $username = $observer->getEvent()->getData('username');
     $customer = $this->customerRepository->get($username);
     if ($customer && $customer->getId()) {
         $this->accountManagementHelper->processCustomerLockoutData($customer->getId());
         $this->customerRepository->save($customer);
     }
     return $this;
 }
 /**
  * @param array $orderData
  * @return void
  */
 public function createOrder($orderData)
 {
     $this->setPhraseRenderer();
     if (!empty($orderData)) {
         $orderCreateModel = $this->processQuote($orderData);
         if (!empty($orderData['payment'])) {
             $orderCreateModel->setPaymentData($orderData['payment']);
             $orderCreateModel->getQuote()->getPayment()->addData($orderData['payment']);
         }
         $customer = $this->customerRepository->get($orderData['order']['account']['email'], $this->storeManager->getWebsite()->getId());
         $orderCreateModel->getQuote()->setCustomer($customer);
         $orderCreateModel->getSession()->setCustomerId($customer->getId());
         $order = $orderCreateModel->importPostData($orderData['order'])->createOrder();
         $orderItem = $this->getOrderItemForTransaction($order);
         $this->invoiceOrder($orderItem);
         $this->shipOrder($orderItem);
         if ($orderData['refund'] === "yes") {
             $this->refundOrder($orderItem);
         }
         $registryItems = ['rule_data', 'currently_saved_addresses', 'current_invoice', 'current_shipment'];
         $this->unsetRegistryData($registryItems);
         $this->currentSession->unsQuoteId();
         $this->currentSession->unsStoreId();
         $this->currentSession->unsCustomerId();
     }
 }
 /**
  * @param string $customerEmail
  * @return int|null
  */
 protected function getCustomerIdByEmail($customerEmail)
 {
     $customerData = $this->customerRepository->get($customerEmail);
     if ($customerData) {
         return $customerData->getId();
     }
     return null;
 }
 /**
  * Process login by customer attribute or email
  *
  * @param string $username Username
  * @return bool|\Magento\Customer\Api\Data\CustomerInterface
  */
 private function loginViaCustomerAttributeOrEmail($username)
 {
     $customer = $this->findCustomerByLoginAttribute($username);
     if (false === $customer) {
         $customer = $this->customerRepository->get($username);
     }
     return $customer;
 }
 /**
  * @magentoAppArea adminhtml
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoAppIsolation enabled
  */
 public function testDeleteById()
 {
     $fixtureCustomerEmail = '*****@*****.**';
     $fixtureCustomerId = 1;
     $this->customerRepository->deleteById($fixtureCustomerId);
     /** Ensure that customer was deleted */
     $this->setExpectedException('Magento\\Framework\\Exception\\NoSuchEntityException', 'No such entity with email = customer@example.com, websiteId = 1');
     $this->customerRepository->get($fixtureCustomerEmail);
 }
 /**
  * @param string $email
  * @return array
  */
 protected function getAccountInformation($email)
 {
     $customer = $this->customerRepository->get($email);
     $account = ['email' => $customer->getEmail(), 'group_id' => $customer->getGroupId()];
     foreach ($customer->getAddresses() as $customerAddress) {
         if ($customerAddress->isDefaultBilling()) {
             $account['billing_address'] = $this->getAddresses($customerAddress);
         }
         if ($customerAddress->isDefaultShipping()) {
             $account['shipping_address'] = $this->getAddresses($customerAddress);
         }
     }
     return $account;
 }
 /**
  * {@inheritdoc}
  */
 public function isEmailAvailable($customerEmail, $websiteId = null)
 {
     try {
         if ($websiteId === null) {
             $websiteId = $this->storeManager->getStore()->getWebsiteId();
         }
         $this->customerRepository->get($customerEmail, $websiteId);
         return false;
     } catch (NoSuchEntityException $e) {
         return true;
     }
 }
 /**
  * @Given I am logged in as :customerEmail
  */
 public function iAmLoggedInAs($customerEmail)
 {
     $this->customer = $this->customerRepository->get($customerEmail);
 }