Skip to content

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

Open
@abramchukm

Description

@abramchukm

Preconditions and environment

  • Magento 2.4.7 and all others including MCLOUD-10032 patch.
  • You should have at least one website and several stores attached to it.
  • You should have an attribute that should have a Website Scope.

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);
  1. 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:

protected function _updateAttribute($object, $attribute, $valueId, $value)

Instead of processing attributes using

protected function _saveAttributeValue($object, $attribute, $value)

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

  • 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

Labels

Area: CatalogComponent: 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: PR in progressReported on 2.4.xIndicates original Magento version for the Issue report.Reproduced 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