Open ioweb-gr opened 2 years ago
Hi @ioweb-gr. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:
Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
@magento give me 2.4-develop instance
- upcoming 2.4.x release
For more details, review the Magento Contributor Assistant documentation.
Add a comment to assign the issue: @magento I am working on this
To learn more about issue processing workflow, refer to the Code Contributions.
Join Magento Community Engineering Slack and ask your questions in #github channel.
:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
:clock10: You can find the schedule on the Magento Community Calendar page.
:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel
Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).Details
If the issue has a valid description, the label Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.
[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description
label to the issue by yourself.
[ ] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.4-develop
branchDetails
- Add the comment @magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
[ ] 5. Add label Issue: Confirmed
once verification is complete.
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Hello @ioweb-gr,
Thanks for the report and collaboration!
We have tried to reproduce the issue in Magento 2.4-develop branch. Actually, I have a suggestion here, no need to save group_id as an attribute. The customer_entity
table has group_id
field. So we can set it through the customer model as given below:
$customer = $this->customerFactory->create();
$this->customerResourceModel->load($customer, 1);
$customer->setGroupId(3);
$customer->save();
Let me know in case of a query.
Thanks
@engcom-Hotel Saving the whole customer is a actually a much heavier process as it saves both the customer model and his address.
We have over 50k customers which need to be processed daily for group changes based on their order totals, so saving the whole customer including his address every single time is consuming a lot of resources especially memory-wise. Moreover the time of processing is much bigger like this.
That's why I'd prefer to use the saveAttribute function which should function correctly for group_id as well.
However it doesn't work.
Hello @ioweb-gr,
Thanks for the reply!
As we have a workaround for this issue and seems that the workaround is very heavy in terms of memory consumption I think we can mark this issue as a feature request.
Please suggest.
Thanks
How is it considered a workaround?
Saving two models instead of a single attribute is not a workaround in my opinion.
Even if you consider it so, the issue is still that saveAttribute function is not working as expected. It should be able to save the group id.
This is not a feature request, it's broken functionality.
saveAttribute is supposed to be able to save a single attribute correctly
Hello @ioweb-gr,
Thanks for your reply!
As per the discussion, we are not able to use the saveAttribute
method in order to save group_id
. Hence we are confirming this issue for further processing.
Thanks
:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-5894 is successfully created for this GitHub issue.
:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
@engcom-Hotel Let me add here that it's not possible to update static attributes for products either. I created a custom attribute which is static and is added as a table column in catalog_product_entity. I can update it just fine using $productRepository->save
or with $model->save
or $resourceModel->save($product)
However $resourceModel->saveAttribute()
won't work throwing an exception.
For example in my case
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'catalog_product_entity.value_id' in 'field list', query was: SELECT `catalog_product_entity`.`value_id`, `catalog_product_entity`.`value` FROM `catalog_product_entity` WHERE (attribute_id='838' AND entity_id='1209' AND store_id=1)
The same core issue is for every static attribute in all entities it seems and it's a general problem. When doing mass updates of products, you don't need to always save the whole product which is a very taxing operation just to update a single attribute.
Valid use cases where this might be needed.
ERP synchronization API synchronization Marketplaces synchronization Newsletter subscriber synchronization
All of them need to store a mapping id as a static field usually and saveAttribute should be usable in these cases and an eav attribute is not needed in such cases. A static field will perform better.
Preconditions and environment
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
Expected result
The customer group_id is changed
Actual result
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.Instead of using
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{}}}:
`` $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