Skip to content

Product Repository saves attribute values for existing product always on "Default Store Level" #7720

Closed
@itaymesh

Description

@itaymesh

Preconditions

  1. Magento 2.1.2
  2. PHP 7
  3. Mysql 5.6

Steps to reproduce

  1. Create a CLI command to create/update a production
  2. Execute the comment (new product)
  3. Execute the comment (update product)

Expected result

  1. New Product: values are saved on "All Store Views"
  2. Update Product: values are saved on "All Store Views"

Actual result

  1. New Product: values are saved on "All Store Views"
  2. Update Product: values are saved on "Default Store View"

Seems like the product repository class overrides the product store id and always assign default store id

app/code/Magento/Catalog/Model/ProductRepository.php#L530

$productDataArray['store_id'] = (int)$this->storeManager->getStore()->getId();

The only way to work around this issue is by getting the existing product with explicit parameter:
$product = $this->_productRepository->get($sku, true, 0);

and use the deprecated save method of Magento\Framework\Model\AbstractModel class at line 629.

Metadata

Metadata

Labels

Component: CatalogFixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.4.xThe issue has been fixed in 2.4-develop branchIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: doneReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchSeverity: S3Affects non-critical data or functionality and does not force users to employ a workaround.bug report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions