Skip to content

Commit

Permalink
Don't index products with invalid visibility (#358)
Browse files Browse the repository at this point in the history
* Don't index products with invalid visibility

* updated version
  • Loading branch information
sofia-doofinder authored Nov 20, 2024
1 parent 06e9cbb commit 0b456a9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Observer/Product/AbstractChangedProductObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Doofinder\Feed\Model\ChangedItemFactory;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\Catalog\Model\Product\Visibility;
use \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
Expand Down Expand Up @@ -44,6 +45,11 @@ abstract class AbstractChangedProductObserver implements ObserverInterface
*/
private $configurableProductType;

/**
* @var []
*/
private $visibilityAllowed;

/**
* AbstractChangedProductObserver constructor.
*
Expand All @@ -65,6 +71,7 @@ public function __construct(
$this->changedItemRepository = $changedItemRepository;
$this->logger = $logger;
$this->configurableProductType = $configurableProductType;
$this->visibilityAllowed = [Visibility::VISIBILITY_IN_SEARCH, visibility::VISIBILITY_BOTH];
}

/**
Expand All @@ -79,6 +86,8 @@ public function execute(Observer $observer)

if ($product->getStatus() == Status::STATUS_DISABLED) {
$this->setOperationType(ChangedItemInterface::OPERATION_TYPE_DELETE);
} elseif (!in_array($product->getVisibility(), $this->visibilityAllowed)){
$this->setOperationType(ChangedItemInterface::OPERATION_TYPE_DELETE);
} elseif ($product->getUpdatedAt() == $product->getCreatedAt() &&
$operationType == ChangedItemInterface::OPERATION_TYPE_UPDATE
) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "doofinder/doofinder-magento2",
"version": "1.0.0",
"version": "1.0.1",
"description": "Doofinder module for Magento 2",
"type": "magento2-module",
"require": {
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
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.0">
<module name="Doofinder_Feed" setup_version="1.0.1">
<sequence>
<module name="Magento_Integration" />
</sequence>
Expand Down

0 comments on commit 0b456a9

Please sign in to comment.