Skip to content

Commit 9193cd2

Browse files
committed
MAGE-1083 Implement observer for mass action status change
1 parent 3fb2264 commit 9193cd2

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Model\Observer\Product;
4+
5+
use Algolia\AlgoliaSearch\Model\Cache\Product\IndexCollectionSize as Cache;
6+
use Magento\Framework\Event\ObserverInterface;
7+
use Magento\Framework\Event\Observer;
8+
9+
/**
10+
* Handle the `catalog_product_attribute_update_before` event.
11+
* Triggered via mass action "Change status" but not "Update attributes"
12+
*/
13+
class CacheCleanAttributeUpdate implements ObserverInterface
14+
{
15+
public function __construct(
16+
protected readonly Cache $cache
17+
) {}
18+
19+
public function execute(Observer $observer): void
20+
{
21+
$attributes = $observer->getData('attributes_data');
22+
$productIds = $observer->getData('product_ids');
23+
$attributesToObserve = ['status'];
24+
25+
if ($productIds
26+
&& array_intersect(array_keys($attributes), $attributesToObserve)) {
27+
$this->cache->clear();
28+
}
29+
}
30+
}
31+
32+
33+
34+

etc/events.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44
<observer name="algoliasearch_reindex_product_on_last_item_purchase_if_msi_disable"
55
instance="Algolia\AlgoliaSearch\Observer\ReindexProductOnLastItemPurchaseIfMsiDisable"/>
66
</event>
7+
8+
<event name="catalog_product_attribute_update_before">
9+
<observer name="clean_cache_on_mass_product_before" instance="Algolia\AlgoliaSearch\Model\Observer\Product\CacheCleanAttributeUpdate" />
10+
</event>
11+
712
</config>

0 commit comments

Comments
 (0)