Smile-SA/elasticsuite

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

Summary

Maintainability
Test Coverage
<?xml version="1.0"?>
<!--
/**
 * Smile_ElasticsuiteCatalog adminhtml dependency injection configuration.
 *
 * 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    Romain RUAUD <romain.ruaud@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">

    <type name="\Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit\Tab\Front">
        <plugin name="search_weigh"
            type="\Smile\ElasticsuiteCatalog\Block\Plugin\Adminhtml\Product\Attribute\Edit\Tab\FrontPlugin"
            sortOrder="200"
        />
    </type>

    <type name="Magento\Catalog\Model\Category\DataProvider">
        <plugin name="smile_elasticsuite_categories_form_data_provider" type="Smile\ElasticsuiteCatalog\Plugin\Ui\Category\Form\DataProviderPlugin" />
    </type>

    <!-- Prevent computing categories aggregations (that's used only for displaying facets in front) in back-office objects that manipulate products collections -->
    <virtualType name="categoryRequestBuilderWithoutAggregations" type="Smile\ElasticsuiteCore\Search\Request\Builder">
        <arguments>
            <argument name="aggregationResolver" xsi:type="object">Smile\ElasticsuiteCatalog\Search\Request\Product\Coverage\Aggregation\Resolver</argument>
        </arguments>
    </virtualType>

    <virtualType name="fulltextProductCollectionWithoutAggregations" type="Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection">
        <arguments>
            <argument name="requestBuilder" xsi:type="object">categoryRequestBuilderWithoutAggregations</argument>
        </arguments>
    </virtualType>

    <virtualType name="fulltextProductCollectionWithoutAggregationsBuilder" type="Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\CollectionFactory">
        <arguments>
            <argument name="instanceName" xsi:type="string">fulltextProductCollectionWithoutAggregations</argument>
        </arguments>
    </virtualType>

    <type name="Smile\ElasticsuiteCatalog\Model\ProductSorter\PreviewInterface">
        <arguments>
            <argument name="productCollectionFactory" xsi:type="object">fulltextProductCollectionWithoutAggregationsBuilder</argument>
        </arguments>
    </type>

    <type name="Smile\ElasticsuiteCatalog\Plugin\Ui\Category\Form\DataProviderPlugin">
        <arguments>
            <argument name="fulltextCollectionFactory" xsi:type="object">fulltextProductCollectionWithoutAggregationsBuilder</argument>
        </arguments>
    </type>

    <!-- Use the coverage mechanism in BO -->
    <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>

    <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>
            </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>
            </argument>
        </arguments>
    </virtualType>

    <!-- Handle category additional "use_config" checkboxes because the native ones are hardcoded in controller -->
    <type name="Magento\Catalog\Controller\Adminhtml\Category\Save">
        <plugin name="handle_additional_use_config" type="Smile\ElasticsuiteCatalog\Plugin\Catalog\Controller\Adminhtml\Category\SavePlugin" />
    </type>
</config>