Elasticsuite: Out of stock child products are still available in list

Created on 9 Mar 2018  路  8Comments  路  Source: Smile-SA/elasticsuite


This issue is similar to #480, except that we are talking about out of stock and virtual categories with filter by configurable attribute.

Preconditions


Magento Version : 2.1.11


ElasticSuite Version : 2.3.11 (I have checked changelog for newest versions of this plugin - this issue not fixed yet)


Environment : PHP 7.0


Third party modules : -

Steps to reproduce

  1. Create configurable product C1 with attribute "size", children: S1, S2, S3
  2. Let's S2 to be out of stock
  3. Disable displaying out of stock products in category view (stores - config - catalo - ...)
  4. Create virtual category with filter by size, where size = S2
  5. Open this virtual category on frontend

Expected result

  1. Product with size S2 should not be visible in virtual category. Simple product with this size is out of stock

Actual result

  1. json from ES response
                "children_ids": [
                    77449,
                    77450, // this product is out of stock
                    77451
                ],
                "children_attributes": [
                    "size",
                    "option_text_size"
                ],
                "configurable_attributes": [
                    "size"
                ],
                "size": [
                    110,
                    109, // product with this size is out of stock
                    111
                ],

Most helpful comment

quick temporary workaround:

<?php

namespace Brouzie\Satin\Plugin\Model\ResourceModel\Product\Indexer\Fulltext\Datasource;

use Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Datasource\AttributeData;
use Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Datasource\InventoryData;

class AttributeDataPlugin
{
    private $inventoryData;

    public function __construct(InventoryData $inventoryData)
    {
        $this->inventoryData = $inventoryData;
    }

    public function aroundLoadChildrens(AttributeData $subject, callable $proceed, $productIds, $storeId)
    {
        $children = $proceed($productIds, $storeId);

        $inventoryData = $this->inventoryData->loadInventoryData($storeId, array_keys($children));

        foreach ($inventoryData as $inventoryDataRow) {
            $productId = (int) $inventoryDataRow['product_id'];
            if (!$inventoryDataRow['stock_status']) {
                unset($children[$productId]);
            }
        }

        return $children;
    }
}

All 8 comments

quick temporary workaround:

<?php

namespace Brouzie\Satin\Plugin\Model\ResourceModel\Product\Indexer\Fulltext\Datasource;

use Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Datasource\AttributeData;
use Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Datasource\InventoryData;

class AttributeDataPlugin
{
    private $inventoryData;

    public function __construct(InventoryData $inventoryData)
    {
        $this->inventoryData = $inventoryData;
    }

    public function aroundLoadChildrens(AttributeData $subject, callable $proceed, $productIds, $storeId)
    {
        $children = $proceed($productIds, $storeId);

        $inventoryData = $this->inventoryData->loadInventoryData($storeId, array_keys($children));

        foreach ($inventoryData as $inventoryDataRow) {
            $productId = (int) $inventoryDataRow['product_id'];
            if (!$inventoryDataRow['stock_status']) {
                unset($children[$productId]);
            }
        }

        return $children;
    }
}

Hi @Koc,

This issue has already been raised by some internal projects at Smile.
Until now my position was to consider that it is by design and this behavior is consistent with what a standard Magento does out-of-the-box. I explained the projects how to change this behavior. Your workaround seems good to me.

I think we will not implement this behavior because :

  • It is specific to your project. Some projects may want to keep the current behavior in order to maximize the offer presented to customers.
  • We prefer to stay consistent with the standard Magento behavior, as we prefer avoid others issues that are hard to debug like : "Product is missing in category. Why ?".
  • There is an extension point allowing you to implement this behavior and you were able to implement it very easily.

Do you think this is fair ?

Hi @afoucret

We prefer to stay consistent with the standard Magento behavior, as we prefer avoid others issues that are hard to debug like : "Product is missing in category. Why ?".

I think this's a standard Magento setting

Disable displaying out of stock products in category view (stores - config - catalo - ...)

So we should implement this setting Enable/Disable Out-of-stock for ES

Hi @minhluan259,

Disabling out of stock products in product listing is a Magento configuration option.

But when applied it does not remove the configuration option from configurable when a simple goes out of stock. In a standard Magento : the facet on the size stay if the simple product goes out of stock and is linked to a configurable product.

The configurable goes out-of-stock and and it values are removed from faceting only when ALL SIMPLE ATTACHED GOES OUT OF STOCK.

We are consistent with this behavior.

Thank your for explaining. This behavior is fair.

@Koc I close because of the above explanations.

But for now plugin excludes from indexation products without any enabled children.

Is pull request with new config option for possibility change behavior can be accepted?

Hi All,

We are facing one issue related to Out of Stock items. In configurable Products, when all children items are out of stock it should be out of stock the configurable Product. But its not happening when all children items are out of stock.

Kindly let me know the reason why its not updating? When we idividually make In Stock any single children then it updates into Elastic.

For example: I have 4 child items and all 3 are out of stock. Someone place an order for last childeren then it should make Out of Stock Configurable product or delete Index from Elastic Search. But it still show Last child item into Elastic.

@Koc is your solution will help to resolve this issue? and how can use your solution? can you please mentioned the steps

@afoucret please suggest

Regards
Raman

Was this page helpful?
0 / 5 - 0 ratings