Closed itaymesh closed 4 years ago
This is driving me crazy. Updating a product in the backend always saves attributes with store_id of 0 and then on the frontend it looks up attributes using store_id of 1. So the only way to update anything is to do so directly in the database. This is with single store mode enabled, which should mean that there should only be ONE store not two.
I have this issue as well. I fixed it with a hack but is something going to be done about this?
I can confirm that this is an issue for me too still. Magento 2.1.6
What kind of hack did you use? This is really a debilitating issue and the developers don't seem to care at all.
On Mar 27, 2017 2:24 PM, "leitot" notifications@github.com wrote:
I have this issue as well. I fixed it with a hack but is something going to be done about this?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/magento/magento2/issues/7720#issuecomment-289536701, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUf75koyoYhVYhjfucIs3xidcrCeJxHks5rp_uNgaJpZM4LHJ7x .
I wrote a before plugin for the save() method for the type Magento\Catalog\Model\ResourceModel\Product. Inside beforeSave() I set the store ID correctly on the product (after the ProductRepository's save() method messes it up)
Thanks, I'll give that a shot. I have the same problem with the category repository too.
On May 22, 2017 9:03 PM, "leitot" notifications@github.com wrote:
I wrote a before plugin for the save() method for the type Magento\Catalog\Model\ResourceModel\Product. Inside beforeSave() I set the store ID correctly on the product (after the ProductRepository's save() method messes it up)
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/magento/magento2/issues/7720#issuecomment-303269134, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUf75oBD3hoHTgjSLK6Qrr9hU7PmiZoks5r8j5bgaJpZM4LHJ7x .
I have this issue in CE 2.1.7.
The save method in the ProductRepository is incorrectly setting the store_id property on the product.
The fix is to check if the store_id is already set on the product, and if not, set it. Add the if-statement around the line below:
if (!isset($productDataArray['store_id'])) {
$productDataArray['store_id'] = (int)$this->storeManager->getStore()->getId();
}
@itaymesh, thank you for your report. We've created internal ticket(s) MAGETWO-83254 to track progress on the issue.
One could argue that this is not an issue but a feature: what Magento does: is when saving a product, it looks at the current store to determine where to save the attributes to. You could solve this by using emulation when using CLI:
/** @var \Magento\Store\Model\App\Emulation $this->emulation */
$this->emulation->startEnvironmentEmulation($product->getStoreId(), Area::AREA_ADMINHTML);
$this->productRepository->save($product);
$this->emulation->stopEnvironmentEmulation();
Wrapping your save()
-method between these 2 lines also fixes the issue. However, I do agree that re-saving a products saves attributes for all stores and unchecks the 'Use Default Value' is unintended behavior so it would still classify as a bug.
I'm not following the argument that this is a feature. The inner workings for saving a product are not intuitive and IMHO not correct: When I'm given the option of getting a product for a specific store, and I update that product, I would expect that a save operation would update that exact product (based on its store id).
If store emulation needs to be used, then the API would need to indicate this as well. Getting a product for a specific storeview via a parameter on the 'get' method should hence not be possible (which would be a pity).
Hi @itaymesh we have a Pull Request for this issue. We are testing the solution right now.
Hi @itaymesh. Thank you for your report. The issue has been fixed in magento-engcom/magento2ce#967 by @p-bystritsky in 2.2-develop branch Related commit(s):
The fix will be available with the upcoming 2.2.5 release.
I am on 2.2.2 and if I save a product from the backend the ProductRepository save method is not called at all. I see vendor/magento/module-catalog/Controller/Adminhtml/Product/Save.php is calling $product->save().
Am I missing something or how can this fix work for you @cherreman, @okorshenko?
@bpoiss Our context is that we are importing products from an external system. We use the ProductRepository to save the products in the code of our import script.
@cherreman thanks for your response. Do you have any idea how this issue can be fixed also for saving products via backend?
Still present on 2.2.6 EE adding new product from API using catalogProductRepository
This fix was never ported to 2.3 - why?
Hi @engcom-Charlie. 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:
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).Details
If the issue has a valid description, the label Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.
[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description
label to the issue by yourself.
[ ] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.4-develop
branchDetails
- Add the comment @magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
[ ] 5. Add label Issue: Confirmed
once verification is complete.
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
:white_check_mark: Confirmed by @engcom-Charlie
Thank you for verifying the issue. Based on the provided information internal tickets MC-30488
were created
Issue Available: @engcom-Charlie, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
Hi @engcom-Charlie. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:
[ ] 1. Add/Edit Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[ ] 2. Verify that the issue is reproducible on 2.4-develop
branchDetails
- Add the comment @magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
[ ] 3. If the issue is not relevant or is not reproducible any more, feel free to close it.
Hi @itaymesh. Thank you for your report. The issue has been fixed in magento/magento2#26470 by @engcom-Charlie in 2.4-develop branch Related commit(s):
The fix will be available with the upcoming 2.4.2 release.
Preconditions
Steps to reproduce
Expected result
Actual result
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.