public function testPopulateCustomerInfo() { $this->quoteMock->expects($this->once())->method('getCustomer')->willReturn($this->customerMock); $this->customerMock->expects($this->atLeastOnce())->method('getId')->willReturn(null); $this->customerMock->expects($this->atLeastOnce())->method('getDefaultBilling')->willReturn(100500); $this->quoteMock->expects($this->atLeastOnce())->method('getBillingAddress')->willReturn($this->quoteAddressMock); $this->quoteMock->expects($this->atLeastOnce())->method('getShippingAddress')->willReturn($this->quoteAddressMock); $this->quoteMock->expects($this->atLeastOnce())->method('setCustomer')->with($this->customerMock)->willReturnSelf(); $this->quoteMock->expects($this->once())->method('getPasswordHash')->willReturn('password hash'); $this->quoteAddressMock->expects($this->atLeastOnce())->method('getId')->willReturn(null); $this->customerAddressRepositoryMock->expects($this->atLeastOnce())->method('getById')->with(100500)->willReturn($this->customerAddressMock); $this->quoteAddressMock->expects($this->atLeastOnce())->method('importCustomerAddressData')->willReturnSelf(); $this->accountManagementMock->expects($this->once())->method('createAccountWithPasswordHash')->with($this->customerMock, 'password hash')->willReturn($this->customerMock); $this->customerManagement->populateCustomerInfo($this->quoteMock); }
/** * Submit quote * * @param Quote $quote * @param array $orderData * @return \Magento\Framework\Model\AbstractExtensibleModel|\Magento\Sales\Api\Data\OrderInterface|object * @throws \Exception * @throws \Magento\Framework\Exception\LocalizedException */ protected function submitQuote(QuoteEntity $quote, $orderData = []) { $order = $this->orderFactory->create(); $this->quoteValidator->validateBeforeSubmit($quote); if (!$quote->getCustomerIsGuest()) { if ($quote->getCustomerId()) { $this->_prepareCustomerQuote($quote); } $this->customerManagement->populateCustomerInfo($quote); } $addresses = []; $quote->reserveOrderId(); if ($quote->isVirtual()) { $this->dataObjectHelper->mergeDataObjects('\\Magento\\Sales\\Api\\Data\\OrderInterface', $order, $this->quoteAddressToOrder->convert($quote->getBillingAddress(), $orderData)); } else { $this->dataObjectHelper->mergeDataObjects('\\Magento\\Sales\\Api\\Data\\OrderInterface', $order, $this->quoteAddressToOrder->convert($quote->getShippingAddress(), $orderData)); $shippingAddress = $this->quoteAddressToOrderAddress->convert($quote->getShippingAddress(), ['address_type' => 'shipping', 'email' => $quote->getCustomerEmail()]); $addresses[] = $shippingAddress; $order->setShippingAddress($shippingAddress); $order->setShippingMethod($quote->getShippingAddress()->getShippingMethod()); } $billingAddress = $this->quoteAddressToOrderAddress->convert($quote->getBillingAddress(), ['address_type' => 'billing', 'email' => $quote->getCustomerEmail()]); $addresses[] = $billingAddress; $order->setBillingAddress($billingAddress); $order->setAddresses($addresses); $order->setPayment($this->quotePaymentToOrderPayment->convert($quote->getPayment())); $order->setItems($this->resolveItems($quote)); if ($quote->getCustomer()) { $order->setCustomerId($quote->getCustomer()->getId()); } $order->setQuoteId($quote->getId()); $order->setCustomerEmail($quote->getCustomerEmail()); $order->setCustomerFirstname($quote->getCustomerFirstname()); $order->setCustomerMiddlename($quote->getCustomerMiddlename()); $order->setCustomerLastname($quote->getCustomerLastname()); $this->eventManager->dispatch('sales_model_service_quote_submit_before', ['order' => $order, 'quote' => $quote]); try { $order = $this->orderManagement->place($order); $quote->setIsActive(false); $this->eventManager->dispatch('sales_model_service_quote_submit_success', ['order' => $order, 'quote' => $quote]); $this->quoteRepository->save($quote); } catch (\Exception $e) { $this->eventManager->dispatch('sales_model_service_quote_submit_failure', ['order' => $order, 'quote' => $quote, 'exception' => $e]); throw $e; } return $order; }