magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.55k stars 9.32k forks source link

_updateAttribute function started to behave incorrectly when trying to update an attribute which is on a website scope. #38243

Open abramchukm opened 11 months ago

abramchukm commented 11 months ago

Preconditions and environment

Steps to reproduce

Let's assume that we have a website called test_website and 3 stores attached to it: be_store (with id 1), at_store (with id 2), uk_store (with id 3). Also, we have an attribute called show_discount which is a simple Yes/No in Catalog Input Type for Store Owner, and also it should be on a Website scope. To reproduce a bug, we should do the next:

  1. Load a product using the repository and specify any store ID of a website. (let it be the be_store with id 1 from the example).
    $product = $this->productRepository->get('some-product-sku', false, 1);
  2. Now I want to update my show_discount attribute value from 0 to 1 by using the next code piece:
    $product->addAttributeUpdate('show_discount', 1, $product->getStoreId());

Expected result

Because the attribute is managed on the Website scope, it should be updated for all store views attached to a website test_website, meaning that for all be_store, at_store, and uk_store stores, an attribute show_discount will be enabled. And have corresponding values in catalog_product_entity_int table.

Actual result

The attribute value was changed only for the be_store without taking into account the fact that the attribute is managed on the Website scope.

Additional information

Because of the change to the function, it started to behave incorrectly: https://github.com/magento/magento2/blob/7d724b79ddc8fb3704007cc1167f25f4c3b852da/app/code/Magento/Catalog/Model/ResourceModel/AbstractResource.php#L326

Instead of processing attributes using https://github.com/magento/magento2/blob/7d724b79ddc8fb3704007cc1167f25f4c3b852da/app/code/Magento/Catalog/Model/ResourceModel/AbstractResource.php#L186

And applying changes for attributes to Website in case it is on the website scope: https://github.com/magento/magento2/blob/7d724b79ddc8fb3704007cc1167f25f4c3b852da/app/code/Magento/Catalog/Model/ResourceModel/AbstractResource.php#L235C16-L235C16

We change it only for the one store, ignoring this crucial functionality https://github.com/magento/magento2/blob/7d724b79ddc8fb3704007cc1167f25f4c3b852da/app/code/Magento/Catalog/Model/ResourceModel/AbstractResource.php#L337C12-L337C12

Release note

No response

Triage and priority

m2-assistant[bot] commented 11 months ago

Hi @abramchukm. Thank you for your report. To speed up processing of this issue, 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:

m2-assistant[bot] commented 11 months ago

Hi @engcom-November. 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:

engcom-November commented 11 months ago

Hello @abramchukm,

Thank you for the report and collaboration!

We tried to reproduce this on magento 2.4-develop as well as 2.4.7-beta2, but in our case it is not reproducible. We followed the below steps:

Please take a look at the screenshot below:

image image

But when the value was set to 1 using the custom module, it was reflected in all the stores.

Please find the custom module used to reproduce this issue, and let us know if we are missing anything. ScopeVendor.zip

Thank you.

abramchukm commented 11 months ago

Hi @engcom-November,

Thanks for trying to reproduce it. I was a bit mistaken in my steps to reproduce. I've tried your extension on the first try and it worked perfectly (for all stores values were inserted properly, all of them were 1) because we've inserted a new value here https://github.com/magento/magento2/blob/7d724b79ddc8fb3704007cc1167f25f4c3b852da/app/code/Magento/Eav/Model/Entity/AbstractEntity.php#L1721C16-L1721C16. However if you will try to switch it back (try to update it to 0 for the same store), you will see where the problem lies. https://github.com/magento/magento2/blob/7d724b79ddc8fb3704007cc1167f25f4c3b852da/app/code/Magento/Eav/Model/Entity/AbstractEntity.php#L1723

For me the result after updating this attribute looked like this: image You can see that the value was updated only for one store for the attribute with ID 137.

I've reproduced it using a Magento 2.4.7-beta2 version.

Thank you.

engcom-November commented 11 months ago

Hello @abramchukm,

Thank you for the quick reply!

We were able to verify this issue on 2.4-develop, and also in 2.4.7-beta2. As you mentioned when changing the value back to 0, we were able to see that the value is changed in only one store and not in all the stores, even though the attribute has website scope.

Please take a look at the screenshot: After changing the attribute value back to 0

image

We can see that the value is changed for only one store.

Hence confirming this issue.

Thank you.

github-jira-sync-bot commented 11 months ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-10664 is successfully created for this GitHub issue.

m2-assistant[bot] commented 11 months ago

:white_check_mark: Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

vpodorozh commented 11 months ago

I can confirm that we have faced this issue on our project.

simsComputing commented 10 months ago

Hello,

I have worked on a PR. Though it is a first contribution and i can't understand why it won't pass the functional tests. I need a bit more time this week to investigate further. But if anyone amongst you has any inclue on wether the bugs are really related to my PR, please don't hesitate

Thanks,