Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magento 2 configurable product selection stock issue #5948

Closed
dapdx opened this issue Aug 2, 2016 · 61 comments
Closed

Magento 2 configurable product selection stock issue #5948

dapdx opened this issue Aug 2, 2016 · 61 comments
Labels
bug report Component: Catalog Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@dapdx
Copy link

dapdx commented Aug 2, 2016

Setting up configurable products and using the text swatch option to select shirt sizes. The issue is the out of stock shirt text swatches are still showing up, clickable, and have no styling to show that they are out of stock. I'd like the swatch to still show up, but not be clickable and appear faded out or something so you know they are out of stock. Any help?

I'm not seeing any class for out of stock being passed through that I can style with CSS.

This worked fine in Magento 1, where on drop downs the out of stock simple products were not selectable, but in Magento 2, both on drop downs and text swatches they still show up and you can click on them, but when added to the cart you get the "product not in stock" error.

@veloraven
Copy link
Contributor

@dapdx thank you for your report.
Please provide description according to the template: with steps, actual result and expected result.
Please also provide the used version. If the problem is actual for a specific tag, please, specify it and be sure that the latest update was used.

@dapdx
Copy link
Author

dapdx commented Aug 3, 2016

Magento 2.1
PHP 7

Steps to Reproduce

  1. Create configurable product (in this case example t-shirt)
  2. Create linked simple prodcuts (sizes S, Med, Large, XL)
  3. Set Size attribute to Text Swatch
  4. Set Medium size to out of stock, others are in-stock

Expected Result

  1. When Medium size is out of stock, on the front end it should have a class assigned to it so you can style it with CSS to make it not available for purchase or signify that it is out of stock.

Actual Result

  1. On front end all (S, M, L, XL) text swatches appear, none have a strike through, or greyed out or missing. There is no "out of stock" class applied to the swatch so you can style it with CSS.

@JohnWean
Copy link

JohnWean commented Aug 4, 2016

I also have the same problems and then I have to use an extension from the third part to solve it although this issue can be overcome quite easily in Magento 1 as you have said.
I have been using this Magento 2 extension - Configurable product grid table view bought from a Magento provider to make out of stock product still visible but unavailable to choose quantity in the box . The quantity box is faded and cannot fill in.

@andidhouse
Copy link

I can confirm this on a fresh 2.1 system.

Really bad bug as we have lots of sizes :-/

@duhon
Copy link
Contributor

duhon commented Aug 5, 2016

@dapdx Thanks for reporting this issue.
We've created internal ticket MAGETWO-56480 to fix it.

@duhon duhon added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Aug 5, 2016
@otg-chris
Copy link

This bug came up when I updated a site from 2.02 to 2.1. Before the out-of-stock options were not shown. A quick fix to hide them (probably won't work with multiple options)
is to modify the /vendor/magento/module-swatches/Block/Product/Renderer/Configurable.php file

change the getConfigurableOptionsIds function to this

protected function getConfigurableOptionsIds (array $attributeData) {
    $ids = [];
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface');
    foreach ($this->getAllowProducts() as $product) {
        if (0 == $StockState->getStockQty($product->getId(), $product->getStore()->getWebsiteId())) continue;
        /** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute $attribute */
        foreach ($this->helper->getAllowAttributes($this->getProduct()) as $attribute) {
            $productAttribute = $attribute->getProductAttribute();
            $productAttributeId = $productAttribute->getId();
            if (isset($attributeData[$productAttributeId])) {
                $ids[$product->getData($productAttribute->getAttributeCode())] = 1;
            }
        }
    }
    return array_keys($ids);
}

@epadmin
Copy link

epadmin commented Aug 25, 2016

I also have this problem. Worked in 2.0 but on 2.1 it does not.
http://foxtrotboutique.com/sally-gaucho-crop-denim-by-level-99-white.html Size 24 for example is out of stock and should not let you choose it, but it lets you pick it until you try to add to cart and then gives an out of stock message

@mjankiewicz
Copy link

mjankiewicz commented Aug 28, 2016

Hi, I had similar problem but the client did not want to hide products out of stock but display on gray or other a style (as unavailable).
I've prepared simple module to that: https://github.com/mjankiewicz/MagentoConfigurableProduct

zrzut ekranu 2016-08-28 16 36 56

Maybe it will be useful for someone :)

@MorganGonzales
Copy link

MorganGonzales commented Aug 30, 2016

Hi @mjankiewicz,

Tried installing your module (followed the steps), but wasn't able to make it work (tried to install it on a fresh M2.1 environment).
Badly need a fix for this issue for our client.

Thanks!

@mjankiewicz
Copy link

mjankiewicz commented Aug 30, 2016

Hi @MhorGonzales,

  1. the module is enabled ? php bin/magento module:status
  2. do you see some error messages on the frontend or backend ?

@mjankiewicz
Copy link

@MhorGonzales

I've checked again my module on fresh Magento 2 (sample data) and everything works fine.
Detail view without module:
zrzut ekranu 2016-08-31 10 02 36

And with module:
zrzut ekranu 2016-08-31 10 01 20

@epadmin
Copy link

epadmin commented Sep 1, 2016

it seemed to work in 2.01 but on 2.1 it does not.  Are you using 2.1?

-------- Original Message --------
Subject: Re: [magento/magento2] Magento 2 configurable product selection
stock issue (#5948)
From: mjankiewicz notifications@github.com
Date: Wed, August 31, 2016 3:07 am
To: magento/magento2 magento2@noreply.github.com
Cc: epadmin admin@elemeno-pee.com, Comment
comment@noreply.github.com

@MhorGonzales I've checked again my module on fresh Magento 2 (sample data) and everything works fine. Detail view without module: And with module: —You are receiving this because you commented.Reply to this email directly, view it on GitHub, or mute the thread.

@mjankiewicz
Copy link

Yes. I use Magento ver. 2.1.1 (installed by composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2demo)

@MorganGonzales
Copy link

Hi @mjankiewicz,

Thank you for the response, after investigation, it seems that this conflicts with the extension MagicToolbox_MagicZoom.

Anyway, it is working now. However, is there a tweak where in it should show the slash/not-available, if just the status alone is "Out of Stock", regardless of the "Quantity" value? As observed, "Quantity" should be set to zero (0) for this to work.

Thank you in advance.

@MorganGonzales
Copy link

@mjankiewicz Does it mean, this issue is still not yet resolved in 2.1.1???

@mjankiewicz
Copy link

Yes. The issue isn't resolved in 2.1.1. (tested on fresh installation Magento 2.1.1 with sample data)

@duhon duhon removed their assignment Sep 2, 2016
@RishabhRkRai
Copy link

Hi,
I also have this problem and i'm using 2.1.1

@andidhouse
Copy link

@magento-team

This is another MUST-FIX bug - a normal logic at an commerce site! I have no idea why this worked before and is missing now. Can you pls give us a feedback when this one will work again.

I think one of the main problems with m2 at this stage is that new bugs come in with every release like waves at a beach - and only some are fixed. Very frustrating at the moment to be honest.

@cuiyang000
Copy link

Can confirm the problem with 2.1.1

And @mjankiewicz 's module worked great! Thanks a lot, really saved my hair :)

@staffrob
Copy link

Thanks @mjankiewicz, your module is working for me on 2.1.1.

BTW. Is anyone here using M2 on live site with configurable products and if so how did you resolve this issue with first associated product becoming out of stock?#6799

@giacmir
Copy link
Member

giacmir commented Mar 12, 2017

2.1.3 solved for me too.

@alrayn
Copy link

alrayn commented Apr 12, 2017

am using 2.1.5 but these problem stile there !

I must to change status manually vi MySQL

@v0gler
Copy link

v0gler commented Apr 12, 2017

What variable do you change in MySQL?

@alrayn
Copy link

alrayn commented Apr 14, 2017

stock_status to 1 on cataloginventory_stock_status table

but now I change PHP version to 5.6 and it's work fine

@pushonscott
Copy link

Just upgraded to 2.1.7 and this is still an issue for us.

The module https://github.com/mjankiewicz/MagentoConfigurableProduct works ok for swatches, but not drop downs.

Does anyone have a fix?

@LupoiuAlin15
Copy link

For magento 2.1.6 to work i was needed to create another custom module.
See the answer

https://magento.stackexchange.com/questions/191431/out-of-stock-products-from-configurable-not-appears-in-swatches-on-magento-2/191435#191435

@magento-engcom-team magento-engcom-team added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report Component: Catalog Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels Sep 11, 2017
@magento-engcom-team magento-engcom-team added the Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed label Sep 27, 2017
@magento-engcom-team
Copy link
Contributor

@dapdx, thank you for your report.
We were not able to reproduce this issue by following the steps you provided. If you'd like to update it, please reopen the issue.

@magento-engcom-team magento-engcom-team added the Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch label Sep 27, 2017
@waqarriaz
Copy link

its only work on swatches icons not on dropdown

@diptihere
Copy link

Awesome solution..Its working

@jmtakahashi
Copy link

So it this issue fixed properly in 2.1.9?

Meaning, swatches are still displayed, but unselectable?

Currently, my store just hides the sizes that are out of stock, and only shows sizes that are in stock. I'n assuming this is proper behavior, but is there way to show the sizes that are out if stock as well, and disable them from being selectable?

@diptihere
Copy link

I have checked this in 2.2.0. After applying above solution, It shows sizes which are out of stock and they wont be selectable.

@jmtakahashi
Copy link

@diptihere which solution are you referring to? The mjankiewicz extension doesn't work "out of the box" on my 2.1.9 store.

@diptihere
Copy link

Yes, mjankiewicz extension. It worked for me. U just have to override this getOptions method. Is there any error u r getting.

@jmtakahashi
Copy link

@diptihere how do I override the getOptions method? Maybe thats where the problem is.

@dawhoo
Copy link

dawhoo commented Nov 28, 2017

Magento 2.2.1 - I have tried the solution from @mjankiewicz but the product pages and search return blank or broken.

Update: @mjankiewicz works when installed via composer. When I tried via zip and upload, it didn't but does when installed via composer.

@Wernervanrun
Copy link

Wernervanrun commented Dec 17, 2017

Magento 2.2.2 - Still not working...

@mjankiewicz your solution is only a partial fix.
It will not work in the following situations;

If only one attribute Size as Text Swatch is available ( Size dropped )
If Color and Size are set but one Color has no Sizes available ( Color dropped )
If none of the Colors have one of the Size available ( Size dropped )

Looking at the php and javascript there does not seem to be an easy fix for every situation.

In my opinion all available Simple products should always render ( with exception of disabled Simple products )
In the case Stock alerts are enabled and backorders are turned off, out of stock Simple products should be selectable after selecting a Stock alert text + link should appear below the options.

Something like;
We are sorry this product is not available at this time, LINK NOTIFY ME when the product becomes available.

@coderimus
Copy link
Contributor

@dawhoo @Wernervanrun I think I have found the reason why this error appeared. Please, review this PR - #12936

The main problem, from my point of view, was in the incorrect stock status filter appliance. It was successfully implemented previously in Magento\ConfigurableProduct\Model\Product\Type\Configurable::getSalableUsedProducts(\Magento\Catalog\Model\Product $product, $requiredAttributeIds = null) This method called the $this->loadUsedProducts($product, $cacheKey, true); method where 3rd param allows stock status filter in Magento\ConfigurableProduct\Model\Product\Type\Configurable::loadUsedProducts(\Magento\Catalog\Model\Product $product, $cacheKey, $salableOnly = false)
Since 100.2.0 method the getSalableUsedProducts method was deprecated.

About suggested solution in the helper class: to be honest, it is totally not good to call the object load in the loop. This generates extra load. Much better to get needed data in one collection call to avoid performance issue.

@magento-team
Copy link
Contributor

Hi @dapdx. Thank you for your report.
The issue has been fixed in #12936 by @coderimus in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming patch release.

@magento-team magento-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Jan 26, 2018
@mclevenger
Copy link

mclevenger commented Mar 11, 2018

In Magento 2.2.2

Worked out a plugin to allow for out of stock child option products of a configurable product to work in concert with the @mjankiewicz helper.

Key point was in: vendor/magento/module-configurable-product/Model/ResourceModel/Attribute/OptionSelectBuilder.php

Created a plugin to modify the select to allow for out of stock products in the configurable options:

`<?php

namespace Watermelon\OutofStockChildProductSwatchVisible\Plugin\Magento\ConfigurableProduct\Model\ResourceModel\Attribute;

class OptionSelectBuilder
{
protected $logger;
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Psr\Log\LoggerInterface $logger)
{
$this->_scopeConfig = $scopeConfig;
$this->logger = $logger;
}

public function afterGetSelect(
\Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilder $subject,
$result
) {

$showoutofstock =  $this->_scopeConfig->getValue('cataloginventory/options/show_out_of_stock', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

if ($showoutofstock == '1') {

  $where = $result->getPart('where');

  foreach ($where as $key => $condition)
  {

  //$this->logger->info("CONDITION: " . json_encode($condition));

    if (strpos($condition, 'stock.stock_status = 1') !== false) {
        $updatedWhere[] = 'AND (stock.stock_status IN (1,0))';
    } else {
        $updatedWhere[] = $condition;
    }

  }

  $result->setPart('where', $updatedWhere);

}

return $result;

}
}`
Hope it helps someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Catalog Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests