From ccba42089f1ca465cb43fc60339671db5e9a504a Mon Sep 17 00:00:00 2001 From: NazarKlovanych Date: Tue, 13 Nov 2018 16:59:23 +0200 Subject: [PATCH 1/5] Customer related values are NULL for guests --- app/code/Magento/Quote/Model/QuoteManagement.php | 6 ++++++ .../Magento/Quote/Test/Unit/Model/QuoteManagementTest.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php index 451ad08d425f5..b71cee9845134 100644 --- a/app/code/Magento/Quote/Model/QuoteManagement.php +++ b/app/code/Magento/Quote/Model/QuoteManagement.php @@ -354,6 +354,12 @@ public function placeOrder($cartId, PaymentInterface $paymentMethod = null) if ($quote->getCheckoutMethod() === self::METHOD_GUEST) { $quote->setCustomerId(null); $quote->setCustomerEmail($quote->getBillingAddress()->getEmail()); + $quote->setCustomerFirstname($quote->getBillingAddress()->getFirstname()); + $quote->setCustomerLastname($quote->getBillingAddress()->getLastname()); + + if ($quote->getBillingAddress()->getMiddlename()) { + $quote->setCustomerMiddlename($quote->getBillingAddress()->getMiddlename()); + } $quote->setCustomerIsGuest(true); $quote->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID); } diff --git a/app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php index 107445bb18d2a..c7b271ca1d3c6 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php @@ -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()) From f8a6d059fbe002e6bcc1a81ea9fdc73f069f97e2 Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Tue, 13 Nov 2018 21:03:07 +0200 Subject: [PATCH 2/5] fix code style --- .../Magento/Quote/Model/QuoteManagement.php | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php index b71cee9845134..e4ee95b80228f 100644 --- a/app/code/Magento/Quote/Model/QuoteManagement.php +++ b/app/code/Magento/Quote/Model/QuoteManagement.php @@ -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 @@ -221,7 +221,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ public function createEmptyCart() { @@ -241,7 +241,7 @@ public function createEmptyCart() } /** - * {@inheritdoc} + * @inheritdoc */ public function createEmptyCartForCustomer($customerId) { @@ -257,7 +257,7 @@ public function createEmptyCartForCustomer($customerId) } /** - * {@inheritdoc} + * @inheritdoc */ public function assignCustomer($cartId, $customerId, $storeId) { @@ -332,7 +332,7 @@ protected function createCustomerCart($customerId, $storeId) } /** - * {@inheritdoc} + * @inheritdoc */ public function placeOrder($cartId, PaymentInterface $paymentMethod = null) { @@ -354,11 +354,12 @@ public function placeOrder($cartId, PaymentInterface $paymentMethod = null) if ($quote->getCheckoutMethod() === self::METHOD_GUEST) { $quote->setCustomerId(null); $quote->setCustomerEmail($quote->getBillingAddress()->getEmail()); - $quote->setCustomerFirstname($quote->getBillingAddress()->getFirstname()); - $quote->setCustomerLastname($quote->getBillingAddress()->getLastname()); - - if ($quote->getBillingAddress()->getMiddlename()) { - $quote->setCustomerMiddlename($quote->getBillingAddress()->getMiddlename()); + 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); @@ -385,7 +386,7 @@ public function placeOrder($cartId, PaymentInterface $paymentMethod = null) } /** - * {@inheritdoc} + * @inheritdoc */ public function getCartForCustomer($customerId) { @@ -412,6 +413,8 @@ public function submit(QuoteEntity $quote, $orderData = []) } /** + * Resolve items + * * @param Quote $quote * @return array */ From 7607c829e066b541bed53fea65d171c006834849 Mon Sep 17 00:00:00 2001 From: NazarKlovanych Date: Fri, 16 Nov 2018 10:09:07 +0200 Subject: [PATCH 3/5] Revert "Customer related values are NULL for guests" This reverts commit ccba420 --- .../integration/testsuite/Magento/Quote/Model/QuoteTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dev/tests/integration/testsuite/Magento/Quote/Model/QuoteTest.php b/dev/tests/integration/testsuite/Magento/Quote/Model/QuoteTest.php index 72c5d7736a30d..15f555a67e722 100644 --- a/dev/tests/integration/testsuite/Magento/Quote/Model/QuoteTest.php +++ b/dev/tests/integration/testsuite/Magento/Quote/Model/QuoteTest.php @@ -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()); } /** From e20c7efd4b8d61dac21a3d1691d6b2c950826d59 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Mon, 4 Feb 2019 16:41:21 +0200 Subject: [PATCH 4/5] ENGCOM-3477: Static test fix. --- app/code/Magento/Quote/Model/QuoteManagement.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php index 8816e4121b062..8f216b64aa9b0 100644 --- a/app/code/Magento/Quote/Model/QuoteManagement.php +++ b/app/code/Magento/Quote/Model/QuoteManagement.php @@ -25,6 +25,7 @@ /** * Class QuoteManagement * + * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.TooManyFields) */ From 7d22ae870c3b4e8224f620f877686678c0f2fa16 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Tue, 5 Feb 2019 17:25:50 +0200 Subject: [PATCH 5/5] ENGCOM-3477: MFTF test fix. --- .../Checkout/Test/Mftf/Test/StorefrontGuestCheckoutTest.xml | 2 +- app/code/Magento/Customer/Test/Mftf/Data/CustomerData.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontGuestCheckoutTest.xml b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontGuestCheckoutTest.xml index 7b81f12624864..ff61b3be08af1 100644 --- a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontGuestCheckoutTest.xml +++ b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontGuestCheckoutTest.xml @@ -63,7 +63,7 @@ - + diff --git a/app/code/Magento/Customer/Test/Mftf/Data/CustomerData.xml b/app/code/Magento/Customer/Test/Mftf/Data/CustomerData.xml index ab42dfe85e4ff..f07eb2ecb97ce 100644 --- a/app/code/Magento/Customer/Test/Mftf/Data/CustomerData.xml +++ b/app/code/Magento/Customer/Test/Mftf/Data/CustomerData.xml @@ -21,6 +21,7 @@ John Doe S + John Doe pwdTest123! Mr Sr