-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating a product through the API removes its images #10461
Comments
What is the complete JSON string you are POSTing to the server? The problem you describe will happen if you are sending an empty array assigned to |
@jordanbrauer I'm not writing an empty value to the media gallery entries, I'm writing the same values as were on the product previously to the media gallery. |
I have a similar setup as you and I do not have this problem. 🤔 I am curious though - why are you resending the same images if they already exist on the product? That could be a potential contributor to the reason this is happening. The JSON object that you are POSTing to the API, what does it look like? For example, mine looks like this for our stock level & inventory status update script (ignore that it is PHP for now and pretend it was a JSON object), $json = [
'product' => [
'status' => $row->status,
'sku' => $row->sku,
'extension_attributes' => [
'stock_item' => [
'qty' => $row->qty,
'is_in_stock' => is_in_stock($row->qty),
],
],
],
'save_options' => true,
]; Notice that I am not including the If you believe it to be a store ID issue - I have a workaround for that that may or may not work for you. What I do is simply dispatch the request/operation again on the same set of products, except with a different e.g., Using the following as a template, Default Endpoint: Specific Endpoint: |
I should have mentioned, that we are using the PHP api rather than the json one, as we have our own web service for dealing with importing data. Anyway if I send a different set of images for a product update, the issue is the same. |
Ah I understand. My bad! As far as I know, you're still able to specify the store ID with the framework using, $product->setStoreId($store_id); So the workaround might work. The images thing is quite strange for sure. Is there ant chance your shop is able to upgrade to 2.1.5 > ? |
Well it's my bad really for not stating I was using the PHP api but thanks for spending the time to look into it. I could update to 2.1.5 but I have a linux VM version of Magento that is running version 2.2.0-dev and that has the same issue so I don't think it would make any difference. Oh yes I tried that setting the store id on the product - but on product save it still creates the store id 1 version of the product (as described in issue #7877 ). The workaround for that is to save the attribute value with a store id of 0 - I could maybe try that for the image type values - I didn't try that approach. I just thought I would raise the issue for anyone else struggling with the php api. |
Could this be investigated and raised as a bug if appropriate? |
We just have to wait until a Magento CE team member sees this and deems it worthy of being added to their internal tickets. Do you have any 3rd part extensions that alter products, images, and/or stores? |
It's this issue, I believe. |
I am sharing the workaround I have for this issue, for anyone who might find it helpful. There is also this workaround, mentioned on #10687
|
@CatherineLearmonth, thank you for your report. |
@CatherineLearmonth Can you please specify where the mentioned fix needs to be added? |
Saving the product is the thing that removes its images. If you're not changing the product image, use this fix: If you are updating the images, try the other code (in the txt file) but add it after the product save. |
@CatherineLearmonth Thanks for a quick response, but what we need is the specific location? Can you name a file or a class? something we could cling on.... |
I inserted the fix into a bespoke Magento module that I wrote that takes products from one system and writes them to Magento. I don't know where you would insert the code fix into the Magento code base itself if that is what you are looking for. |
You can look into Magento\Catalog\Model\ProductRepository DEBUG HER: if media_gallery in empty then, unset($productDataArray['media_gallery']); |
I had similar iussue. Solved it to set null value for json id property: |
I think its issue on Magento 2.2.3 or below version protected function processMediaGallery(ProductInterface $product, $mediaGalleryEntries) I have make this patched and its working for me. |
I'm having this issue in 2.3.3 - what is the recommended fix? |
Hi @engcom-Delta. Thank you for working on this issue.
|
Hi @merance2000 . Unfortunately, I cannot reproduce this issue on 2.4-develop. Case2:
Actual result: Could you add detailed steps to reproduce this issue in your case? |
@merance2000, we are closing this issue due to inactivity. If you'd like to update it, please reopen the issue. |
Preconditions
Steps to reproduce
Expected result
Actual result
Note: On product update, the value of the store id on table 'catalog_product_entity_media_gallery_value' is set to 1 (when previously it was set to 0). I believe this prevents the update being done to the catalog_product_entity_varchar table for the asset.
I have got round this issue by inserting a row to the varchar table for each asset type after a product save. The assets still exist on the media gallery tables, but are removed from the product varchar table, which prevents them from being displayed in the UI.
The text was updated successfully, but these errors were encountered: