If you have a use case that requires modifying an attribute before indexing from Magento to Algolia, you can implement a Magento backend observer by customizing the algolia_after_create_product_object
event.
For example, if some of your product SKUs have a leading 0 in Magento (ie;0123456
), you may wish to index both the original SKU and a modified version without the leading zero (ie: [0123456
,123456
]).
Here is an example customization to the events.xml
file to modify the SKU indexing:
<?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="algolia_after_create_product_object">
<observer name="customalgolia_sku_modifier" instance="Algolia\CustomAlgolia\Observer\AlgoliaAfterCreateProductObject" />
</event>
</config>
The object's data would get passed to the observer as custom_data
:
public function execute(Observer $observer)
{
/** @var \Magento\Framework\DataObject $data */
$data = $observer->getData('custom_data');
$sku = $data->getData('sku');
// Massage skus however you like
// Keep in mind could be array or scalar
// (depending on whether simple vs configurable product etc.)
$data->setData('sku', $sku);
}
For more details on this approach, please refer to this documentation. Please note that this customization is out-of-scope for our Support team.