Description
This is related to #7720 and #7879 and #9486
Preconditions
- Magento 2.4-develop
Steps to reproduce
- Create a simple product that belongs to multiple websites.
- In a script, change the current store to non-default store
- Load the product using the ProductRepository class
- Change an attribute value for the loaded product
- 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
- The value for
short_description
should be overridden, all other attributes should remain as Use default value
Actual result
- 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.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status