Elasticsuite: 2.3.2 Upgrade Undefined factory elasticsuite

Created on 26 Jun 2019  路  7Comments  路  Source: Smile-SA/elasticsuite

After removing or fixing the plugin in this issue: https://github.com/Smile-SA/elasticsuite/issues/1442 when trying to use the search it throws a exception with Undefined factory elasticsuite being thrown in this file: https://github.com/magento/magento2/blob/9fc254f241b5a2fa9e28ebdbb179538ca7c1959f/app/code/Magento/Elasticsearch/Model/Layer/Search/ItemCollectionProvider.php#L46

Preconditions

Magento Version : 2.3.2

ElasticSuite Version : 2.8.0

Environment : Developer

Third party modules : N/A

Steps to reproduce

  1. Using default Magento's search
  2. Search for a item

Expected result

  1. Search page should load with products related to the search

Actual result

  1. Exception is thown `Undefined factory elasticsuite

From checking it seems this file is newly added in 2.3.2

bug

Most helpful comment

Hello people,

we are working on this one and aim to release an ElasticSuite 2.8.1 version as soon as possible :)

@androshchuk will have a look on this one.

I'm not sure "just" adding the factories will work properly. Maybe we'll also have to implement them, I'm not sure since I did not dig more into this.

All 7 comments

Looks like you have to do something similar to https://github.com/magento/magento2/commit/885b7a99397e52e1b094c3d23c314ca508429b3b#diff-b2e0d454e4ffd542fa96dc1b7dc225d9 this now, though I haven't gotten that to work personally

worked for me after dealing with the broken addisinstockfilter plugin:

in elasticsuitecatalog\etc\di.xml add :

```xml



Smile\ElasticsuiteCatalogModel\ResourceModel\Product\Fulltext\CollectionFactory


<type name="Magento\CatalogSearch\Model\Search\ItemCollectionProvider">
    <arguments>
        <argument name="factories" xsi:type="array">
            <item name="elasticsuite" xsi:type="object">elasticsearchAdvancedCollectionFactory</item>
        </argument>
    </arguments>
</type>

<type name="Magento\CatalogSearch\Model\Advanced\ProductCollectionPrepareStrategyProvider">
    <arguments>
        <argument name="strategies" xsi:type="array">
            <item name="elasticsuite" xsi:type="object">Magento\Elasticsearch\Model\Advanced\ProductCollectionPrepareStrategy</item>
        </argument>
    </arguments>
</type>

<virtualType name="elasticsearchLayerSearchItemCollectionProvider" type="Magento\Elasticsearch\Model\Layer\Search\ItemCollectionProvider">
    <arguments>
        <argument name="factories" xsi:type="array">
            <item name="elasticsuite" xsi:type="object">Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\CollectionFactory</item>
        </argument>
    </arguments>
</virtualType>

````

Also you could put back the module-catalog-inventory/Model/Plugin/Layer.php instead of deleting this plugin in elasticsearch:

<?php
/**
 * Copyright 漏 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\CatalogInventory\Model\Plugin;

class Layer
{
    /**
     * Stock status instance
     *
     * @var \Magento\CatalogInventory\Helper\Stock
     */
    protected $stockHelper;

    /**
     * Store config instance
     *
     * @var \Magento\Framework\App\Config\ScopeConfigInterface
     */
    protected $scopeConfig;

    /**
     * @param \Magento\CatalogInventory\Helper\Stock $stockHelper
     * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
     */
    public function __construct(
        \Magento\CatalogInventory\Helper\Stock $stockHelper,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
    ) {
        $this->stockHelper = $stockHelper;
        $this->scopeConfig = $scopeConfig;
    }

    /**
     * Before prepare product collection handler
     *
     * @param \Magento\Catalog\Model\Layer $subject
     * @param \Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection $collection
     *
     * @return void
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function beforePrepareProductCollection(
        \Magento\Catalog\Model\Layer $subject,
        \Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection $collection
    ) {
        if ($this->_isEnabledShowOutOfStock()) {
            return;
        }
        $this->stockHelper->addIsInStockFilterToCollection($collection);
    }

    /**
     * Get config value for 'display out of stock' option
     *
     * @return bool
     */
    protected function _isEnabledShowOutOfStock()
    {
        return $this->scopeConfig->isSetFlag(
            'cataloginventory/options/show_out_of_stock',
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
    }
}

worked for me after dealing with the broken addisinstockfilter plugin:

in elasticsuitecatalog\etc\di.xml add :

<virtualType> name="elasticsearchLayerCategoryItemCollectionProvider" type="Magento\Elasticsearch\Model\Layer\Category\ItemCollectionProvider">
        <arguments>
            <argument name="factories" xsi:type="array">
                <item name="elasticsuite" xsi:type="object">Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\CollectionFactory</item>
            </argument>
        </arguments>
    </virtualType>

    <type name="Magento\CatalogSearch\Model\Search\ItemCollectionProvider">
        <arguments>
            <argument name="factories" xsi:type="array">
                <item name="elasticsuite" xsi:type="object">elasticsearchAdvancedCollectionFactory</item>
            </argument>
        </arguments>
    </type>

    <type name="Magento\CatalogSearch\Model\Advanced\ProductCollectionPrepareStrategyProvider">
        <arguments>
            <argument name="strategies" xsi:type="array">
                <item name="elasticsuite" xsi:type="object">Magento\Elasticsearch\Model\Advanced\ProductCollectionPrepareStrategy</item>
            </argument>
        </arguments>
    </type>

    <virtualType name="elasticsearchLayerSearchItemCollectionProvider" type="Magento\Elasticsearch\Model\Layer\Search\ItemCollectionProvider">
        <arguments>
            <argument name="factories" xsi:type="array">
                <item name="elasticsuite" xsi:type="object">Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\CollectionFactory</item>
            </argument>
        </arguments>
    </virtualType>

Thank you, for that post. That saved my day. Mind the first tag and remove the ">" after virtualType <virtualType> name....

Hello people,

we are working on this one and aim to release an ElasticSuite 2.8.1 version as soon as possible :)

@androshchuk will have a look on this one.

I'm not sure "just" adding the factories will work properly. Maybe we'll also have to implement them, I'm not sure since I did not dig more into this.

This one is fixed issue for me. https://github.com/comwrap/elasticsuite-magento-patch

Hope will help somebody. If there are any problems please report or you can also push PR there

Fixed by PR #1461

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DanieliMi picture DanieliMi  路  5Comments

emirajbbd picture emirajbbd  路  3Comments

ghost picture ghost  路  4Comments

markdimi picture markdimi  路  4Comments

wintermute-84 picture wintermute-84  路  4Comments