Skip to content

Commit 9e90edc

Browse files
committed
Merge remote-tracking branch 'magento-l3/ACP2E-2622' into Tier4-Kings-PR-03-19-2024
2 parents c971859 + 9d9025a commit 9e90edc

File tree

4 files changed

+153
-11
lines changed
  • app/code/Magento/Sales
  • dev/tests/integration/testsuite/Magento/Sales/Model/ResourceModel/Order
  • lib/internal/Magento/Framework/Model/ResourceModel/Db/VersionControl

4 files changed

+153
-11
lines changed

app/code/Magento/Sales/Model/ResourceModel/Order/Address.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Sales\Model\ResourceModel\Order;
77

8+
use Magento\Framework\Model\AbstractModel;
89
use Magento\Sales\Model\ResourceModel\EntityAbstract as SalesResource;
910
use Magento\Sales\Model\Spi\OrderAddressResourceInterface;
1011
use Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot;
@@ -15,7 +16,7 @@
1516
class Address extends SalesResource implements OrderAddressResourceInterface
1617
{
1718
/**
18-
* Event prefix
19+
* Sales order address event prefix
1920
*
2021
* @var string
2122
*/
@@ -33,10 +34,10 @@ class Address extends SalesResource implements OrderAddressResourceInterface
3334

3435
/**
3536
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
36-
* @param \Magento\Sales\Model\ResourceModel\Attribute $attribute
37-
* @param \Magento\SalesSequence\Model\Manager $sequenceManager
3837
* @param Snapshot $entitySnapshot
3938
* @param \Magento\Framework\Model\ResourceModel\Db\VersionControl\RelationComposite $entityRelationComposite
39+
* @param \Magento\Sales\Model\ResourceModel\Attribute $attribute
40+
* @param \Magento\SalesSequence\Model\Manager $sequenceManager
4041
* @param \Magento\Sales\Model\Order\Address\Validator $validator
4142
* @param \Magento\Sales\Model\ResourceModel\GridPool $gridPool
4243
* @param string $connectionName
@@ -122,4 +123,24 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
122123
}
123124
return $this;
124125
}
126+
127+
/**
128+
* @inheritdoc
129+
*/
130+
protected function isModified(AbstractModel $entity): bool
131+
{
132+
if (!$entity->getId()) {
133+
return true;
134+
}
135+
$snapShotData = $this->entitySnapshot->getSnapshotData($entity);
136+
foreach ($snapShotData as $field => $value) {
137+
$fieldValue = $entity->getDataByKey($field);
138+
if (is_numeric($fieldValue) && is_numeric($value)) {
139+
if ($fieldValue !== $value) {
140+
return true;
141+
}
142+
}
143+
}
144+
return parent::isModified($entity);
145+
}
125146
}

app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/AddressTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ public function testSave()
9898
->method('validate')
9999
->with($this->addressMock)
100100
->willReturn([]);
101-
$this->entitySnapshotMock->expects($this->once())
102-
->method('isModified')
103-
->with($this->addressMock)
104-
->willReturn(true);
105101
$this->addressMock->expects($this->once())
106102
->method('getParentId')
107103
->willReturn(1);
@@ -116,10 +112,6 @@ public function testSaveValidationFailed()
116112
{
117113
$this->expectException('Magento\Framework\Exception\LocalizedException');
118114
$this->expectExceptionMessage('We can\'t save the address:');
119-
$this->entitySnapshotMock->expects($this->once())
120-
->method('isModified')
121-
->with($this->addressMock)
122-
->willReturn(true);
123115
$this->addressMock->expects($this->any())
124116
->method('hasDataChanges')
125117
->willReturn(true);
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
/**
3+
* Copyright 2023 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained
13+
* from Adobe.
14+
*/
15+
declare(strict_types=1);
16+
17+
namespace Magento\Sales\Model\ResourceModel\Order;
18+
19+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
20+
use Magento\Checkout\Test\Fixture\PlaceOrder as PlaceOrderFixture;
21+
use Magento\Checkout\Test\Fixture\SetBillingAddress;
22+
use Magento\Checkout\Test\Fixture\SetDeliveryMethod as SetDeliveryMethodFixture;
23+
use Magento\Checkout\Test\Fixture\SetPaymentMethod as SetPaymentMethodFixture;
24+
use Magento\Checkout\Test\Fixture\SetShippingAddress;
25+
use Magento\Customer\Test\Fixture\Customer;
26+
use Magento\Framework\Exception\LocalizedException;
27+
use Magento\Quote\Test\Fixture\AddProductToCart;
28+
use Magento\Quote\Test\Fixture\CustomerCart;
29+
use Magento\Sales\Api\OrderAddressRepositoryInterface;
30+
use Magento\Sales\Api\OrderRepositoryInterface;
31+
use Magento\TestFramework\Fixture\DataFixture;
32+
use Magento\TestFramework\Fixture\DataFixtureStorage;
33+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
34+
use Magento\TestFramework\Fixture\DbIsolation;
35+
use Magento\TestFramework\Helper\Bootstrap;
36+
use Magento\TestFramework\ObjectManager;
37+
use PHPUnit\Framework\TestCase;
38+
39+
/**
40+
* Test for order address
41+
*
42+
* @magentoAppArea adminhtml
43+
*/
44+
class AddressTest extends TestCase
45+
{
46+
/**
47+
* @var ObjectManager
48+
*/
49+
private $objectManager;
50+
51+
/**
52+
* @var DataFixtureStorage
53+
*/
54+
private $fixtures;
55+
56+
/**
57+
* @var OrderAddressRepositoryInterface
58+
*/
59+
private $orderAddressRepository;
60+
61+
/**
62+
* @var OrderRepositoryInterface
63+
*/
64+
private $orderRepository;
65+
66+
protected function setUp(): void
67+
{
68+
$this->objectManager = Bootstrap::getObjectManager();
69+
$this->fixtures = $this->objectManager->get(DataFixtureStorageManager::class)->getStorage();
70+
$this->orderAddressRepository = $this->objectManager->get(OrderAddressRepositoryInterface::class);
71+
$this->orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
72+
}
73+
74+
/**
75+
* Check to see if leading zeros have been added to the number strings
76+
* in the order address's phone field.
77+
*
78+
* @return void
79+
* @throws LocalizedException
80+
*/
81+
#[
82+
DataFixture(ProductFixture::class, as: 'product'),
83+
DataFixture(Customer::class, as: 'customer'),
84+
DataFixture(CustomerCart::class, ['customer_id' => '$customer.id$'], as: 'quote'),
85+
DataFixture(AddProductToCart::class, ['cart_id' => '$quote.id$', 'product_id' => '$product.id$', 'qty' => 1]),
86+
DataFixture(SetBillingAddress::class, [
87+
'cart_id' => '$quote.id$',
88+
'address' => [
89+
'customer_id' => '$customer.id$',
90+
'telephone' => '009999999999'
91+
]
92+
]),
93+
DataFixture(SetShippingAddress::class, ['cart_id' => '$quote.id$']),
94+
DataFixture(SetDeliveryMethodFixture::class, ['cart_id' => '$quote.id$']),
95+
DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$quote.id$']),
96+
DataFixture(PlaceOrderFixture::class, ['cart_id' => '$quote.id$'], 'order')
97+
]
98+
public function testOrderAddressUpdateWithTelephone(): void
99+
{
100+
$telephoneValue = '9999999999';
101+
$order = $this->fixtures->get('order');
102+
$address = $this->orderAddressRepository->get($order->getBillingAddressId());
103+
$address->setTelephone($telephoneValue);
104+
$this->orderAddressRepository->save($address);
105+
$updatedOrder = $this->orderRepository->get($order->getId());
106+
$billingAddress = $updatedOrder->getBillingAddress();
107+
$updatedTelephoneValue = $billingAddress->getTelephone();
108+
$this->assertEquals($telephoneValue, $updatedTelephoneValue);
109+
}
110+
}

lib/internal/Magento/Framework/Model/ResourceModel/Db/VersionControl/Snapshot.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Framework\Model\ResourceModel\Db\VersionControl;
77

8+
use Magento\Framework\DataObject;
89
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
910

1011
/**
@@ -50,6 +51,24 @@ public function registerSnapshot(\Magento\Framework\DataObject $entity)
5051
$this->snapshotData[get_class($entity)][$entity->getId()] = $data;
5152
}
5253

54+
/**
55+
* Get snapshot data
56+
*
57+
* @param DataObject $entity
58+
* @return array
59+
*/
60+
public function getSnapshotData(DataObject $entity): array
61+
{
62+
$entityClass = get_class($entity);
63+
$entityId = $entity->getId();
64+
65+
if (isset($this->snapshotData[$entityClass][$entityId])) {
66+
return $this->snapshotData[$entityClass][$entityId];
67+
}
68+
69+
return [];
70+
}
71+
5372
/**
5473
* Check is current entity has changes, by comparing current object state with stored snapshot
5574
*

0 commit comments

Comments
 (0)