Description
Preconditions and environment
- 2.4.1
Steps to reproduce
Use the following sample code
``{{php
public function __construct(
CustomerRepositoryInterface $customerRepository,
Customer $customerResourceModel,
CustomerFactory $customerFactory
}
{ $this->customerRepository = $customerRepository; $this->customerResourceModel = $customerResourceModel; $this->customerFactory = $customerFactory; }
}}``
And then
$customer = $this->customerFactory()->create();
$this->customerResourceModel->load($customer, <id>);
$customer->setGroupId(<new_id>);
$this->customerResourceModel->saveAttribute($customer, 'group_id');
Expected result
The customer group_id is changed
Actual result
SQLSTATE<42S22>: Column not found: 1054
Unknown column 'customer*entity.value_id' in 'field list', query was: SELECT `customer_entity\`.`value*id`,
`customer*entity\`.`value\` FROM `customer_entity` WHERE (attribute_id='10' AND entity*id='7218')
Additional information
It seems that the \Magento\Eav\Model\Entity\AbstractEntity::saveAttribute
function cannot properly save the value because it's building the wrong select query.
SELECT `customer*entity\`.`value_id\`, `customer_entity\`.`value\` FROM `customer_entity` WHERE (attribute_id='10' AND entity*id='7352')
Instead of using
SELECT `customer*entity\`.`group_id\`, `customer_entity\`.`value\` FROM `customer_entity` WHERE (entity*id='7352')
So it has an issue with static attributes.
Similar Issue
There is a similar issue here #35064. Copying its content here and marking that issue as a duplicate of this one
unable to save Customer's billing address with {{{}saveAttribute{}}}:
- Create customer (ex. ID = 100500).
- Create address for customer (ex. ID = 123).
- Run code
`` $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
/*** @var \Magento\Customer\Model\Customer $customer /
$customer = $objectManager->create(\Magento\Customer\Model\Customer::class);
/* @var \Magento\Customer\Model\ResourceModel\Customer $customerResource **/
$customerResource = $objectManager->get(\Magento\Customer\Model\ResourceModel\Customer::class);
$customerResource->load($customer, 100500);
$customer->setDefaultBilling(123);
$customerResource->saveAttribute($customer, 'default_billing'); `#
Release note
No response
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- < > Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- < > Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- < > Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- < > Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.