Saving a configurable product while the product editor is not fully initialized destroys the connection to its child products and turns the configurable product into a simple product.
Before

After

We could reproduce the bug under the following conditions:
Magento 2 Backend > Products > Catalog > Filter [Type = Configurable] > Edit (e.g. Hero Hoodie (MH07))Here is a short video of the steps above: https://youtu.be/ShBcU_-LQHA

The example might seem a bit contrived but we experienced this issue many times in our production environment.
Magento should not take the data sent by the client as the single source of truth. If the product relations have not been updated, Magento should not remove them if they are missing in the request sent by the client. Or the JavaScript should prevent save requests if the product model is not fully initialized.
As a quick fix we have added a check to the method that prevents the save if the product does not have any configurable products. For the Community Edition could look something like this (see: Magento\Catalog\Controller\Adminhtml\Product\Save::execute):
class Save extends \Magento\Catalog\Controller\Adminhtml\Product
{
public function execute()
{
...
$product = $this->initializationHelper->initialize(
$this->productBuilder->build($this->getRequest())
);
if ($this->isConfigurableWithoutProductLinks($product)) {
throw new \Exception("A second save request with missing product relations was detected");
}
...
}
private function isConfigurableWithoutProductLinks(\Magento\Catalog\Model\Product $product): bool
{
if ($product->getTypeId() !== 'configurable') {
return false;
}
/** @var \Magento\Catalog\Api\Data\ProductExtension $extensionAttributes */
$extensionAttributes = $product->getExtensionAttributes();
if (empty($extensionAttributes)) {
return false;
}
$configurableProductLinks = $extensionAttributes->getConfigurableProductLinks();
if (!empty($configurableProductLinks)) {
return false;
}
return true;
}
}
But it would be nice if you could find a more elegant way to prevent this whole class of errors.
If you watch the catalog/product/save/id/ requests sent by Magento with your browser's network console or with Fiddler you can see the impartial save request body that destroys the configurable product:
save-request-1.txt compared to save-request-2.txt

Magento saves the data sent by the client without checking the integrity of the data and clears all attributes that are missing the request body.
New to Magento and having this issue. Does the code you have posted under expected result give you the expected outcome? If so, where would I put it in CE 2.1.2 so that it doesn't get written over?
Have you had any more insight into this issue? Currently experiencing it on servers running Apache and PHP5.6.
Same behavior in 2.1.3 CE , Apache + PHP7, but it seems to affect only some backoffice users ( the role is the same ). Tested with the same "affected-user" using different devices/browsers.
I have encountered this issue when dealing with custom and standard product attributes, if an error is thrown then the product association can get lost.
I have raised this with EE support team and provided replication steps but for openness I am going to post the issue here as well as it is a really bad bug.
In order to work around the datetime issue we are creating separate date and time attributes in order to be able to set the the time on a datetime product attribute.
The new time attribute (static, custom backend model) has to do some validation to make sure the content team use the correct time format, "HH:MM". The class extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend like many other core backend product models.
This throws a \Magento\Framework\Exception\LocalizedException if there are any issues.
All good so far the functionality is working as intended, an error message is presented if incorrectly used.
The issue happens after an error message is presented, which is then fixed allowing the product to be successfully saved. All product variants of the configurable product are lost and now the product is a simple product.
I used a fresh install of Magento to replicate this issue using the Docker DevBox (Beta) installing a fresh copy of EE 2.1.3 with sample data using Redis and Varnish.
It is possible to replicate this issue by following these steps:
I have tested and confirmed this issue in our native Magento EE version 2.1.3. This issue has not been reported by an EE merchant and there is currently no available fix or workaround other than generating a product CSV prior to making changes for a product to ensure that if the error occurs, you can reassign the lost products via a CSV import.
This seems to be caused by /vendor/magento/module-configurable-product/view/adminhtml/web/js/variations/variations.js line 306 and 309:
delete this.source.data["configurable-matrix"];
delete this.source.data["associated_product_ids"];
Removing/commenting these lines solves this issue. The next question: What does this solution break?
We are an EE merchant and we are putting in a ticket with EE support as we are having this exact issue.
I will update once I've heard back from Magento support.
@ImFastTom I've had 9 updates of the following, hopefully you get more out of them than me:
I am again reaching out to provide you with a weekly update on the status of this issue and the escalation ticket. Our developers are still working to resolve this issue and have not yet provided any new information. Due to the complex nature of the Magento software, we are unable to provide you with an ETA or an expected release version that will correct this issue. I am constantly monitoring the escalation ticket and will keep you updated as this issue progresses through the investigation and development processes.
I thank you for your patience and understanding.
Thanks for letting me know @jzahedieh I'll let you know if i get any more info.
Running into the same issue after configuring UPC attribute having a unique value configuration. Our setup consists of:
Facing the same on
Magento CE 2.1.3
PHP 7.0.17
Zend Engine v3.0.0
Nexces Hosting Server
Chrome, FireFox, Safar & IE
@andreaskoch, , Thanks for reporting this issue.
We've created internal ticket MAGETWO-69704 to address this issue.
I am facing the same issue in 2.1.6. It is very frustrating and costing us a lot of time :( . I am already regreting to update to M2.
We have created a composer patch which comments line 306 and 309 in /vendor/magento/module-configurable-product/view/adminhtml/web/js/variations/variations.js after deployment.
This solves the issue for us and we have not found any downsides of this solution the last month.
@schakenraadjuh Can you please share the file with me, as I can't update my installation with composer.
@altafhussain10 Attached the patch I use. If you do not use deployment / composer you can always comment the mentioned lines manually, but keep in mind they wil be overwritten when updating.
Patch-Magento_Configurable-loosing-simples-after-double-save.txt
Reproduced on 2.1.7 running apache with PHP 7. Mentioned patch fixes the problem.
Facing the same issue after save configurable products. Our setup consists of:
Magento 2.1.7 CE
PHP 7.0.19
chrome and firefox browser.
Reproduced on 2.1.8. Mentioned patch doesn't seem to fix the issue.
@andreaskoch, thank you for your report.
The issue is already fixed in 2.2.0
Hi,
Is there any fix for issue? I am also facing similar issue if there is any validation error for required field thrown for configuration product and then save the product all the associated child product get lost.
Magento 2.1.9 CE
PHP 7.0.19
chrome browser.
Note we have a Magento CE 2.3.2 customer and they still get this issue. Whether it makes any difference, but they were a M1.9 migration.