Smile-SA/elasticsuite

View on GitHub
src/module-elasticsuite-catalog/etc/frontend/di.xml

Summary

Maintainability
Test Coverage
<?xml version="1.0"?>
<!--
/**
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer
 * versions in the future.
 *
 * @category  Smile
 * @package   Smile\ElasticsuiteCatalog
 * @author    Aurelien FOUCRET <aurelien.foucret@smile.fr>
 * @copyright 2020 Smile
 * @license   Open Software License ("OSL") v. 3.0
 */
 -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <virtualType name="Smile\ElasticsuiteCatalog\Model\Layer\Filter\Item\AttributeFactory" type="Magento\Catalog\Model\Layer\Filter\ItemFactory">
        <arguments>
            <argument name="instanceName" xsi:type="string">Smile\ElasticsuiteCatalog\Model\Layer\Filter\Item\Attribute</argument>
        </arguments>
    </virtualType>

    <type name="Smile\ElasticsuiteCatalog\Model\Layer\Filter\Attribute">
        <arguments>
            <argument name="filterItemFactory" xsi:type="object">Smile\ElasticsuiteCatalog\Model\Layer\Filter\Item\AttributeFactory</argument>
            <argument name="mappingHelper" xsi:type="object">Smile\ElasticsuiteCatalog\Helper\ProductAttribute</argument>
        </arguments>
    </type>

    <virtualType name="smileEScategoryFilterableAttributesCollection" type="Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory">
        <arguments>
            <argument name="instanceName" xsi:type="string">Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\FilterableAttribute\Category\Collection</argument>
        </arguments>
    </virtualType>

    <type name="Smile\ElasticsuiteCatalog\Model\Layer\Category\FilterableAttributeList">
        <arguments>
            <argument name="collectionFactory" xsi:type="object">smileEScategoryFilterableAttributesCollection</argument>
        </arguments>
    </type>

    <type name="Smile\ElasticsuiteCatalog\Model\Layer\Filter\Boolean">
        <arguments>
            <argument name="mappingHelper" xsi:type="object">Smile\ElasticsuiteCatalog\Helper\ProductAttribute</argument>
        </arguments>
    </type>

    <virtualType name="Smile\ElasticsuiteCatalog\Model\Layer\Filter\Item\CategoryFactory" type="Magento\Catalog\Model\Layer\Filter\ItemFactory">
        <arguments>
            <argument name="instanceName" xsi:type="string">Smile\ElasticsuiteCatalog\Model\Layer\Filter\Item\Category</argument>
        </arguments>
    </virtualType>

    <type name="Smile\ElasticsuiteCatalog\Model\Layer\Filter\Category">
        <arguments>
            <argument name="filterItemFactory" xsi:type="object">Smile\ElasticsuiteCatalog\Model\Layer\Filter\Item\CategoryFactory</argument>
        </arguments>
    </type>

    <virtualType name="categoryFilterList" type="Smile\ElasticsuiteCatalog\Model\Layer\FilterList">
        <arguments>
            <argument name="filterableAttributes" xsi:type="object">Smile\ElasticsuiteCatalog\Model\Layer\Category\FilterableAttributeList</argument>
            <argument name="filters" xsi:type="array">
                <item name="attribute" xsi:type="string">Smile\ElasticsuiteCatalog\Model\Layer\Filter\Attribute</item>
                <item name="price" xsi:type="string">Smile\ElasticsuiteCatalog\Model\Layer\Filter\Price</item>
                <item name="decimal" xsi:type="string">Smile\ElasticsuiteCatalog\Model\Layer\Filter\Decimal</item>
                <item name="category" xsi:type="string">categoryFilterUsingRewrite</item>
                <item name="boolean" xsi:type="string">Smile\ElasticsuiteCatalog\Model\Layer\Filter\Boolean</item>
            </argument>
        </arguments>
    </virtualType>

    <virtualType name="searchFilterList" type="Smile\ElasticsuiteCatalog\Model\Layer\FilterList">
        <arguments>
            <argument name="filterableAttributes" xsi:type="object">Smile\ElasticsuiteCatalog\Model\Layer\Search\FilterableAttributeList</argument>
            <argument name="filters" xsi:type="array">
                <item name="attribute" xsi:type="string">Smile\ElasticsuiteCatalog\Model\Layer\Filter\Attribute</item>
                <item name="price" xsi:type="string">Smile\ElasticsuiteCatalog\Model\Layer\Filter\Price</item>
                <item name="decimal" xsi:type="string">Smile\ElasticsuiteCatalog\Model\Layer\Filter\Decimal</item>
                <item name="category" xsi:type="string">Smile\ElasticsuiteCatalog\Model\Layer\Filter\Category</item>
                <item name="boolean" xsi:type="string">Smile\ElasticsuiteCatalog\Model\Layer\Filter\Boolean</item>
            </argument>
        </arguments>
    </virtualType>

    <virtualType name="categoryFilterUsingRewrite" type="Smile\ElasticsuiteCatalog\Model\Layer\Filter\Category">
        <arguments>
            <argument name="useUrlRewrites" xsi:type="boolean">true</argument>
        </arguments>
    </virtualType>

    <virtualType name="Magento\LayeredNavigation\Block\Navigation\Category" type="Smile\ElasticsuiteCatalog\Block\Navigation">
        <arguments>
            <argument name="filterList" xsi:type="object">categoryFilterList</argument>
        </arguments>
    </virtualType>

    <virtualType name="Magento\LayeredNavigation\Block\Navigation\Search" type="Smile\ElasticsuiteCatalog\Block\Navigation">
        <arguments>
            <argument name="filterList" xsi:type="object">searchFilterList</argument>
        </arguments>
    </virtualType>

    <type name="Smile\ElasticsuiteCatalog\Controller\Navigation\Filter\Ajax">
        <arguments>
            <argument name="filterListPool" xsi:type="array">
                <item name="category" xsi:type="object">categoryFilterList</item>
                <item name="search" xsi:type="object">searchFilterList</item>
            </argument>
        </arguments>
    </type>

    <type name="Magento\Search\Model\Autocomplete">
        <arguments>
            <argument name="dataProviders" xsi:type="array">
                <item name="20" xsi:type="object">Smile\ElasticsuiteCatalog\Model\Autocomplete\Product\DataProvider</item>
                <item name="30" xsi:type="object">Smile\ElasticsuiteCatalog\Model\Autocomplete\Product\Attribute\DataProvider</item>
                <item name="40" xsi:type="object">Smile\ElasticsuiteCatalog\Model\Autocomplete\Category\DataProvider</item>
            </argument>
        </arguments>
    </type>

    <virtualType name="Smile\ElasticsuiteCatalog\Model\Autocomplete\Product\Collection" type="Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection">
        <arguments>
            <argument name="searchRequestName" xsi:type="string">catalog_product_autocomplete</argument>
        </arguments>
    </virtualType>

    <type name="Smile\ElasticsuiteCatalog\Model\Autocomplete\Product\Collection\Provider" shared="true">
        <arguments>
            <argument name="collection" xsi:type="object">Smile\ElasticsuiteCatalog\Model\Autocomplete\Product\Collection</argument>
            <argument name="collectionProcessors" xsi:type="array">
                <item name="filters" xsi:type="object">Smile\ElasticsuiteCatalog\Model\Autocomplete\Product\Collection\Filter</item>
                <item name="attributeSelect" xsi:type="object">Smile\ElasticsuiteCatalog\Model\Autocomplete\Product\Collection\AttributeSelector</item>
            </argument>
        </arguments>
    </type>

    <!-- Handle compatibility with Staging for Layered Navigation -->
    <virtualType name="Magento\LayeredNavigationStaging\Block\Navigation\Category" type="Smile\ElasticsuiteCatalog\Block\Navigation">
        <arguments>
            <argument name="filterList" xsi:type="object">categoryFilterList</argument>
        </arguments>
    </virtualType>

    <virtualType name="Magento\LayeredNavigationStaging\Block\Navigation\Search" type="Smile\ElasticsuiteCatalog\Block\Navigation">
        <arguments>
            <argument name="filterList" xsi:type="object">searchFilterList</argument>
        </arguments>
    </virtualType>
    <!-- End of  compatibility with Staging for Layered Navigation -->

    <!-- Ensure navigation block is using fulltext collection, to prevent error when it sends it through the Layer -->
    <type name="Magento\Catalog\Block\Navigation">
        <arguments>
            <argument name="productCollectionFactory" xsi:type="object">Magento\CatalogSearch\Model\ResourceModel\Fulltext\CollectionFactory</argument>
        </arguments>
    </type>

    <!-- Ensure standard promotion block is using fulltext collection, to prevent error when it sends it through the Layer -->
    <type name="Magento\Catalog\Block\Product\ProductList\Promotion">
        <arguments>
            <argument name="productCollectionFactory" xsi:type="object">Magento\CatalogSearch\Model\ResourceModel\Fulltext\CollectionFactory</argument>
        </arguments>
    </type>

    <!-- Ensure standard random products block is using fulltext collection, to prevent error when it sends it through the Layer -->
    <type name="Magento\Catalog\Block\Product\ProductList\Random">
        <arguments>
            <argument name="productCollectionFactory" xsi:type="object">Magento\CatalogSearch\Model\ResourceModel\Fulltext\CollectionFactory</argument>
        </arguments>
    </type>

    <!-- Ensure category RSS feed dataprovider is using fulltext collection, to prevent error when it sends it through the Layer -->
    <type name="Magento\Catalog\Model\Rss\Category">
        <arguments>
            <argument name="collectionFactory" xsi:type="object">Magento\CatalogSearch\Model\ResourceModel\Fulltext\CollectionFactory</argument>
        </arguments>
        <plugin name="apply_category_filter" type="Smile\ElasticsuiteCatalog\Plugin\Rss\CategoryPlugin"/>
    </type>

    <type name="Magento\CatalogSearch\Controller\Result\Index">
        <plugin name="redirect_if_one_result" type="Smile\ElasticsuiteCatalog\Plugin\CatalogSearch\ResultPlugin"/>
    </type>

    <type name="Smile\ElasticsuiteCatalog\Helper\Autocomplete">
        <arguments>
            <argument name="attributeHelper" xsi:type="object">Smile\ElasticsuiteCatalog\Helper\ProductAttribute</argument>
        </arguments>
    </type>

    <!-- Search Context init -->
    <type name="Magento\Catalog\Model\Layer\Category">
        <plugin name="initSearchContext" type="Smile\ElasticsuiteCatalog\Plugin\Layer\CategoryPlugin"/>
    </type>

    <type name="Magento\Search\Model\QueryFactory">
        <plugin name="initSearchContext" type="Smile\ElasticsuiteCatalog\Plugin\Search\QueryFactoryPlugin"/>
    </type>

    <!-- Layered navigation filtering : Aggregation building and modifying -->
    <type name="\Smile\ElasticsuiteCatalog\Search\Request\Product\Aggregation\Provider\FilterableAttributes\Modifier\Coverage">
        <arguments>
            <argument name="coverageRequestBuilder" xsi:type="object">\Smile\ElasticsuiteCatalog\Search\Request\Product\Coverage\Builder</argument>
        </arguments>
    </type>

    <type name="\Smile\ElasticsuiteCatalog\Search\Request\Product\Aggregation\Provider\FilterableAttributes">
        <arguments>
            <argument name="modifiersPool" xsi:type="array">
                <item name="ajaxFilterModifier" xsi:type="object">Smile\ElasticsuiteCatalog\Search\Request\Product\Aggregation\Provider\FilterableAttributes\Modifier\AjaxFilter</item>
            </argument>
        </arguments>
    </type>

    <virtualType name="searchFilterableAttributesProvider" type="Smile\ElasticsuiteCatalog\Search\Request\Product\Aggregation\Provider\FilterableAttributes">
        <arguments>
            <argument name="attributeList" xsi:type="object">Smile\ElasticsuiteCatalog\Search\Request\Product\Aggregation\Provider\FilterableAttributes\Search\AttributeList</argument>
            <argument name="modifiersPool" xsi:type="array">
                <item name="coverageModifier" xsi:type="object">Smile\ElasticsuiteCatalog\Search\Request\Product\Aggregation\Provider\FilterableAttributes\Modifier\Coverage</item>
                <item name="statisticsModifier" xsi:type="object">Smile\ElasticsuiteCatalog\Search\Request\Product\Aggregation\Provider\FilterableAttributes\Modifier\Statistics</item>
            </argument>
        </arguments>
    </virtualType>

    <virtualType name="categoryFilterableAttributesProvider" type="Smile\ElasticsuiteCatalog\Search\Request\Product\Aggregation\Provider\FilterableAttributes">
        <arguments>
            <argument name="attributeList" xsi:type="object">Smile\ElasticsuiteCatalog\Search\Request\Product\Aggregation\Provider\FilterableAttributes\Category\AttributeList</argument>
            <argument name="modifiersPool" xsi:type="array">
                <item name="coverageModifier" xsi:type="object">Smile\ElasticsuiteCatalog\Search\Request\Product\Aggregation\Provider\FilterableAttributes\Modifier\Coverage</item>
                <item name="statisticsModifier" xsi:type="object">Smile\ElasticsuiteCatalog\Search\Request\Product\Aggregation\Provider\FilterableAttributes\Modifier\Statistics</item>
            </argument>
        </arguments>
    </virtualType>

    <preference for="Smile\ElasticsuiteCatalog\Search\Request\Product\Aggregation\Provider\FilterableAttributes\Modifier\Statistics\AttributeFilterInterface"
                type="Smile\ElasticsuiteCatalog\Search\Request\Product\Aggregation\Provider\FilterableAttributes\Modifier\Statistics\PriceAttributeFilter" />

    <type name="Smile\ElasticsuiteCatalog\Search\Request\Product\Attribute\AggregationInterface">
        <plugin name="layered_nav_attributes_replace_filter_field"
                type="Smile\ElasticsuiteCatalog\Plugin\Search\Request\Product\Attribute\Aggregation\LayeredNavAttribute"/>
    </type>
</config>