Skip to content

Commit

Permalink
Take care deleting variants products
Browse files Browse the repository at this point in the history
  • Loading branch information
sofia-doofinder committed Dec 17, 2024
1 parent 3385e29 commit f8c6286
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions Observer/Product/AbstractChangedProductObserver.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Doofinder_Feed" setup_version="1.0.2">
<module name="Doofinder_Feed" setup_version="1.0.3">
<sequence>
<module name="Magento_Integration" />
</sequence>
Expand Down

0 comments on commit f8c6286

Please sign in to comment.