magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

CE 2.2.X Configurable product with 1 Attribute - Display Out of Stock Products #15047

Closed kinhcan closed 3 years ago

kinhcan commented 6 years ago

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.
sduif commented 6 years ago

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.

jeffb1a5 commented 6 years ago

still a problem in CE 2.2.4

sduif commented 6 years ago

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;
    }
}
ghost commented 6 years ago

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

congson95dev commented 5 years ago

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

sduif commented 5 years ago

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.

congson95dev commented 5 years ago

@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.

lamasfoker commented 4 years ago

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

toby-pondr commented 4 years ago

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.

diamondavocado commented 4 years ago

@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.

ihor-sviziev commented 4 years ago

@magento give me 2.4-develop instance

magento-engcom-team commented 4 years ago

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

magento-engcom-team commented 4 years ago

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.

ihor-sviziev commented 4 years ago

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

ihor-sviziev commented 4 years ago

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?

m2-assistant[bot] commented 4 years ago

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:

ihor-sviziev commented 4 years ago

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.

joshdavenport commented 3 years ago

@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:

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

ihor-sviziev commented 3 years ago

Thx for the additional info. I reopened this issue

joshdavenport commented 3 years ago

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:

m2-assistant[bot] commented 3 years ago

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:

engcom-Delta commented 3 years ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 3 years ago

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

magento-deployment-service[bot] commented 3 years ago

Hi @engcom-Delta, here is your Magento Instance: https://1a7cac06c8fc2990b65c8f45d77618c2-2-4-develop.instances.magento-community.engineering Admin access: https://1a7cac06c8fc2990b65c8f45d77618c2-2-4-develop.instances.magento-community.engineering/admin_fb45 Login: 8f59f9cb Password: 36ca722a5014

engcom-Delta commented 3 years ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 3 years ago

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

magento-deployment-service[bot] commented 3 years ago

Hi @engcom-Delta, here is your Magento Instance: https://1a7cac06c8fc2990b65c8f45d77618c2-2-4-develop.instances.magento-community.engineering Admin access: https://1a7cac06c8fc2990b65c8f45d77618c2-2-4-develop.instances.magento-community.engineering/admin_fbf2 Login: 5a9d6237 Password: 3779025339e6

engcom-Delta commented 3 years ago

@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?

joshdavenport commented 3 years ago

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.

joshdavenport commented 3 years ago

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.

ihor-sviziev commented 3 years ago

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.

lbajsarowicz commented 3 years ago

🤯 Glad the issue is sorted, but... definitely, I'd love to know which Commit fixes that or what Quality Patch offers the fix. --- EDIT --- The problem is still not resolved and when you try to get Out of Stock products to display, you end up with this method: https://github.com/magento/magento2/blob/bf4cdad2b1d0436be831c1f5c89c1adc77bfd1fc/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php#L1291-L1300 Where the false in 1294 line stands for excluding out-of-stock products.

magento-deployment-service[bot] commented 3 years ago

Hi @lbajsarowicz. Thank you for your request. Comments like @magento give me test instance are intended for instance deployments on Pull Requests. Please use comment like: @magento give me 2.4-develop instance to request an instance on an issue.

magento-deployment-service[bot] commented 3 years ago

Hi @lbajsarowicz. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 3 years ago

Hi @lbajsarowicz, here is your Magento Instance: https://1a7cac06c8fc2990b65c8f45d77618c2-2-4-develop.instances.magento-community.engineering Admin access: https://1a7cac06c8fc2990b65c8f45d77618c2-2-4-develop.instances.magento-community.engineering/admin_eab9 Login: 2c60abb8 Password: 8149b2d95688

lbajsarowicz commented 3 years ago
  1. Settings image
  2. Product image
  3. Result image

Also (!) When you create completely new product: image

Comments?

ihor-sviziev commented 3 years ago

Reopened since we have a report that issue still reproducing on the 2.4-develop branch

mrtuvn commented 3 years ago

Lukas have you tested in latest code ? From my side results seem working! What do i miss something ? (2.4-develop, sampledata + inventory with config show out-stock product) Both condition i have set quantity 0 for gray variant product No show out-stock no-show-outstock

Showed out-stock showed-out-stock

Correct me if i'm wrong! Very appreciate it

lbajsarowicz commented 3 years ago

@mrtuvn I used the test instance that Magento built. image

m2-assistant[bot] commented 3 years ago

Hi @engcom-November. 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:

lamasfoker commented 3 years ago

@mrtuvn you have to test with a product with only 1 configurable attribute.

mrtuvn commented 3 years ago

config-1attr here is for configurable with 1 attribute swatch (no selected)

Selected option config-selected

config2

lamasfoker commented 3 years ago

Thanks @mrtuvn for check it out, I think te issue can finally been closed now 🎉

ihor-sviziev commented 3 years ago

@lbajsarowicz, could you provide more info on how you reproduced it? Thank you!

lbajsarowicz commented 3 years ago

Ignore it. We fixed that locally on the project. You can close it now.

engcom-November commented 3 years ago

Thanks for your update @mrtuvn. Closing the ticket as the issue is resolved.