Modify index settings
To change index settings before sending them to Algolia, use the{ENTITY}_index_before_set_settings event.
| Entity | Event |
|---|---|
| Products | algolia_products_index_before_set_settings |
| Categories | algolia_categories_index_before_set_settings |
| Pages | algolia_pages_index_before_set_settings |
| Suggestions | algolia_suggestions_index_before_set_settings |
| Additional sections | algolia_additional_sections_index_before_set_settings |
PHP
PHP
Update attribute data
To change entity data before indexing, use thealgolia_after_create_{ENTITY}_object events.
| Entity | Event |
|---|---|
| products | algolia_after_create_product_object |
| categories | algolia_after_create_category_object |
| pages | algolia_after_create_page_object |
| suggestions | algolia_after_create_suggestion_object |
getObject() method of the entity Helper class.
For example, in \Algolia\AlgoliaSearch\Helper\Entity\ProductHelper::getObject() this event is dispatched just before the object is returned for indexing:
PHP
created_at attribute from the default MySQL date format to a timestamp:
PHP
Modify product data
Use thealgolia_after_create_product_object event to change the product data sent to Algolia.
If you need access to specific attributes that aren’t available in the collection data,
request them from the product collection with the algolia_after_products_collection_build event.
The product data used for indexing is from a product collection request.
The full product model isn’t available during the object creation method.
This applies for categories and suggestions indexing as well.
They have their own algolia_after_{ENTITY}_collection_build events where you can access the collection.
The product collection is created by the
\Algolia\AlgoliaSearch\Helper\Entity\ProductHelper::getProductCollectionQuery() method.
This method dispatches the algolia_after_products_collection_build event, which lets you access the $collection object:
PHP
PHP
algolia_after_create_product_object event:
PHP
Modify the frontend configuration
To let the frontend display the configured UI, the Algolia extension creates thealgoliaConfig JavaScript variable by retrieving the configuration from a class.
You can change the algoliaConfig object before the page loads by using the algolia_after_create_configuration event.
This event is dispatched at the end of \Algolia\AlgoliaSearch\Block\Configuration::getConfiguration():
PHP
DataObject so that you can make changes in your observer using getters and setters:
PHP
List of product events
Dispatched before sending products index settings to Algolia
algolia_products_index_before_set_settings
Parameters:
$storeId$index_settingsas data inMagento\Framework\DataObjectobject (modifiable)
Dispatched after products collection creation
algolia_after_products_collection_build
Parameters:
$storeId$collectionasMagento\Catalog\Model\ResourceModel\Product\Collection(modifiable)$only_visible$include_not_visible_individually
Dispatched before final products collection load
algolia_before_products_collection_load
Parameters:
$collectionasMagento\Catalog\Model\ResourceModel\Product\Collection(modifiable)$store
Dispatched before fetching product attributes for indexing
algolia_product_index_before
Parameters:
$productasMagento\Catalog\Model\Product$custom_dataas data inMagento\Framework\DataObjectobject (modifiable)
Dispatched after fetching product’s attributes for indexing
algolia_after_create_product_object
Parameters:
$custom_dataas data inMagento\Framework\DataObjectobject (modifiable)$subProductsas array of sub products$productObjectasMagento\Catalog\Model\Product
List of category events
Dispatched before pushing categories index settings to Algolia
algolia_categories_index_before_set_settings
Parameters:
$storeId$index_settingsas data inMagento\Framework\DataObjectobject (modifiable)
Dispatched after categories collection creation
algolia_after_categories_collection_build
Parameters:
$store$collectionasMagento\Catalog\Model\ResourceModel\Category\Collection(modifiable)
Dispatched before fetching category attributes for indexing
algolia_category_index_before
Parameters:
$categoryasMagento\Catalog\Model\Category$custom_dataas data inMagento\Framework\DataObjectobject (modifiable)
Dispatched after fetching category attributes for indexing
algolia_after_create_category_object
Parameters:
$categoryasMagento\Catalog\Model\Category$categoryObjectas data inMagento\Framework\DataObjectobject (modifiable)
List of page events
Dispatched before pushing pages index settings to Algolia
algolia_pages_index_before_set_settings
Parameters:
$store_id$index_settingsas data inMagento\Framework\DataObjectobject (modifiable)
Dispatched after fetching page attributes for indexing
algolia_after_create_page_object
Parameters:
$pageas data inMagento\Framework\DataObjectobject (modifiable)$pageObjectasMagento\Cms\Model\Page
List of suggestion events
Dispatched before pushing suggestions index settings to Algolia
algolia_suggestions_index_before_set_settings
Parameters:
$store_id$index_settingsas data inMagento\Framework\DataObjectobject (modifiable)
Dispatched after suggestions collection creation
algolia_after_suggestions_collection_build
Parameters:
$store$collectionasMagento\Search\Model\ResourceModel\Query\Collection(modifiable)
Dispatched after fetching suggestion attributes for indexing
algolia_after_create_suggestion_object
Parameters:
$suggestionas data inMagento\Framework\DataObjectobject (modifiable)$suggestionObjectasMagento\Search\Model\Query
List of additional sections events
Dispatched before pushing additional section index settings to Algolia
algolia_additional_sections_index_before_set_settings
Parameters:
$store_id$index_settingsas data inMagento\Framework\DataObjectobject (modifiable)
Dispatched after fetching additional section attributes for indexing
algolia_additional_section_items_before_index
Parameters:
$section$recordas data inMagento\Framework\DataObjectobject (modifiable)$store_id
List of frontend configuration events
Dispatched after frontend configuration creation
algolia_after_create_configuration
Parameters:
$configurationas data inMagento\Framework\DataObjectobject (modifiable)