Skip to content

Extending

Romain Ruaud edited this page Nov 13, 2017 · 2 revisions

Extending Elasticsuite

The goal of this part is to list the most common extension points of Elasticsuite and how they can be used by developers to fit their needs.

Adding special attributes to rules

You are able to add special attributes to rules by doing it via the code.

Attributes added like this will be available for virtual categories and optimizers.

The entry point for these attributes will be the DI first :

    <!-- Add the default Elasticsuite Special Attributes. -->
    <type name="Smile\ElasticsuiteCatalogRule\Model\Rule\Condition\Product\SpecialAttributesProvider">
        <arguments>
            <argument name="attributes" xsi:type="array">
                <item name="has_image" xsi:type="object">Smile\ElasticsuiteCatalogRule\Model\Rule\Condition\Product\SpecialAttribute\HasImage</item>
                <item name="stock.is_in_stock" xsi:type="object">Smile\ElasticsuiteCatalogRule\Model\Rule\Condition\Product\SpecialAttribute\IsInStock</item>
                <item name="price.is_discount" xsi:type="object">Smile\ElasticsuiteCatalogRule\Model\Rule\Condition\Product\SpecialAttribute\IsDiscount</item>
            </argument>
        </arguments>
    </type>

You can add a new attribute here, and then you will have to implement it's object.

The object must implements \Smile\ElasticsuiteCatalogRule\Api\Rule\Condition\Product\SpecialAttributeInterface.

The most complex part to implement is the getSearchQuery() method. You can find additional method about how you are supposed to build a search query in the Querying part.

Do not hesitate to inspire from the default Elasticsuite special attributes.

Adding custom data (not attributes) to Product index.

When installing Elasticsuite, you will have by default all attributes data indexed into Elasticsearch. But you may wonder how you are supposed to add data coming from elsewhere to the index.

To achieve this, you should read carefully the Indexing - Data Sources part which is explaining how it's done and how you can extend it.

Clone this wiki locally