Skip to content

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

Closed
@phirunson

Description

@phirunson

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.

Metadata

Metadata

Assignees

Labels

Area: ProductComponent: CatalogIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P1Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing.Progress: doneReported 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 branchSeverity: S1Affects critical data or functionality and forces users to employ a workaround.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions