Skip to content

Cannot save only group_id using \Magento\Customer\Model\ResourceModel\Customer::saveAttribute #35699

Open
@ioweb-gr

Description

@ioweb-gr

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{}}}:

  1. Create customer (ex. ID = 100500).
  2. Create address for customer (ex. ID = 123).
  3. 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'); `#

  1.  

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”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: FrameworkComponent: CustomerAttributesIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: ready for devReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions