diff --git a/vendor/magento/module-admin-gws-configurable-product/Plugin/ConfigurableResourcePlugin.php b/vendor/magento/module-admin-gws-configurable-product/Plugin/ConfigurableResourcePlugin.php new file mode 100644 index 000000000000..94970a2eb9fd --- /dev/null +++ b/vendor/magento/module-admin-gws-configurable-product/Plugin/ConfigurableResourcePlugin.php @@ -0,0 +1,96 @@ +role->getIsAll()) { + return [$mainProduct, $productIds]; + } + + if (!$mainProduct->getId()) { + return [$mainProduct, $productIds]; + } + + try { + $allExistingChildIds = $subject->getChildrenIds($mainProduct->getId()); + + if (empty($allExistingChildIds)) { + return [$mainProduct, $productIds]; + } + + $allExistingChildIds = $allExistingChildIds[0] ?? []; + + $childProductsOutsideScope = []; + foreach ($allExistingChildIds as $childId) { + try { + $this->productRepository->getById($childId); + } catch (\Exception $e) { + $childProductsOutsideScope[] = $childId; + } + } + + if (!empty($childProductsOutsideScope)) { + $productIds = array_unique(array_merge($productIds, $childProductsOutsideScope)); + } + } catch (\Exception $e) { + $this->logger->error(sprintf( + 'Error preserving configurable product children: %s', + $e->getMessage() + )); + } + + return [$mainProduct, $productIds]; + } +} diff --git a/vendor/magento/module-admin-gws-configurable-product/etc/adminhtml/di.xml b/vendor/magento/module-admin-gws-configurable-product/etc/adminhtml/di.xml index 763eeff48a22..cca6bd663547 100644 --- a/vendor/magento/module-admin-gws-configurable-product/etc/adminhtml/di.xml +++ b/vendor/magento/module-admin-gws-configurable-product/etc/adminhtml/di.xml @@ -9,4 +9,7 @@ + + + diff --git a/vendor/magento/module-admin-gws-configurable-product/etc/module.xml b/vendor/magento/module-admin-gws-configurable-product/etc/module.xml index 1c0bcb3c896d..a3585e6d424a 100644 --- a/vendor/magento/module-admin-gws-configurable-product/etc/module.xml +++ b/vendor/magento/module-admin-gws-configurable-product/etc/module.xml @@ -7,4 +7,11 @@ --> + + + + + + +