diff --git a/vendor/magento/module-shared-catalog/Observer/DeleteImportProducts.php b/vendor/magento/module-shared-catalog/Observer/DeleteImportProducts.php new file mode 100644 index 000000000000..0d11d5e0dafb --- /dev/null +++ b/vendor/magento/module-shared-catalog/Observer/DeleteImportProducts.php @@ -0,0 +1,75 @@ +itemRepository = $itemRepository; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + } + + /** + * When products are deleted from the catalog through an import, clear shared catalog as well + * + * @param Observer $observer + * @return DeleteImportProducts + */ + public function execute(Observer $observer): static + { + $skus = []; + foreach ($observer->getEvent()->getData('bunch') as $product) { + if (isset($product['sku'])) { + $skus[] = $product['sku']; + } + } + $this->searchCriteriaBuilder + ->addFilter(ProductItemInterface::SKU, $skus, 'in'); + $searchCriteria = $this->searchCriteriaBuilder->create(); + + if ($items = $this->itemRepository->getList($searchCriteria)->getItems()) { + $this->itemRepository->deleteItems($items); + } + + return $this; + } +} diff --git a/vendor/magento/module-shared-catalog/etc/adminhtml/events.xml b/vendor/magento/module-shared-catalog/etc/adminhtml/events.xml index 67af14df7d3a..08684a58fbd0 100644 --- a/vendor/magento/module-shared-catalog/etc/adminhtml/events.xml +++ b/vendor/magento/module-shared-catalog/etc/adminhtml/events.xml @@ -12,4 +12,7 @@ + + +