Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving product with non-default store scope causes untouched attributes to become store scoped if loaded using ProductRepository #8897

Closed
phirunson opened this issue Mar 16, 2017 · 54 comments
Assignees
Labels
Area: Product Component: Catalog Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S1 Affects critical data or functionality and forces users to employ a workaround. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@phirunson
Copy link

phirunson commented Mar 16, 2017

This is related to #7720 and #7879 and #9486

Preconditions

  1. Magento 2.4-develop

Steps to reproduce

  1. Create a simple product that belongs to multiple websites.
  2. In a script, change the current store to non-default store
  3. Load the product using the ProductRepository class
  4. Change an attribute value for the loaded product
  5. Save the product either using the ProductRepository class or calling $product->save() (deprecated)
$this->storeManager->setCurrentStore(2);
$product = $this->productRepository->getById(1, true, 2);
$product->setShortDescription('Setting short desc');
$this->productRepository->save($product); // or $product->save();

Expected result

  1. The value for short_description should be overridden, all other attributes should remain as Use default value

Actual result

  1. All store scoped eav attributes are overridden. Values other than short_description are copied over from the default store scope values.

You can see the results of this by checking the catalog_product_entity_text table and seeing that new values for not just short_description, but description and meta_keyword as well. Checking the catalog_product_entity_{varchar,int,decimal,etc} tables will also show new entries for store scope 2 even though none of that was modified.

Checking the how the admin backend handles this, it seems the Save controller requires passing in values for whether to use default values in a param use_default. (https://github.com/magento/magento2/blob/develop/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php#L171)
This makes it tightly coupled to the admin ui, and so it is hard to replicate proper save behaviour in code.

The use case is that products are being pushed externally via the Magento api, but this makes it so that doing store scoped save operations means anytime something is changed in default scope, it needs to also update in all store scopes independently rather than inheriting from default scope like it should.

@magento-engcom-team magento-engcom-team added G1 Passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed and removed G1 Passed labels Sep 5, 2017
@magento-engcom-team magento-engcom-team added Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed 2.1.x Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Oct 12, 2017
@magento-engcom-team
Copy link
Contributor

@phirunson, thank you for your report.
We've created internal ticket(s) MAGETWO-81741 to track progress on the issue.

@mustdobetter
Copy link
Contributor

mustdobetter commented Dec 18, 2017

This is also an issue when updating a product via the REST API in 2.1.19. When updating a product under a non-default store scope, all store scoped eav attributes are overridden, not just those that are being updated.

This seems to be a major bug, and so should be addressed in 2.1.x and 2.2.x, no?

@versdivers
Copy link

This is still an issue in CE 2.2.1. If you save a product programmaticly without touching the attributes that have a default value in that store it will save those attributes with the value from the default value and thus unsetting the 'use default value' check

@koenner01
Copy link
Contributor

koenner01 commented Jan 4, 2018

We are also having this problem in 2.2.2

@versdivers
Copy link

For the ones who have this issue. You will need to use the resourcemodel to post your own mysql queries to the database. No other solution that i have found

@koenner01
Copy link
Contributor

We are using the api to update to product data so what you are saying is that we should trash the api Magento provides and create our own calls...

@hws47a
Copy link
Contributor

hws47a commented Jan 24, 2018

I believe I have a related issue.
When creating a product with selected website id (non-single store mode) it saves attributes (at least some of them) on store view level even if it's a new product and there are no default values.

For varchar attributes you set, there will be values for selected store_id (related to a website) and admin one, for varchar attributes with default values like media_images there will only be "no_selection" on a store level.

So if you later upload an image on admin side on default scope, an image will not appear. One more problem is that you'll have to upload the image again on store view level because there is no "use default scope" checkbox in the images section.

@koenner01
Copy link
Contributor

snippet of the wall of text from our cloud support ticket:

  1. Setup a clean 2.2.2 installation

  2. Create a new (extra) storeview:
    => Store='Main Website Store'
    => Name='Some Random Storeview'
    => Code='random'
    => Status='Enabled'
    => Sort Order='0'

  3. Make sure the shop is using flat tables
    => Stores > Configuration > Catalog > Catalog > Storefront > Use Flat Catalog Category = Yes
    => Stores > Configuration > Catalog > Catalog > Storefront > Use Flat Catalog Product = Yes

  4. Create a simple product and save it
    => Fill in all required attributes with random stuff
    => Fill in all fields with storeview/website scope in all the closed tabs
    => Make sure to add 2 random images and set the 1th as base/small_image/thumbnail/swatch

  5. Take note of the values in the database:

  • catalog_product_entity_int
  • catalog_product_entity_text
  • catalog_product_entity_text

Break stuff through the backend:

  1. Switch the storeview to our newly created 'random' storeview
    => Don't change any data AND DON'T OPEN ANY TABS

  2. Save the product on storeview scope
    => If you look at the closed tabs after the product save reloaded the page, you will see that the 'use default value' checkboxes have all been unchecked

  3. Take note of the values in:

  • catalog_product_entity_int
  • catalog_product_entity_text
  • catalog_product_entity_text
    => All attributes from the closed tabs that have storeview/website scope have just had a value saved to the database
  1. Switch back to the 'All store views' scope

  2. Change all product attributes that have scope storeview or website with new values and save the product
    => Make sure to select the 2th image as base/small_image/thumbnail/swatch!
    => Make sure to change the meta_title, meta_keywords and meta_description

  3. Take note of the values in:

  • catalog_product_entity_int
  • catalog_product_entity_text
  • catalog_product_entity_text
    => The values with store_id 0 will contain the correct value
    => values saved to the database for our new storeview during step 7 are incorrect
  1. Look at the frontend where the product is using the incorrect data on our 'random' storeview
    => the image used as base/small_image/thumbail/swatch is wrong
    => the meta data in the header is wrong

The problem can be split into multiple origins:

  • Part of the problem lies with the fact that closed tabs will uncheck all 'use default value' checkboxes. This causes discrepancies between values on storeviews because (unwanted) values are being saved to the database.
    You cannot assume that a user will open all tabs when he is editting a product, just to make sure the 'use default value' checkboxes get saved properly

  • Another part of the problem is the fact that for images there is no 'use default value' option. This will cause problems on the frontend when the user assumes the value of default is being used, while actually an incorrectly saved value is being used.

Break stuff through the api:

  1. Update the product's name through the api:
    => PUT '../rest/{OurRandomStoreviewCode}/V1/products/{createdProductSku}
    => request body: {"product":{"name":"Test API"}}

  2. Take note of the values in:

  • catalog_product_entity_int
  • catalog_product_entity_text
  • catalog_product_entity_text
    => Besides the product's name being updated on the storeview, the database tables got filled with unwanted values for attributes that have scope storeview/website

I can't even wrap my head around this problem.
We are updating 1 attribute but the database is being filled with a lot of other (unwanted) values. If we now check the product through the adminhtml the same behaviour as the closed tabs was reproduced. All attributes in the closed tabs have had their 'use default value' checkbox unchecked...

@engcom-Hotel
Copy link
Contributor

Hello,

Tried to reproduce the issue in the latest 2.4-develop branch by making a custom module. But it seems the issue is not reproducible for us. Please have a look at the below screenshot for reference:

Before Updates:
image

After Updates:
image

We are also attaching the module for reference:

Magz.zip

Please let us know if we have missed anything.

Thanks

@engcom-Hotel engcom-Hotel added the Issue: needs update Additional information is require, waiting for response label Feb 28, 2023
@MarianNapi
Copy link

Hey @engcom-Hotel

Please take a look at your second screenshot. As you can see every single "Use Default Value" option is deselected.
This means that for example Product Name, Tax Class and so on now use a custom scope value instead of the default scope.

@t-heuser
Copy link

Hey @engcom-Hotel

Please take a look at your second screenshot. As you can see every single "Use Default Value" option is deselected. This means that for example Product Name, Tax Class and so on now use a custom scope value instead of the default scope.

Which proofs that the issue is still reproducible in the latest 2.4-develop branch.

@engcom-Hotel
Copy link
Contributor

Hello @MarianNapi @oneserv-heuser,

I agree with you. Hence confirming this issue.

Thanks

@engcom-Hotel engcom-Hotel added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch and removed Issue: needs update Additional information is require, waiting for response labels Mar 1, 2023
@github-jira-sync-bot
Copy link

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

@convenient
Copy link
Contributor

What commits relate to this being completed?

@ihor-sviziev
Copy link
Contributor

Looks like related changes are ed33a4e (found by ticket id that was mentioned in #8897 (comment)), but would be great to confirm it

@ThijsdejongSNC
Copy link

Pretty crazy that this big bug is not fixed yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Product Component: Catalog Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S1 Affects critical data or functionality and forces users to employ a workaround. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Development

Successfully merging a pull request may close this issue.