Closed phirunson closed 11 months ago
@phirunson, thank you for your report. We've created internal ticket(s) MAGETWO-81741 to track progress on the issue.
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?
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
We are also having this problem in 2.2.2
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
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...
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.
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:
6) Switch the storeview to our newly created 'random' storeview => Don't change any data AND DON'T OPEN ANY TABS
8) 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
9) Take note of the values in:
10) Switch back to the 'All store views' scope
11) 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
12) Take note of the values in:
13) 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.
6) Update the product's name through the api: => PUT '../rest/{OurRandomStoreviewCode}/V1/products/{createdProductSku} => request body: {"product":{"name":"Test API"}}
7) Take note of the values in:
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...
This is still an issue in 2.2.4
The product attributes are solved by using the emulation to set your script to admin store id 0
use Magento\Store\Model\App\Emulation;
use Magento\Framework\App\Area;
public function __construct(
FilterFactory $filter,
Emulation $emulation
)
{
$this->filter = $filter;
$this->emulation = $emulation;
}
.....
$this->emulation->startEnvironmentEmulation(0,Area::AREA_ADMINHTML);
$productrep->save($product);
$this->emulation->stopEnvironmentEmulation();
....
Still an issue on last Magento 2 version.
Same in 2.2.5.
we are running in single store mode and creating products from the configurable products and several seemingly random attribute values are getting filled.
Hi, is there any news about this? seems quite concerning has been reproduced on 2.1, 2.2, 2.3 but still no update.
I am also having same problem. This is happening when product is updated via api on all store view in product admin grid it is showing old image though I have uploaded new image when I delete image from cache it start showing me placeholder image instead of image I have set base,small, thumbnail on all store view but it is working fine for store image.
I randomly get data from other products of other store views getting copied into wrong products. Does anyone else see this weird behavior?
On Wed, Jan 30, 2019 at 7:40 AM irehmankhan notifications@github.com wrote:
I am also having same problem. This is happening when product is updated via api on all store view in product admin grid it is showing old image though I have uploaded new image when I delete image from cache it start showing me placeholder image instead of image I have set base,small, thumbnail on all store view but it is working fine for store image.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/magento/magento2/issues/8897#issuecomment-458929511, or mute the thread https://github.com/notifications/unsubscribe-auth/ACQbJYNsla6LxQJsMgWvm6YF2tQbOKRkks5vIZLIgaJpZM4Me0lk .
Still happening on EE2.2.6
Still seeing this issue in 2.1.16. Any updates?
Also - there is sample code above by @versdivers using EnvironmentEmulation. Does this work and is there documentation anywhere that describes how EnvironmentEmulation works?
@abrittis I can confirm that it works since we use it for a very big synchronization module with Exact Online for our customers. But except from some forums i did not find any documentation on it no (This is the new account of @versdivers )
We're encountering the same issue here on 2.2.8 Commerce.
We have a process running that should update an attribute if some criteria are met on a store scope basis, once we save the product in this process (CRON) all attributes get overwritten with the attributes of the default scope.
The hotfix @CompactCodeEU proposed didn't work for this and the problem still persists.
Also reproduced in Magento 2.3.0 and 2.3.1. If a product is edited in the backend in a specific store view, the images are saved store specific. This store specific setting for the images cannot be removed, as there are no "Use Default Value" checkboxes at the images.
Experience in 2.3.1, load product using product repository & on save it added store_view_code as default. on export it duplicate row with just value dded store_view_code = default
Hi @engcom-Alfa. 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.
@engcom-Alfa Thank you for verifying the issue.
Unfortunately, not enough information was provided to acknowledge ticket. Please consider adding the following:
"Component: "
label(s) to this ticket based on verification result. If uncertain, you may follow the best guessOnce all required information is added, please add label "Issue: Confirmed"
again.
Thanks!
:white_check_mark: Confirmed by @engcom-Alfa
Thank you for verifying the issue. Based on the provided information internal tickets MC-30077
were created
Issue Available: @engcom-Alfa, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
Please assign that to me, I am going to fix the issue.
I tried to reproduce the issue on other Entities to make sure if it's global issue of EAV mechanism or just related to products.
Hey, guys, I was having similar issue using Magento API to create products on M2 2.3.4. Calling /V1/products with website_ids: [1] element or leaving it empty and adding websites using /V1/products/{sku}/websites was resulting on having specific non default values to stores inside the associated website.
I've work around this by creating a plugin on Magento\Catalog\Model\ProductWebsiteLinkRepository::save method like below. Hope it helps someone until we have an official resolution from Magento. If you're having similar issue on another part of the code, consider using ProductWebsiteLinkRepository instead of set website_ids directly to product.
class ProductWebsiteLinkRepository
{
/**
* @var ProductWebsiteResourceModel
*/
protected $productWebsiteResourceModel;
/**
* @var ProductRepositoryInterface
*/
protected $productRepository;
/**
* ProductWebsiteLinkRepository constructor.
* @param ProductWebsiteResourceModel $productWebsiteResourceModel
* @param ProductRepositoryInterface $productRepository
*/
public function __construct(
ProductWebsiteResourceModel $productWebsiteResourceModel,
ProductRepositoryInterface $productRepository
) {
$this->productWebsiteResourceModel = $productWebsiteResourceModel;
$this->productRepository = $productRepository;
}
/**
* @param MagentoProductWebsiteLinkRepository $subject
* @param callable $proceed
* @param ProductWebsiteLinkInterface $productWebsiteLink
* @return bool
* @throws CouldNotSaveException
* @throws InputException
*/
public function aroundSave(
MagentoProductWebsiteLinkRepository $subject,
callable $proceed,
ProductWebsiteLinkInterface $productWebsiteLink
) {
if (!$productWebsiteLink->getWebsiteId()) {
throw new InputException(__('There are not websites for assign to product'));
}
try {
$product = $this->productRepository->get($productWebsiteLink->getSku());
$websitesIds = array_merge($product->getWebsiteIds(), [$productWebsiteLink->getWebsiteId()]);
$this->productWebsiteResourceModel->addProducts($websitesIds, [$product->getId()]);
} catch (\Exception $e) {
throw new CouldNotSaveException(
__(
'Could not assign product "%1" to websites "%2"',
$product->getId(),
$productWebsiteLink->getWebsiteId()
),
$e
);
}
return true;
}
}
So in the meantime should I just send two API requests to save product data using the Rest API? One to all and one to default? (Admin and Default values get out of sync)
Can someone please explain why are there two store views/copies of same data all over the show in the EAV/DB? As I do not understand why there is an Admin and a Frontend store id when website has the single store/site enabled.
So saving has been bugged since at least 2016 or earlier? How can we get an update on the status of MAGETWO-81741 fix?
This also impacts the bulk api... even when using all/ it adds store id 1 when my site is single store. How frustrating, so I can't use the bulk api.
This is the same in the Category Repository. Having store admin is_active set to 1 and other stores is_active not set (use default)
running foreach store
$this->getContext()->getStoreManager()->setCurrentStore($store);
/** @var Category $category */
$category = $this->_categoryRepository->get($entity->getId(), $store->getId());
// some changes (but not is_active flag)
try {
$this->_categoryRepository->save($category);
} catch (\Exception $e) {
}
you end up having set is_active to all stores explizit
when you have 17 stores like us than you have 18 times is_active = 1 in DB even though one would be enough.
It's 2022, and we are still having this issue with both categories and products especially when updating using the REST APi.
:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-2904 is successfully created for this GitHub issue.
:white_check_mark: Confirmed by @sidolov. Thank you for verifying the issue.
Issue Available: @sidolov, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
Where is this done 👀 what commit?
I do not see a commit. How is this done?
@sidolov @sivaschenko any related commits?
This issue was marked as "Not a bug", here is why: For REST API or for the case described here, the \Magento\Catalog\Api\ProductRepositoryInterface::save will take the action.
Implementation of \Magento\Catalog\Api\ProductRepositoryInterface::save loads Product Entity by ID according to the provided store, populates product attributes with new values, and saves the whole Product Entity in the scope of the current store.
The whole product is saved in the current scope, not regarding if some attributes had values in this scope before or not.
The solution is to set NULL values for attributes for which you want to preserve inheritance. I've tested that it helps in 2.4-develop.
I'm pretty confident that just describes the bug as it was raised years ago.
Using the API to update a single attribute of a product in a store view, it is expected that you have to list every attribute for the product and mark them as null so they fall back? That's what is being said now?
I guess you need to know which attributes are store view level as well, because if you use attributes that are default, or website, these will get overwritten on these levels as well.
We also have the issue, bloated up our whole database 3x its size as we have 3 stores and cronjobs that touched a lot of products and used the save() function. Very neat. As I understand right, a workaround until this is fixed, is to either set all attribute values you dont want to change to null or, if you're not using the REST-Api, to use the addAttributeUpdate() function from the Product Model, which saves a specific attribute value for a specific store.
But the problem I see here is that the save() function triggers SaveHandlers, a cache clean for the saved product and reindexing for the product (just a problem if the indexes are set to update on save and not update on schedule, as update on schedule works with database triggers). Am I missing something if I say the addAttributeUpdate() function, which directly saves the value to the database, doesn't do anything of the above?
And please someone reopen this issue or show us the related commit.
@abukatar @sidolov @sdzhepa any comments?
@abukatar @sidolov @sdzhepa I'm still facing the same issue. Any update?
Re-opened for confirmation if this issue was fixed or not because the bot has closed the issue in https://github.com/magento/magento2/issues/8897#event-6518708220 /CC @ishakhsuvarov
Hey @ihor-sviziev Please dont forget https://github.com/magento/magento2/issues/14622 This issue also still exists
Hi @engcom-November. 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:
Area: XXXXX
label to the ticket, indicating the functional areas it may be related to.2.4-develop
branch@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure. 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.Issue: Confirmed
once verification is complete. Hi @engcom-Hotel. 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:
Area: XXXXX
label to the ticket, indicating the functional areas it may be related to.2.4-develop
branch@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure. 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.Issue: Confirmed
once verification is complete. 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:
After Updates:
We are also attaching the module for reference:
Please let us know if we have missed anything.
Thanks
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.
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.
Hello @MarianNapi @oneserv-heuser,
I agree with you. Hence confirming this issue.
Thanks
This is related to #7720 and #7879 and #9486
Preconditions
Steps to reproduce
Expected result
short_description
should be overridden, all other attributes should remain as Use default valueActual result
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 justshort_description
, butdescription
andmeta_keyword
as well. Checking thecatalog_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.