Magento2: CE 2.2.X Configurable product with 1 Attribute - Display Out of Stock Products

Created on 8 May 2018  ·  31Comments  ·  Source: magento/magento2


Preconditions


  1. Magento CE 2.2.X
  2. Apache 2.4.27
  3. PHP 7.0.22

Steps to reproduce

  1. Install Magento 2.2.X CE Sample Data
  2. Admin > Stores > Configuration > Catalog > Inventory > Stock Options > Display Out of Stock Products = Yes.
  3. CLI php bin/magento indexer:reindex
  4. Admin > Products > Catalog > Create configurable product with 1 attribute. Set either Quantity = 0 or Stock Status = Out of Stock.

Expected result

  1. Frontend product should display with all Simple products part of Configurable product and should display with class disabled (red strike through) for out of stock .

Actual result

  1. Frontend product not displayed all.

Swatches needs update S2 not-confirmed

Most helpful comment

Just to further corroborate this, I also followed my original steps from November in that instance and found that the swatches are indeed correctly showing now:

image

Would be very interested to learn what commit(s) addressed this.

All 31 comments

We have the same issue with simple products that are shown in a dropdown attribute. "Display out of stock products" = yes, but they do not appear in the dropdown on a configurable product detail page.

Even after reindexing/clearing cache.

still a problem in CE 2.2.4

Edit: _The following is for <= 2.2.4. This has since been changed in 2.2.5_

The cause seems to be Magento\ConfigurableProduct\Plugin\Model\ResourceModel\Attribute\InStockOptionSelectBuilder which always adds a stock status filter without regard to the "Show out of Stock Products" setting.

I personally fixed it with a custom module di.xml though I doubt that this is always the right solution since this for example doesn't check if backorders are allowed for a specific attribute . Maybe someone else has a more prominent solution?

<type name="Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface">
        <plugin name="Magento_ConfigurableProduct_Plugin_Model_ResourceModel_Attribute_InStockOptionSelectBuilder" disabled="true"/>
        <plugin name="attribute_option_select_builder_instock_fix" type="Vendor\MyModule\Plugin\Magento\ConfigurableProduct\Attribute\InStockOptionSelectBuilder" />
</type>

Vendor\MyModule\Plugin\Magento\ConfigurableProduct\Attribute\InStockOptionSelectBuilder.php

<?php

namespace Vendor\MyModule\Plugin\Magento\ConfigurableProduct\Attribute;

use Magento\CatalogInventory\Model\ResourceModel\Stock\Status;
use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface;
use Magento\Framework\DB\Select;
use Magento\Framework\App\Config\ScopeConfigInterface;

class InStockOptionSelectBuilder
{
    private $stockStatusResource;
    private $scopeConfig;

    public function __construct(
        Status $stockStatusResource,
        ScopeConfigInterface $scopeConfig
    )
    {
        $this->stockStatusResource = $stockStatusResource;
        $this->scopeConfig = $scopeConfig;
    }

    public function afterGetSelect(OptionSelectBuilderInterface $subject, Select $select)
    {
        if (!$this->scopeConfig->getValue(\Magento\CatalogInventory\Model\Configuration::XML_PATH_SHOW_OUT_OF_STOCK, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
            $select->joinInner(
                ['stock' => $this->stockStatusResource->getMainTable()],
                'stock.product_id = entity.entity_id',
                []
            )->where(
                'stock.stock_status = ?',
                \Magento\CatalogInventory\Model\Stock\Status::STATUS_IN_STOCK
            );
        }        

        return $select;
    }
}

@kinhcan this is dublicate to -> https://github.com/magento/magento2/issues/10454

@sduif i've follow your instruction, but it doesn't work on magento 2.2.5

Correct, unfortunately there have been various changes in 2.2.5 that break the suggested fix. I've updated my comment to reflect this. I'm affraid I do not have an alternative fix at this time.

@sduif thanks you, i've searching for this issue all day long and find a lot of code and suggestion, but none of them work so far.

The bug is still present, with a configurable and only one attribute, please reopen the issue.

I don't believe this to be a bug. It's more just how they've decided to handle this logic.

That said, I would like an option to show sold out sizes on items with just one attribute.

@kinhcan this is dublicate to -> #10454

This is not a duplicate of that issue. That issue was closed because they didn't try reproducing it correctly. They tried on a product with more than one configurable attributes. They need to try on a product with only a single configurable attribute -- as the very title of this issue says!

@magento-engcom-team or @engcom-Charlie Please re-open this issue.

@magento give me 2.4-develop instance

Hi @ihor-sviziev. Thank you for your request. I'm working on Magento 2.4-develop instance for you

Hi @ihor-sviziev, here is your Magento instance.
Admin access: https://i-15047-2-4-develop.instances.magento-community.engineering/admin_4385
Login: f5a9c1e7 Password: 1902a5ba424d
Instance will be terminated in up to 3 hours.

Re-opening because of https://github.com/magento/magento2/issues/27368. Looks like this issue was closed not correctly and have to be re-checked

Hi @kinhcan @diamondavocado,
I just created configurable product with single attribute on test instance: https://i-15047-2-4-develop.instances.magento-community.engineering/ .

On category page configurable product is shown:
image

On product page:
image

But when I enabled one single product - it started to show "in stock" and it started showing drop-down with attribute selection:
image

As for me it works as expected. Do you agree?

Hi @ihor-sviziev. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

Hi @kinhcan,
I'm closing this issue as we weren't able to reproduce the issue and didn't get any answer https://github.com/magento/magento2/issues/15047#issuecomment-602444182 or additional info during long period of time.

@ihor-sviziev OP was referring to swatches so I don't think your replication was too relevant I'm afraid. OP didn't make that entirely clear as it's not in the title or the description, however their reference to a red strike ("should display with class disabled (red strike through) for out of stock") tells us this is the case.

Your reproduction seems to only check relating to the configurable dropdown and beyond that, only that the dropdown appears when there is at least one configuration available. Not sure if only one option appears in the dropdown in your reproduction when there is only one attribute configured by - if only one colour appears in the dropdown, it is partially relevant. If both appear with one marked out of stock, then it is entirely irrelevant.

The following is definitely happening in in 2.2/2.3/2.4 with swatches:

  • If product is configured by 1 attribute (e.g colour), 2 colours configured, and both are in stock:
    Two swatches show.
    Good behaviour
  • If product is configured by 1 attribute (e.g colour), 2 colours configured, and one is out stock:
    Only one swatch shows, the other is not rendered at all.
    Bad behaviour
  • If product is configured by 2 attributes (e.g. colour and size), one of the configurations is out of stock:
    The relevant swatch is rendered, and is crossed out.
    Good behaviour

Also see https://github.com/magento/magento2/issues/30046

Thx for the additional info. I reopened this issue

Having just now reproduced this in a 2.4-develop instance over in #30046 I am also going to put this reproduction proof here too, as there seems to be many fronts to this and right now it's not clear which one is best served as the authoritative issue. Hopefully its useful for whoever looks at this issue:

Hi @engcom-Delta. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

@magento give me 2.4-develop instance

Hi @engcom-Delta. Thank you for your request. I'm working on Magento instance for you.

@magento give me 2.4-develop instance

Hi @engcom-Delta. Thank you for your request. I'm working on Magento instance for you.

@ihor-sviziev @joshdavenport I'm not able to reproduce issue by steps on clean 2.4-develop
Result:
:heavy_check_mark: The red swatch (out of stock) is crossed out.
image

And according comment we have same result on 2.4-develop as on the latest image: if configurable product has 1 attribute(swatch) and one of the variations is out of stock, then it rendered on frontend as cross out swatch

Could we closed this issue or there are additional steps that were missed?

Well, this looks positive. I was definitely seeing this issue in mid/late November in the instance made here but in this instance you made today it does look to be working as intended. I'm guessing a change has been made in 2.4-develop in the last few weeks that has addressed this issue. If this is for real, very excited for this as it's been an ongoing saga in a current build.

Just to further corroborate this, I also followed my original steps from November in that instance and found that the swatches are indeed correctly showing now:

image

Would be very interested to learn what commit(s) addressed this.

Hi @kinhcan,
Thx for confirmation. I'm closing this issue as not relevant anymore.

Unfortunately, I don't have information on which exactly changes fixed it.

Was this page helpful?
0 / 5 - 0 ratings