MageSmith
Magento_Catalog · Magento 2.4.9

prepare_catalog_product_index_select

Magento 2 event dispatched from Magento_Catalog. Observers bound to this event run whenever the code path that dispatches it executes.

Dispatch location(s)

Every place in Magento 2 core where prepare_catalog_product_index_select is fired. Open the file in your local Magento source to see the event arguments passed alongside the name.

vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php line 210
vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php line 299
vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php line 396
vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/Decimal.php line 156
vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/DefaultPrice.php line 495
vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/Query/BaseFinalPrice.php line 239

Observer skeleton

Paste into your module's etc/events.xml + create the matching Observer class. Adjust the vendor/module namespace to yours.

1. etc/events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="prepare_catalog_product_index_select">
        <observer name="vendor_module_prepare_catalog_product_index_select"
                  instance="Vendor\Module\Observer\PrepareCatalogProductIndexSelect"/>
    </event>
</config>

2. Observer class

<?php
declare(strict_types=1);

namespace Vendor\Module\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class PrepareCatalogProductIndexSelect implements ObserverInterface
{
    public function execute(Observer $observer): void
    {
        $event = $observer->getEvent();

        // Read whatever payload this event carries. Check the
        // dispatch() call in core to see the exact keys.
        // Example: $product = $event->getProduct();

        // Your observer logic here.
    }
}

Need the full module scaffolded around this observer? Module Generator wires the events.xml, observer class, and module registration for you.

Every Magento dev tool, in one hosted workspace.

Free to sign up. Nothing to install. Drafts, audits, and projects saved across every tool.