Skip to content

Commit b13fc15

Browse files
authored
Merge pull request #6057 from magento-honey-badgers/MC-36838
[honey] MC-36838: [GraphQL] Cannot checkout with automatic customer group assignment
2 parents ac45071 + d8e4ce6 commit b13fc15

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

app/code/Magento/Quote/Observer/Frontend/Quote/Address/CollectTotalsObserver.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,10 @@ public function execute(\Magento\Framework\Event\Observer $observer)
135135
$address->setPrevQuoteCustomerGroupId($quote->getCustomerGroupId());
136136
$quote->setCustomerGroupId($groupId);
137137
$this->customerSession->setCustomerGroupId($groupId);
138-
$customer->setGroupId($groupId);
139-
$quote->setCustomer($customer);
138+
if ($customer->getId() !== null) {
139+
$customer->setGroupId($groupId);
140+
$quote->setCustomer($customer);
141+
}
140142
}
141143
}
142144
}

app/code/Magento/Quote/Test/Unit/Observer/Frontend/Quote/Address/CollectTotalsObserverTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public function testDispatchWithDefaultCustomerGroupId()
269269
$this->quoteMock->expects($this->once())
270270
->method('getCustomerGroupId')
271271
->willReturn('customerGroupId');
272-
$this->customerMock->expects($this->once())->method('getId')->willReturn('1');
272+
$this->customerMock->expects($this->exactly(2))->method('getId')->willReturn('1');
273273
$this->groupManagementMock->expects($this->once())
274274
->method('getDefaultGroup')
275275
->willReturn($this->groupInterfaceMock);
@@ -329,6 +329,7 @@ public function testDispatchWithCustomerCountryInEU()
329329
->method('setPrevQuoteCustomerGroupId')
330330
->with('customerGroupId');
331331

332+
$this->customerMock->expects($this->once())->method('getId')->willReturn('1');
332333
$this->quoteMock->expects($this->once())->method('setCustomerGroupId')->with('customerGroupId');
333334
$this->quoteMock->expects($this->once())->method('setCustomer')->with($this->customerMock);
334335
$this->customerDataFactoryMock->expects($this->any())
@@ -436,6 +437,8 @@ public function testDispatchWithEmptyShippingAddress()
436437
->method('setPrevQuoteCustomerGroupId')
437438
->with('customerGroupId');
438439

440+
$this->customerMock->expects($this->once())->method('getId')->willReturn('1');
441+
439442
$this->quoteMock->expects($this->once())->method('setCustomerGroupId')->with('customerGroupId');
440443
$this->quoteMock->expects($this->once())->method('setCustomer')->with($this->customerMock);
441444
$this->customerDataFactoryMock->expects($this->any())

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/PlaceOrderTest.php

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Magento\GraphQl\Quote\Guest;
99

10-
use Exception;
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
1111
use Magento\Framework\Registry;
1212
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1313
use Magento\Sales\Api\OrderRepositoryInterface;
@@ -56,7 +56,10 @@ protected function setUp(): void
5656
$this->orderCollectionFactory = $objectManager->get(CollectionFactory::class);
5757
$this->orderRepository = $objectManager->get(OrderRepositoryInterface::class);
5858
$this->orderFactory = $objectManager->get(OrderFactory::class);
59-
$this->registry = Bootstrap::getObjectManager()->get(Registry::class);
59+
$this->registry = $objectManager->get(Registry::class);
60+
/** @var ScopeConfigInterface $scopeConfig */
61+
$scopeConfig = $objectManager->get(ScopeConfigInterface::class);
62+
$scopeConfig->clean();
6063
}
6164

6265
/**
@@ -68,6 +71,7 @@ protected function setUp(): void
6871
* @magentoConfigFixture default_store payment/cashondelivery/active 1
6972
* @magentoConfigFixture default_store payment/checkmo/active 1
7073
* @magentoConfigFixture default_store payment/purchaseorder/active 1
74+
* @magentoConfigFixture default_store customer/create_account/auto_group_assign 0
7175
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
7276
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
7377
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
@@ -94,6 +98,42 @@ public function testPlaceOrder()
9498
}
9599

96100
/**
101+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
102+
* @magentoConfigFixture default_store carriers/flatrate/active 1
103+
* @magentoConfigFixture default_store carriers/tablerate/active 1
104+
* @magentoConfigFixture default_store carriers/freeshipping/active 1
105+
* @magentoConfigFixture default_store payment/banktransfer/active 1
106+
* @magentoConfigFixture default_store payment/cashondelivery/active 1
107+
* @magentoConfigFixture default_store payment/checkmo/active 1
108+
* @magentoConfigFixture default_store payment/purchaseorder/active 1
109+
* @magentoConfigFixture default_store customer/create_account/auto_group_assign 1
110+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
111+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
112+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
113+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
114+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
115+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
116+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php
117+
*/
118+
public function testPlaceOrderWithAutoGroup()
119+
{
120+
$reservedOrderId = 'test_quote';
121+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
122+
123+
$query = $this->getQuery($maskedQuoteId);
124+
$response = $this->graphQlMutation($query);
125+
126+
self::assertArrayHasKey('placeOrder', $response);
127+
self::assertArrayHasKey('order_number', $response['placeOrder']['order']);
128+
self::assertEquals($reservedOrderId, $response['placeOrder']['order']['order_number']);
129+
$orderIncrementId = $response['placeOrder']['order']['order_number'];
130+
$order = $this->orderFactory->create();
131+
$order->loadByIncrementId($orderIncrementId);
132+
$this->assertNotEmpty($order->getEmailSent());
133+
}
134+
135+
/**
136+
* @magentoConfigFixture default_store customer/create_account/auto_group_assign 0
97137
*/
98138
public function testPlaceOrderIfCartIdIsEmpty()
99139
{
@@ -115,6 +155,7 @@ public function testPlaceOrderIfCartIdIsEmpty()
115155
* @magentoConfigFixture default_store payment/cashondelivery/active 1
116156
* @magentoConfigFixture default_store payment/checkmo/active 1
117157
* @magentoConfigFixture default_store payment/purchaseorder/active 1
158+
* @magentoConfigFixture default_store customer/create_account/auto_group_assign 0
118159
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
119160
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
120161
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
@@ -268,6 +309,7 @@ public function testPlaceOrderWithOutOfStockProduct()
268309
* @magentoConfigFixture default_store payment/cashondelivery/active 1
269310
* @magentoConfigFixture default_store payment/checkmo/active 1
270311
* @magentoConfigFixture default_store payment/purchaseorder/active 1
312+
* @magentoConfigFixture default_store customer/create_account/auto_group_assign 0
271313
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
272314
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
273315
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php

0 commit comments

Comments
 (0)