Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customer related values are NULL for guests converted to customers after checkout. #19166 #19191

Merged
merged 8 commits into from
Feb 18, 2019
21 changes: 15 additions & 6 deletions app/code/Magento/Quote/Model/QuoteManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class QuoteManagement implements \Magento\Quote\Api\CartManagementInterface
* @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
* @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
* @param \Magento\Customer\Model\CustomerFactory $customerModelFactory
* @param \Magento\Quote\Model\Quote\AddressFactory $quoteAddressFactory,
* @param \Magento\Quote\Model\Quote\AddressFactory $quoteAddressFactory
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
* @param StoreManagerInterface $storeManager
* @param \Magento\Checkout\Model\Session $checkoutSession
Expand Down Expand Up @@ -221,7 +221,7 @@ public function __construct(
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function createEmptyCart()
{
Expand All @@ -241,7 +241,7 @@ public function createEmptyCart()
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function createEmptyCartForCustomer($customerId)
{
Expand All @@ -257,7 +257,7 @@ public function createEmptyCartForCustomer($customerId)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function assignCustomer($cartId, $customerId, $storeId)
{
Expand Down Expand Up @@ -332,7 +332,7 @@ protected function createCustomerCart($customerId, $storeId)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function placeOrder($cartId, PaymentInterface $paymentMethod = null)
{
Expand All @@ -354,6 +354,13 @@ public function placeOrder($cartId, PaymentInterface $paymentMethod = null)
if ($quote->getCheckoutMethod() === self::METHOD_GUEST) {
$quote->setCustomerId(null);
$quote->setCustomerEmail($quote->getBillingAddress()->getEmail());
if ($quote->getCustomerFirstname() === null && $quote->getCustomerLastname() === null) {
$quote->setCustomerFirstname($quote->getBillingAddress()->getFirstname());
$quote->setCustomerLastname($quote->getBillingAddress()->getLastname());
if ($quote->getBillingAddress()->getMiddlename() === null) {
$quote->setCustomerMiddlename($quote->getBillingAddress()->getMiddlename());
}
}
$quote->setCustomerIsGuest(true);
$quote->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID);
}
Expand All @@ -379,7 +386,7 @@ public function placeOrder($cartId, PaymentInterface $paymentMethod = null)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getCartForCustomer($customerId)
{
Expand All @@ -406,6 +413,8 @@ public function submit(QuoteEntity $quote, $orderData = [])
}

/**
* Resolve items
*
* @param Quote $quote
* @return array
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ public function testPlaceOrderIfCustomerIsGuest()

$addressMock = $this->createPartialMock(\Magento\Quote\Model\Quote\Address::class, ['getEmail']);
$addressMock->expects($this->once())->method('getEmail')->willReturn($email);
$this->quoteMock->expects($this->once())->method('getBillingAddress')->with()->willReturn($addressMock);
$this->quoteMock->expects($this->any())->method('getBillingAddress')->with()->willReturn($addressMock);

$this->quoteMock->expects($this->once())->method('setCustomerIsGuest')->with(true)->willReturnSelf();
$this->quoteMock->expects($this->once())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public function testSetCustomerData(): void
$customer = $quote->getCustomer();
$this->assertEquals($expected, $this->convertToArray($customer));
$this->assertEquals('qa@example.com', $quote->getCustomerEmail());
$this->assertEquals('Joe', $quote->getCustomerFirstname());
$this->assertEquals('Dou', $quote->getCustomerLastname());
$this->assertEquals('Ivan', $quote->getCustomerMiddlename());
}

/**
Expand Down