Skip to content

Commit 74aef3a

Browse files
committed
ACP2E-279: Customer details are lost after editing an order.
1 parent e7f8c4a commit 74aef3a

File tree

6 files changed

+99
-13
lines changed

6 files changed

+99
-13
lines changed

app/code/Magento/Sales/Controller/Adminhtml/Order/AddressSave.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class AddressSave extends Order implements HttpPostActionInterface
4141
*
4242
* @see _isAllowed()
4343
*/
44-
const ADMIN_RESOURCE = 'Magento_Sales::actions_edit';
44+
public const ADMIN_RESOURCE = 'Magento_Sales::actions_edit';
4545

4646
/**
4747
* @var RegionFactory
@@ -72,6 +72,7 @@ class AddressSave extends Order implements HttpPostActionInterface
7272
* @param LoggerInterface $logger
7373
* @param RegionFactory|null $regionFactory
7474
* @param OrderAddressRepositoryInterface|null $orderAddressRepository
75+
* @param AttributeMetadataDataProvider|null $attributeMetadataDataProvider
7576
*
7677
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
7778
*/

app/code/Magento/Sales/Model/AdminOrder/Create.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\
3333
/**
3434
* Xml default email domain path
3535
*/
36-
const XML_PATH_DEFAULT_EMAIL_DOMAIN = 'customer/create_account/email_domain';
36+
private const XML_PATH_DEFAULT_EMAIL_DOMAIN = 'customer/create_account/email_domain';
3737

3838
private const XML_PATH_EMAIL_REQUIRED_CREATE_ORDER = 'customer/create_account/email_required_create_order';
3939
/**
@@ -100,8 +100,6 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\
100100
protected $_quote;
101101

102102
/**
103-
* Core registry
104-
*
105103
* @var \Magento\Framework\Registry
106104
*/
107105
protected $_coreRegistry = null;
@@ -1844,7 +1842,6 @@ public function _prepareCustomer()
18441842
->setStoreId($store->getId())
18451843
->setWebsiteId($store->getWebsiteId())
18461844
->setCreatedAt(null);
1847-
$customer = $this->_validateCustomerData($customer);
18481845
}
18491846

18501847
$customerBillingAddressDataObject = $this->getBillingAddress()->exportCustomerAddress();

dev/tests/integration/testsuite/Magento/Bundle/Model/Sales/AdminOrder/ReorderTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,23 @@ public function testReorderBundleProductWithCustomPrice(): void
6767
self::assertEquals(0, (int)$quoteItem->getCustomPrice());
6868
}
6969

70+
$customerMock = $this->getMockBuilder(\Magento\Customer\Model\Data\Customer::class)
71+
->disableOriginalConstructor()
72+
->setMethods(
73+
[
74+
'getGroupId',
75+
'getEmail',
76+
'_getExtensionAttributes'
77+
]
78+
)->getMock();
79+
$customerMock->method('getGroupId')
80+
->willReturn(1);
81+
$customerMock->method('getEmail')
82+
->willReturn('[email protected]');
83+
$customerMock->method('_getExtensionAttributes')
84+
->willReturn(NULL);
85+
$this->model->getQuote()->setCustomer($customerMock);
86+
7087
$shippingMethod = 'freeshipping_freeshipping';
7188
/** @var Rate $rate */
7289
$rate = $this->objectManager->create(Rate::class);

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Sales/AdminOrder/ReorderTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,23 @@ public function testReorderConfigurableProductWithCustomPrice(): void
6767
self::assertEquals(0, (int)$quoteItem->getCustomPrice());
6868
}
6969

70+
$customerMock = $this->getMockBuilder(\Magento\Customer\Model\Data\Customer::class)
71+
->disableOriginalConstructor()
72+
->setMethods(
73+
[
74+
'getGroupId',
75+
'getEmail',
76+
'_getExtensionAttributes'
77+
]
78+
)->getMock();
79+
$customerMock->method('getGroupId')
80+
->willReturn(1);
81+
$customerMock->method('getEmail')
82+
->willReturn('[email protected]');
83+
$customerMock->method('_getExtensionAttributes')
84+
->willReturn(NULL);
85+
$this->model->getQuote()->setCustomer($customerMock);
86+
7087
$shippingMethod = 'freeshipping_freeshipping';
7188
/** @var Rate $rate */
7289
$rate = $this->objectManager->create(Rate::class);

dev/tests/integration/testsuite/Magento/Sales/Controller/Adminhtml/Order/AddressSaveTest.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
namespace Magento\Sales\Controller\Adminhtml\Order;
99

1010
use Magento\Framework\App\Request\Http as HttpRequest;
11-
use Magento\Quote\Model\QuoteRepository;
1211
use Magento\Sales\Api\Data\OrderAddressInterface;
1312
use Magento\Sales\Api\Data\OrderInterface;
13+
use Magento\Sales\Api\OrderRepositoryInterface;
1414
use Magento\Sales\Api\Data\OrderInterfaceFactory;
1515
use Magento\Sales\Api\OrderAddressRepositoryInterface;
16+
use Magento\Sales\Model\Order as Order;
17+
use Magento\Quote\Model\Quote as Quote;
1618
use Magento\Sales\Model\Order\Address as AddressType;
1719
use Magento\TestFramework\TestCase\AbstractBackendController;
1820

@@ -47,6 +49,7 @@ protected function setUp(): void
4749
* @dataProvider addressTypeProvider
4850
*
4951
* @magentoDataFixture Magento/Sales/_files/order.php
52+
* @magentoDataFixture Magento/Sales/_files/quote.php
5053
*
5154
* @param string $type
5255
* @return void
@@ -63,7 +66,14 @@ public function testSave(string $type): void
6366
OrderAddressInterface::POSTCODE => '97203',
6467
OrderAddressInterface::TELEPHONE => '5555555555',
6568
];
69+
$quote = $this->_objectManager->create(Quote::class);
70+
$quote->load('test01', 'reserved_order_id');
71+
6672
$order = $this->orderFactory->create()->loadByIncrementId(100000001);
73+
$order->setQuoteId($quote->getId());
74+
$orderRepository = $this->_objectManager->create(OrderRepositoryInterface::class);
75+
$orderRepository->save($order);
76+
6777
$addressId = $this->getAddressIdByType($order, $type);
6878
$this->dispatchWithParams(
6979
['address_id' => $addressId],
@@ -76,13 +86,6 @@ public function testSave(string $type): void
7686
$this->stringContains(sprintf('sales/order/view/order_id/%s/', $order->getId()))
7787
);
7888
$this->assertAddressData($addressId, $data);
79-
/** @var $quoteobj QuoteRepository */
80-
$quoteobj = $this->objectManager->create(QuoteRepository::class);
81-
$quote = $quoteobj->get($order->getQuoteId());
82-
self::assertEquals('New test name', $quote->getCustomerFirstname());
83-
self::assertEquals('New test lastname', $quote->getCustomerLastname());
84-
self::assertEquals('New test name', $order->getCustomerFirstname());
85-
self::assertEquals('New test lastname', $order->getCustomerLastname());
8689
}
8790

8891
/**
@@ -143,6 +146,14 @@ private function assertAddressData(int $addressId, array $expectedData): void
143146
? $this->assertEquals(reset($value), $address->getData($key))
144147
: $this->assertEquals($value, $address->getData($key));
145148
}
149+
if ($address->getAddressType() === 'billing') {
150+
$order = $this->_objectManager->create(Order::class)->load($address->getParentId());
151+
$quote = $this->_objectManager->create(Quote::class)->load($order->getQuoteId());
152+
$this->assertEquals('New test name', $quote->getCustomerFirstname());
153+
$this->assertEquals('New test lastname', $quote->getCustomerLastname());
154+
$this->assertEquals($quote->getCustomerFirstname(), $order->getCustomerFirstname());
155+
$this->assertEquals($quote->getCustomerLastname(), $order->getCustomerLastname());
156+
}
146157
}
147158

148159
/**

dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,12 @@ public function testInitFromOrderAndCreateOrderFromQuoteWithAdditionalOptions()
103103

104104
$customer = $this->objectManager->create(Customer::class);
105105
$customer->load(1)->setDefaultBilling(null)->setDefaultShipping(null)->save();
106+
$customerMock = $this->getMockedCustomer();
106107

107108
$rate = $this->objectManager->create(Quote\Address\Rate::class);
108109
$rate->setCode('freeshipping_freeshipping');
109110

111+
$this->model->getQuote()->setCustomer($customerMock);
110112
$this->model->getQuote()->getShippingAddress()->addShippingRate($rate);
111113
$this->model->getQuote()->getShippingAddress()->setCountryId('EE');
112114
$this->model->setShippingAsBilling(0);
@@ -399,6 +401,11 @@ public function testCreateOrderNewCustomerDifferentAddresses()
399401
$paymentMethod
400402
);
401403
$order = $this->model->createOrder();
404+
$newBillAddress = $order->getBillingAddress();
405+
self::assertEquals($this->model->getQuote()->getCustomerFirstname(), $newBillAddress->getFirstname());
406+
self::assertEquals($this->model->getQuote()->getCustomerLastname(), $newBillAddress->getLastname());
407+
self::assertEquals($order->getCustomerFirstname(), $newBillAddress->getFirstname());
408+
self::assertEquals($order->getCustomerLastname(), $newBillAddress->getLastname());
402409
$this->verifyCreatedOrder($order, $shippingMethod);
403410
/** @var Customer $customer */
404411
$customer = $this->objectManager->create(Customer::class);
@@ -569,6 +576,9 @@ public function testCreateOrderExistingCustomerDifferentAddresses()
569576
$paymentMethod,
570577
$customerIdFromFixture
571578
);
579+
$customerMock = $this->getMockedCustomer();
580+
581+
$this->model->getQuote()->setCustomer($customerMock);
572582
$order = $this->model->createOrder();
573583
$this->verifyCreatedOrder($order, $shippingMethod);
574584
$this->objectManager->get(CustomerRegistry::class)
@@ -617,6 +627,9 @@ public function testCreateOrderExistingCustomer()
617627
$paymentMethod,
618628
$customerIdFromFixture
619629
);
630+
$customerMock = $this->getMockedCustomer();
631+
632+
$this->model->getQuote()->setCustomer($customerMock);
620633
$order = $this->model->createOrder();
621634
$this->verifyCreatedOrder($order, $shippingMethod);
622635
}
@@ -861,6 +874,7 @@ public function testSetBillingAddressStreetValidationErrors()
861874
* They are set to message manager only during createOrder() call.
862875
*/
863876
$this->model->setIsValidate(true)->setBillingAddress($invalidAddressData);
877+
$this->model->setIsValidate(true)->setShippingAddress($invalidAddressData);
864878
try {
865879
$this->model->createOrder();
866880
$this->fail('Validation errors are expected to lead to exception during createOrder() call.');
@@ -939,4 +953,33 @@ public function testCreateOrderExistingCustomerWhenDefaultAddressDiffersWithNew(
939953
self::assertEquals('Validation is failed.', $e->getRawMessage());
940954
}
941955
}
956+
957+
/**
958+
* Get customer mock object.
959+
*
960+
* @return \Magento\Customer\Model\Data\Customer
961+
*/
962+
private function getMockedCustomer()
963+
{
964+
$customerMock = $this->getMockBuilder(\Magento\Customer\Model\Data\Customer::class)
965+
->disableOriginalConstructor()
966+
->setMethods(
967+
[
968+
'getId',
969+
'getGroupId',
970+
'getEmail',
971+
'_getExtensionAttributes'
972+
]
973+
)->getMock();
974+
$customerMock->method('getId')
975+
->willReturn(1);
976+
$customerMock->method('getGroupId')
977+
->willReturn(1);
978+
$customerMock->method('getEmail')
979+
->willReturn('[email protected]');
980+
$customerMock->method('_getExtensionAttributes')
981+
->willReturn(NULL);
982+
983+
return $customerMock;
984+
}
942985
}

0 commit comments

Comments
 (0)