From f8c6286f14812db612726f36fe6ffd2141696d70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sof=C3=ADa=20Moreno?= Date: Tue, 17 Dec 2024 19:22:05 +0100 Subject: [PATCH] Take care deleting variants products --- Observer/Product/AbstractChangedProductObserver.php | 9 +++++---- composer.json | 2 +- etc/module.xml | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) mode change 100644 => 100755 Observer/Product/AbstractChangedProductObserver.php mode change 100644 => 100755 composer.json mode change 100644 => 100755 etc/module.xml diff --git a/Observer/Product/AbstractChangedProductObserver.php b/Observer/Product/AbstractChangedProductObserver.php old mode 100644 new mode 100755 index b809f44..ee0c12b --- a/Observer/Product/AbstractChangedProductObserver.php +++ b/Observer/Product/AbstractChangedProductObserver.php @@ -83,10 +83,11 @@ public function execute(Observer $observer) try { $product = $observer->getEvent()->getProduct(); $operationType = $this->getOperationType(); - + $parentProducts = $this->configurableProductType->getParentIdsByChild($product->getId()); + if ($product->getStatus() == Status::STATUS_DISABLED) { $this->setOperationType(ChangedItemInterface::OPERATION_TYPE_DELETE); - } elseif (!in_array($product->getVisibility(), $this->visibilityAllowed)){ + } elseif (!in_array($product->getVisibility(), $this->visibilityAllowed) && count($parentProducts) == 0){ $this->setOperationType(ChangedItemInterface::OPERATION_TYPE_DELETE); } elseif ($product->getUpdatedAt() == $product->getCreatedAt() && $operationType == ChangedItemInterface::OPERATION_TYPE_UPDATE @@ -99,7 +100,7 @@ public function execute(Observer $observer) } if ($product->getStore()->getId() == 0 || - $this->getOperationType() == ChangedItemInterface::OPERATION_TYPE_DELETE + $operationType == ChangedItemInterface::OPERATION_TYPE_DELETE ) { foreach ($this->storeConfig->getAllStores() as $store) { $this->registerChangedItemStore($product, (int)$store->getId()); @@ -126,7 +127,7 @@ protected function registerChangedItemStore(ProductInterface $product, int $stor $itemsToInsert = [$itemId]; $parentProducts = $this->configurableProductType->getParentIdsByChild($itemId); - if (count($parentProducts) > 0) { + if (count($parentProducts) > 0 && $this->getOperationType() != ChangedItemInterface::OPERATION_TYPE_DELETE) { /* When updating a product it's children are also updated, so in this case we include the parentId but don't need to specify the itemId */ $itemsToInsert = $parentProducts; } diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 index 29e4d0b..d71dc8c --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "doofinder/doofinder-magento2", - "version": "1.0.2", + "version": "1.0.3", "description": "Doofinder module for Magento 2", "type": "magento2-module", "require": { diff --git a/etc/module.xml b/etc/module.xml old mode 100644 new mode 100755 index e9fc171..71357d2 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - +