Skip to content

Commit 896f4a2

Browse files
committed
Merge branch 'ACP2E-1358' of https://github.com/magento-l3/magento2ce into PR-L3-2023-01-31
2 parents 7ca752f + 2ce33e5 commit 896f4a2

File tree

2 files changed

+56
-11
lines changed

2 files changed

+56
-11
lines changed

app/code/Magento/Eav/Model/Entity/AbstractEntity.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,7 @@ public function load($object, $entityId, $attributes = [])
10191019
* Loads attributes metadata.
10201020
*
10211021
* @deprecated 101.0.0 Use self::loadAttributesForObject instead
1022+
* @see \Magento\Eav\Model\Entity\AbstractEntity::loadAttributesForObject
10221023
* @param array|null $attributes
10231024
* @return $this
10241025
* @since 100.1.0
@@ -1544,7 +1545,15 @@ protected function _insertAttribute($object, $attribute, $value)
15441545
*/
15451546
protected function _updateAttribute($object, $attribute, $valueId, $value)
15461547
{
1547-
return $this->_saveAttribute($object, $attribute, $value);
1548+
$table = $attribute->getBackend()->getTable();
1549+
$connection = $this->getConnection();
1550+
$connection->update(
1551+
$table,
1552+
['value' => $this->_prepareValueForSave($value, $attribute)],
1553+
sprintf('%s=%d', $connection->quoteIdentifier('value_id'), $valueId)
1554+
);
1555+
1556+
return $this;
15481557
}
15491558

15501559
/**
@@ -1926,6 +1935,7 @@ protected function _isAttributeValueEmpty(AbstractAttribute $attribute, $value)
19261935
* @return AttributeLoaderInterface
19271936
*
19281937
* @deprecated 100.1.0
1938+
* @see $attributeLoader
19291939
* @since 100.1.0
19301940
*/
19311941
protected function getAttributeLoader()

dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/CustomerRepositoryTest.php

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,30 @@
88

99
use Magento\Customer\Api\AccountManagementInterface;
1010
use Magento\Customer\Api\CustomerRepositoryInterface;
11-
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
11+
use Magento\Customer\Api\Data\AddressInterface;
1212
use Magento\Customer\Api\Data\AddressInterfaceFactory;
13-
use Magento\Framework\Api\ExtensibleDataObjectConverter;
14-
use Magento\Framework\Api\DataObjectHelper;
15-
use Magento\Framework\Encryption\EncryptorInterface;
1613
use Magento\Customer\Api\Data\CustomerInterface;
14+
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
15+
use Magento\Customer\Model\Customer;
1716
use Magento\Customer\Model\CustomerRegistry;
17+
use Magento\Framework\Api\DataObjectHelper;
18+
use Magento\Framework\Api\ExtensibleDataObjectConverter;
19+
use Magento\Framework\Api\FilterBuilder;
20+
use Magento\Framework\Api\SearchCriteriaBuilder;
1821
use Magento\Framework\Api\SortOrder;
22+
use Magento\Framework\Api\SortOrderBuilder;
1923
use Magento\Framework\Config\CacheInterface;
24+
use Magento\Framework\Encryption\EncryptorInterface;
25+
use Magento\Framework\Exception\NoSuchEntityException;
2026
use Magento\Framework\ObjectManagerInterface;
2127
use Magento\Framework\Validator\Exception as ValidatorException;
2228
use Magento\Sales\Api\Data\OrderInterface;
2329
use Magento\Sales\Api\OrderRepositoryInterface;
2430
use Magento\TestFramework\Helper\Bootstrap;
25-
use Magento\Customer\Api\Data\AddressInterface;
26-
use Magento\Framework\Api\SearchCriteriaBuilder;
27-
use Magento\Framework\Api\FilterBuilder;
28-
use Magento\Framework\Api\SortOrderBuilder;
29-
use Magento\Framework\Exception\NoSuchEntityException;
30-
use Magento\Customer\Model\Customer;
31+
use Magento\TestFramework\Fixture\Config as ConfigFixture;
32+
use Magento\TestFramework\Fixture\DataFixture;
33+
use Magento\TestFramework\Fixture\DataFixtureStorage;
34+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
3135

3236
/**
3337
* Checks Customer insert, update, search with repository
@@ -244,6 +248,37 @@ public function testUpdateCustomer($defaultBilling, $defaultShipping)
244248
$this->assertNotContains('password_hash', array_keys($inAfterOnly));
245249
}
246250

251+
/**
252+
* Test update customer custom attributes
253+
*
254+
* @magentoDataFixture Magento/Customer/_files/attribute_user_defined_custom_attribute.php
255+
* @return void
256+
*/
257+
#[
258+
DataFixture(\Magento\Customer\Test\Fixture\Customer::class, ['email' => 'customer@mail.com'])
259+
]
260+
261+
public function testUpdateCustomerAttributesAutoIncrement()
262+
{
263+
$newAttributeValue = 'value1';
264+
$updateAttributeValue = 'value2';
265+
$customer = $this->customerRepository->get('customer@mail.com');
266+
$customer->setCustomAttribute('custom_attribute1', $newAttributeValue);
267+
$savedCustomer = $this->customerRepository->save($customer);
268+
$savedCustomer->setCustomAttribute('custom_attribute1', $updateAttributeValue);
269+
$this->customerRepository->save($savedCustomer);
270+
$customer = $this->customerRepository->get('customer@mail.com');
271+
272+
$this->assertSame(
273+
$customer->getCustomAttribute('custom_attribute1')->getValue(),
274+
$updateAttributeValue
275+
);
276+
$resource = $this->objectManager->get(\Magento\Framework\App\ResourceConnection::class);
277+
$connection = $resource->getConnection();
278+
$tableStatus = $connection->showTableStatus('customer_entity_varchar');
279+
$this->assertSame($tableStatus['Auto_increment'], '2');
280+
}
281+
247282
/**
248283
* Test update customer address
249284
*

0 commit comments

Comments
 (0)