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.56k stars 9.32k forks source link

Attribute getStoreLabel wrong behavior #37953

Open Nuranto opened 1 year ago

Nuranto commented 1 year ago

Preconditions and environment

Steps to reproduce

  1. Create any attribute, with a default label
  2. Set a different label for store id = X
  3. load attribute on admin area, and dump $attribute->getStoreLabel(X)

Expected result

Store label is dumped

Actual result

Default label is dumped

Additional information

The problem is quite obvious when watching the first method lines :

https://github.com/magento/magento2/blob/3cc15fbed80c1f75c77c7cfeeaaba3ca25fe81b8/app/code/Magento/Eav/Model/Entity/Attribute.php#L490-L495

A fix could be :

if (null === $storeId && $this->hasData('store_label')) { instead of if ($this->hasData('store_label')) {

But it's probably a bit more complicated than that, we probably want to use default value if store label is empty or not set

Workaround : $attribute->unsetData('store_label')->getStoreLabel($storeId);

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 year ago

Hi @Nuranto. 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 1 year 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 1 year ago

Hello @Nuranto,

Thank you for the report and collaboration!

We have tried to reproduce the issue on 2.4-develop. But we got the expected result. We have created a custom module to dump the storeLabel in the admin panel. Please take a loot at the screenshot below:

image image

It can be observed that we are getting the store label of the specific website. Please find the custom module and let us know if we are missing anything. LabelVendor.zip

Thank you.

Nuranto commented 1 year ago

What if you add another store, and you try to display the label of both stores ? Something like this in your block :

public function getLabel() {
        $this->attribute = $this->repository->get('test_attribute');
        var_dump($this->attribute->getStoreLabel(2));
        var_dump($this->attribute->getStoreLabel(3));
    }
engcom-November commented 1 year ago

Hello @Nuranto,

Thank you for the quick response.

We have taken your input and tried to reproduce the issue, still we are getting the expected result. Please take a look at the below screenshot:

image image

We are able to get the store label of the second store as well. Please verify if the issue is reproducible on your end, and let us know if we are missing aything.

Thank you.

Nuranto commented 1 year ago

Ok, I think I have the missing step.

In your block, load a product (of an attribute set that contains your test attribute) from product repository just before loading the attribute.

engcom-November commented 1 year ago

Hello @Nuranto,

Thank you for the quick response!

As your input we loaded the attribute form the product itself, and not from the attribute repository. And the issue is reproducible. Please take a look at the screenshot below:

image image

It can be seen that even though we are dumping store labels of 2 different storeID, we are still getting the default label.

Please find below the custom module used to reproduce the issue. LabelVendor.zip

Thank you.

github-jira-sync-bot commented 1 year ago

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

m2-assistant[bot] commented 1 year 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.

github-jira-sync-bot commented 1 year ago

:x: You don't have permission to export this issue.

Kiraberos commented 1 year ago

@magento I am working on this

engcom-November commented 10 months ago

Hello @Nuranto,

Re-verified this issue on 2.4-develop, issue is still present. We are still getting the default labels for all the store.

Thank you.

github-jira-sync-bot commented 10 months ago

:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-9631