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

[2.4.4] Product with Salable Qty of 0 shows 'In Stock' on product page #35319

Closed
5 tasks
FadedOut opened this issue Apr 15, 2022 · 54 comments
Closed
5 tasks

[2.4.4] Product with Salable Qty of 0 shows 'In Stock' on product page #35319

FadedOut opened this issue Apr 15, 2022 · 54 comments
Labels
Area: Product Component: ConfigurableProduct Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Reported on 2.4.4 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch

Comments

@FadedOut
Copy link

FadedOut commented Apr 15, 2022

FIX:
A quick non-official hack/fix was posted further below by @loic-paquin and @jas8522 here

Preconditions (*)

  1. Upgraded from Magento 2.4.3-p1 to 2.4.4
  2. Default Luma Theme or 3rd Party
  3. Have backorders turned off (screenshot attached for confirmation that my settings are correct - though they did not change from 2.4.3-p1 where this was not a problem)

Steps to reproduce (*)

  1. Have a product with 0 salable quantity (configurable product)
  2. Go to frontend product page and check a variation/configuration (by selecting it)
  3. You can click "Add to Cart"

Expected result (*)

  1. It should say "Out of Stock" above SKU and/or you should not be able to select or click the variation swatch.
  2. Should not be able to click "Add to Cart" for an "Out of Stock" product (with 0 salable qty).

Actual result (*)

  1. It will allow you to click/select a swatch of an "out of stock" variation
  2. It will say "In Stock"
  3. Clicking "Add to Cart" it will reload page with error: "There are no source items with the in stock status"
  4. The "X in Stock" feature (only X left threshold) shows correctly when it is under my threshold, but does not show on a product that is really out of stock (with selecting the variation). So that function knows not to show because there are 0 in stock.
  5. Running re-index through CLI, I receive the following error (not sure if it's related - UPDATE: found this to not be related) and made no difference for this problem:

Product EAV index process error during indexation process: Deprecated Functionality: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /home/********/public_html/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php on line 444

My previous installation of 2.4.3-p1 that I just upgraded from, this worked as intended (out of stock variations could not be selected/clicked. It showed a cross-through of the variation that was out of stock). It now does not do this, after upgrading to 2.4.4.

Below are screenshots of the product page as well as the admin/backend showing 0 for default stock quantity. This example is shown on the stock Magento Luma theme.

magento-244-frontend-instock-bug-product_view
magento-244-frontend-instock-bug-backend_settings

EDIT/UPDATE:
The original report of EAV indexing (using CLI) failing might be related, was incorrect. It is not related and made no difference for the bug of "Product with Salable Qty of 0 shows 'In Stock' on product page" - they are separate issues.

Additional Information:
#35319 (comment)


Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
@m2-assistant
Copy link

m2-assistant bot commented Apr 15, 2022

Hi @FadedOut. Thank you for your report.
To speed up processing of this issue, make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@VZeroCool
Copy link

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

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

@magento-deployment-service
Copy link

Hi @VZeroCool, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

@engcom-November engcom-November added the Reported on 2.4.4 Indicates original Magento version for the Issue report. label Apr 18, 2022
@engcom-November engcom-November self-assigned this Apr 18, 2022
@m2-assistant
Copy link

m2-assistant bot commented Apr 18, 2022

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

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

@engcom-November
Copy link
Contributor

engcom-November commented Apr 18, 2022

Hi @FadedOut , Thank you for reporting and collaboration.
Verified the issue on both Magento 2.4.3-p1 instance and 2.4.4 version after upgrading from 2.4.3-p1.
Observations:
Scenario 1: Existing Product - If Product Quantity is > 0 and Salable Quantity is 0 - User is able to select swatch and on clicking "Add to Cart" button - "The requested qty is not available" error message is displayed. Same behavior observed before and after upgrade
image

Scenario 2: Existing Product - If both Product Quantity & Salable Quantity = 0, User is not able to select swatch (Crossed out) in 2.4.3-p1 instance and "The requested qty is not available" error message is displayed in 2.4.4 version
image

Scenario 3: New Product created in 2.4.4 version with Product Quantity 0 - "There are no source items with the in stock status" error message is displayed
But re-indexing working fine in all cases.
image

2.4-develop branch behavior:
image

@engcom-November
Copy link
Contributor

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

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

@magento-deployment-service
Copy link

Hi @engcom-November, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

@engcom-November engcom-November added Component: ConfigurableProduct Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Area: Product Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Apr 18, 2022
@github-jira-sync-bot
Copy link

✅ Jira issue https://jira.corp.magento.com/browse/AC-2877 is successfully created for this GitHub issue.

@m2-assistant
Copy link

m2-assistant bot commented Apr 18, 2022

✅ Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@FadedOut
Copy link
Author

Thank you @engcom-November for verifying.

@engcom-Hotel engcom-Hotel added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Apr 19, 2022
@mikehobin
Copy link

This happens for me in a test site using PHP 8.1, but if I revert to 7.4 the error goes away.

@freakpol
Copy link

This error:

Product EAV index process error during indexation process: Deprecated Functionality: explode(): Passing null to parameter #2 ($string) of type string is deprecated in vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php on line 444

Is also happening for us. There are bunch of entries with null values on the eav tables. And that particular line, under PHP8.1 is preventing the proper reindex of the EAV indices.

@FadedOut
Copy link
Author

@freakpol

Yeah it's weird, for me, if I run the command: bin/magento indexer:reindex then the error shows in the terminal. And in the Magento Admin [index management] it will say "Reindex Required" for the Product EAV. But the odd part: if I don't run the command and let CRON do it, the "Reindex Required" doesn't appear, it seams to run fine when ran by CRON.

So I'm not sure what is going on there, if the Product EAV is not really ever being completed correctly...but @engcom-November said reindexing was working fine for him, so I don't know...

And are you talking about the "catalog_product_index_eav" table? If so, I didn't see any "NULL" but I do have quite a few "1"s under the 'value' column. I'm guessing that's not correct. It's also bloated, like 75k rows. Not sure if that is correct...
magento-catalog-product-eav-table

@cptX
Copy link

cptX commented Oct 19, 2022

Hi, please correct me if my input is wrong or irrelevant. I'm strugling to find a solution for an option of a configurable product to be striked-through instead of normally displayed in case it is out-of-stock. After a lot of searching I ended up to this patch MDVA-34850 here https://experienceleague.adobe.com/tools/commerce-quality-patches/index.html
But I checked my 2.4.5 community installation and this patch was already implemented in the code but I still don't get the correct behavior! So to be honest I don't understand what is happening? My target is to have all options visible and the out-of-stock ones striked-through! How can we accomplish this in the current situation? Is this planned to be solved in 2.4.6?

@drinkingsouls
Copy link

I am having a similar issue.
I can reindex Product EAV fine from command line.
If I use an Admin Reindex module from Mageplaza or Bss Commerce or another vendor I get an issue with a null value.

Deprecated Functionality: explode(): Passing null to parameter #2 ($string) of type string is deprecated in vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php on line 444

Changing line 444 from:
$values = explode(',', $row['value']);
To
$values = explode(',', (string) $row['value']);

Makes this PHP8.1 compatible. Is this just missing 8.1 compatibility or does it signal something incorrectly set or missing in my database for product attrributes?

@FadedOut
Copy link
Author

@drinkingsouls

Pretty certain that just means it's missing PHP 8.1 compatibility. Because that was popping up for me on a few different modules (the $string with null error). Once they were updated for PHP 8.x those errors went away.

@drinkingsouls
Copy link

@FadedOut thanks for the response. This issue should be addressed in the module rather than Magento itself?

@FadedOut
Copy link
Author

@drinkingsouls No prob. Yup, it has to be fixed in the module because Magento works fine with PHP 8.x now. So if you're still getting problems like that it's because the module is not compatible with PHP 8.x - you'd have to bring that up with the module developers.

@cptX
Copy link

cptX commented Oct 29, 2022

Guys the issue here is actually "Product with Salable Qty of 0 shows 'In Stock' on product page". By mistake it was correlated with "Product EAV index process error" as explained by @FadedOut . So please let's stick to the initial issue which is also major!
I saw here that the fix was merged 1fe7184?diff=unified
So my question is when are we going to receive a possible update? We have to wait until March 2023 when the 2.4.6 will be released? Can we apply the changes ourselves manually until an official update comes out?

@FadedOut
Copy link
Author

@cptX

You are correct in that this is really about the stock and the dropdowns/swatches.

But
A) I did not answer your previous post from a few days ago because you need to be able to read previous posts including the very first line of my OP. If you did, you would have notice that
B) There is an interim fix that works fine. You do not need to wait for 2.4.6 and
C) Yes, the dev "engcom-Hotel" already said the official fix would be in 2.4.6.

As for using the fix from the official patch posted (by engcom-Hotel on July 18) I had issues with it. So just use what has already been posted that has been confirmed to work. That is what has been already mentioned, the fix linked in my first OP (first line) works fine for now.

Don't get all bent out of shape until you fully read a bug report topic - there has been a temp fix posted. If there wasn't then I could understand your concern (as there are indeed several like these - no temp fixes) but it's not warranted here, thanks to the great members above we have a fix for now.

@cptX
Copy link

cptX commented Oct 29, 2022

@FadedOut so if I understood correctly you suggest to use the patch here #35319 (comment) and not the official patch that is planned to be rolled out in 2.4.6 version? Please bear in mind I have 2.4.5 and not 2.4.4. Can this make a difference?
If you believe there are issues with the official patch then how can we expect to arrive in 2.4.6 and work? Have you mentioned the issues you found to the devs?
Also, please take into account that I'm not a professional programmer/developer. I just need to build a working and reliable site. Also, I'm completely new to magento. So I don't understand completely all the methodology of solving (important) issues...

@FadedOut
Copy link
Author

@cptX

Yes that comment by "loic-paquin" that you linked to is correct. It is also not a "patch" it is simply a hack to make it work. It is not intended to be "official" in any capacity - it is a temporary fix until the official fix is released (2.4.6). You can use this fix for 2.4.5. I am on 2.4.5-p1 and have used that and it works fine (though do remember modifying core files is not recommended for the main reason of when upgrading to a new version of Magento the "hack" gets overridden - I had to reimplement the fix when I upgraded from 2.4.4 to 2.4.5).

As for mentioning that I had "issues" with the official commit does not mean there is any wrong with it. It is simply that it's a code release not for this version (2.4.5), it is code for 2.4.6. Which is why the developer said it would be fixed in 2.4.6.

Magento and it's code can indeed be complicated, so if you're not able to make sense of what to do, you may wish to hire a coder/Magento developer to help you with it. The comments (the fix posted) I believe to be maybe a 4 or 5/10 complicated, you just have to read thoroughly. But, I do understand making changes like that is not for everyone, to which is why I say you may want to hire someone to help with that. The information on how to make it work has been given and there is nothing more that needs to be done or said until the official fix is released with 2.4.6. The fix (also here: #35319 (comment) ) works so you'll just have to read it thoroughly or you may wish to hire someone to help.

If you do decide to attempt it yourself, the best thing you can do is simple: just make a backup of the file before you modify it. Then modify it and run the standard commands (I use the following for an all-in-one command). Then test if what you did worked. If not, revert the file and try again. But always keep a backup of the file and you'll be fine. It's posted in that comment which file it is.

rm -rf var/cache/* ; rm -rf var/page_cache/* ; rm -rf var/view_preprocessed/* ; rm -rf pub/static/*/* ; rm -rf generated/code/* ; rm -rf generated/metadata/* ; php bin/magento setup:upgrade ; php bin/magento setup:di:compile ; php bin/magento setup:static-content:deploy ; php bin/magento cache:flush ; php bin/magento cache:clean

Sorry I can't help more but I would just be a broken record and be wasting my time - everything you need has been posted already. With that fix you'll have a proper working variation stock visual.

@cptX
Copy link

cptX commented Oct 31, 2022

@FadedOut thank you for your detailed answer!
I have experience with web programming (drupal coding for 12 years) but it has been always for my own needs, not for customers, so my methodologies are not so polished or widely acceptable. So yes I can detect bugs, and try solutions, but I don't have adequate time to create a fine polished solution from scratch these days, thus I'm relying on the community for hints and ideas. I'm going to try your suggestions and of course I'll be waiting for the official solution in 2.4.6.
With time I'll become more experienced in magento and probably I can be more useful to the community too!
I'm a bit surprised though why such basic bugs come up. This specific bug according to what I have read, looks like it came up as a regression. It was previously solved in 2.4.3. So do we know why this came up again, and didn't stay solved since 2.4.3?

@rohitkumawat17
Copy link

@FadedOut
#35319 (comment)
This is working fine if the product has only one option but If the product has two options like color and size then it shows crossed out for all the options.
Any solution??

@FadedOut
Copy link
Author

@rohitkumawat17 I'm sorry I'm not following. This topic has plenty of information to help you get this issue resolved. Simply follow the instructions posted above to have the cross-outs working correctly. And these changes still work fine with 2.4.5-p1 (I'm using it currently).

Here: #35319 (comment)
and
Here: #35319 (comment)

@rohitkumawat17
Copy link

I am still facing the issue. If the product has 2 attributes size and color.

@FadedOut
Copy link
Author

@rohitkumawat17 if you do that fix you will not have the issue. Simple. If you modified the file and it is still doing it, then you've modified it wrong. My current site is living proof it works.

Or you didn't run the proper commands after modifying the file. Run:
rm -rf var/cache/* ; rm -rf var/page_cache/* ; rm -rf var/view_preprocessed/* ; rm -rf pub/static/*/* ; rm -rf generated/code/* ; rm -rf generated/metadata/* ; php bin/magento setup:upgrade ; php bin/magento setup:di:compile ; php bin/magento setup:static-content:deploy ; php bin/magento cache:flush ; php bin/magento cache:clean

That's my super-all-in-one command.

@rohitkumawat17
Copy link

rohitkumawat17 commented Jan 27, 2023 via email

@FadedOut
Copy link
Author

FadedOut commented Jan 27, 2023

I'm not sure what you modified in swatch-rendering.js as there was no "fix" posted for that file...

Hopefully you have originals of both of those files. Always make a copy/backup of files then modify the new (copied file). If you have the originals, restore them and only make a copy of Data.php.

But no problem I'll add it below. This is for the composer installed Magento - not sure if the file would be the same for the non-composer version. EDIT: I should mention this file is from 2.4.5-p1, so directly replacing it in a 2.4.4 may not be super wise (if you're on 2.4.4 that is) - I'm not sure if anything else in the file changed from 2.4.4 to 2.4.5-p1. Use a program like WinMerge to compare. But ultimately the changes happened on lines 93-110
Magento 2.4.4-2.4.5p1 Variation Swatch Stock Crossout Fix.zip

I put the file into the correct folder structure for you to have a better understanding of where to put it. But as a refresher:
./vendor/magento/module-configurable-product/Helper/

And again, make sure to run that command above after replacing the file. And clearing browser cache.

@FadedOut
Copy link
Author

FadedOut commented Jul 2, 2023

Hello @FadedOut,

As I can see this issue got fixed in the scope of the internal Jira ticket AC-2877 by the internal team Related commits: https://github.com/magento/magento2/search?q=AC-2877&type=commits

Based on the Jira ticket, the target version is 2.4.6

Thanks

@engcom-Hotel

Can you double-check this please. This problem still exists in 2.4.6-p1, we still have to do the hack mentioned here: #35319 (comment). Will this ever get fixed properly so we can stop hacking files? It has been years with this issue (v2.4.1 in 2020!!! #31117)

@engcom-November @engcom-Alfa @engcom-Bravo @engcom-Charlie

Can someone actually investigate and fix this? You guys add tags with "Progress: done" but it's never actually fixed...

@engcom-Bravo
Copy link
Contributor

Hi @FadedOut,

Thanks for your update.

It is Working as expected in Magento 2.4-develop instance the configurable variation is crossed out and we are not able to add to cart.

Screenshot 2023-07-06 at 3 21 38 PM

Issue is reproducible in Magento 2.4.6-p1 instance.swatches are not crossed out.

Screenshot 2023-07-06 at 3 22 28 PM

It is working as expected in Magento 2.4.7-beta1 instance.swatches are crossed out.

Screenshot 2023-07-06 at 4 10 18 PM

Issue seems to fixed in latest version of the Magento i.e Magento 2.4.7-beta1.kindly upgrade to latest version of the Magento.

Thanks.

@davirs
Copy link

davirs commented Oct 4, 2023

Could someone explain if this is possible and how I can apply the fix provided in version 2.4.7 to version 2.4.5?

Thank you

@nthurston
Copy link

I think this issue still exists on a product with a mix of swatches and dropdown attributes. It uses swatch-renderer.js (rather than configurable.js) in that case and swatch-renderer only disables the swatch options, not the dropdown options.

@Eikzx
Copy link

Eikzx commented Apr 11, 2024

Hello @nthurston I ran into the exact same issues using MAgento 2.4.6-p3. Have you found a fix for this back in the day?
Greetings Eike.

@stefanskotte
Copy link

Hello @nthurston I ran into the exact same issues using MAgento 2.4.6-p3. Have you found a fix for this back in the day? Greetings Eike.

I still have this problem on 2.4.5-p7, even with 2.4-develop changes applied. I'm trying to figure out where this all goes wrong.

I have MSI enabled, with two different stock sources - both show incorrect on their respective website:

website 1: b2c stock
website 2: b2b stock

Can believe this is so hard to get right.

@jorgepires
Copy link

jorgepires commented Jun 27, 2024

I have managed to get this to work, my conclusion is that the isSalable() is not checking for any quantities on the salable stock. So if you make $product->isSalable() you always get true. This is not following best pratices, and is only used as a demonstration of the issue source.

My solution consists on only touching file vendor/magento/module-configurable-product/Helper/Data.php , the file below is from version 2.4.6-p4 , modified with the issue tag.

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\ConfigurableProduct\Helper;

use Magento\Catalog\Model\Product\Image\UrlBuilder;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Catalog\Helper\Image as ImageHelper;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Image;

 
use Magento\Catalog\Api\ProductRepositoryInterface; /* Salable Issue */
use Magento\InventorySalesApi\Api\GetProductSalableQtyInterface; /* Salable Issue */ 
 
/**
 * Class Data
 *
 * Helper class for getting options
 * @api
 * @since 100.0.2
 */
class Data
{
    /**
     * @var ImageHelper
     */
    protected $imageHelper;

    /**
     * @var UrlBuilder
     */
    private $imageUrlBuilder;

    /**
     * @var ScopeConfigInterface
     */
    private $scopeConfig;
	
 
    protected $productRepository; /* Salable Issue */
    protected $getProductSalableQty; /* Salable Issue */
	 

    /**
     * @param ImageHelper $imageHelper
     * @param UrlBuilder|null $urlBuilder
     * @param ScopeConfigInterface|null $scopeConfig
     */
    public function __construct(
        ImageHelper $imageHelper,
        UrlBuilder $urlBuilder = null,
        ?ScopeConfigInterface $scopeConfig = null,
		ProductRepositoryInterface $productRepository, /* Salable Issue */
        GetProductSalableQtyInterface $getProductSalableQty /* Salable Issue */
    ) {
        $this->imageHelper = $imageHelper;
        $this->imageUrlBuilder = $urlBuilder ?? ObjectManager::getInstance()->get(UrlBuilder::class);
        $this->scopeConfig = $scopeConfig ?? ObjectManager::getInstance()->get(ScopeConfigInterface::class);
		
	$this->productRepository = $productRepository; /* Salable Issue */
        $this->getProductSalableQty = $getProductSalableQty; /* Salable Issue */
    }

    /**
     * Retrieve collection of gallery images
     *
     * @param ProductInterface $product
     * @return Image[]|null
     */
    public function getGalleryImages(ProductInterface $product)
    {
        $images = $product->getMediaGalleryImages();
        if ($images instanceof \Magento\Framework\Data\Collection) {
            /** @var $image Image */
            foreach ($images as $image) {
                $smallImageUrl = $this->imageUrlBuilder
                    ->getUrl($image->getFile(), 'product_page_image_small');
                $image->setData('small_image_url', $smallImageUrl);

                $mediumImageUrl = $this->imageUrlBuilder
                    ->getUrl($image->getFile(), 'product_page_image_medium');
                $image->setData('medium_image_url', $mediumImageUrl);

                $largeImageUrl = $this->imageUrlBuilder
                    ->getUrl($image->getFile(), 'product_page_image_large');
                $image->setData('large_image_url', $largeImageUrl);
            }
        }

        return $images;
    }

    /**
     * Get Options for Configurable Product Options
     *
     * @param Product $currentProduct
     * @param array $allowedProducts
     * @return array
     */
    public function getOptions($currentProduct, $allowedProducts)
    {
        $options = [];
        $allowAttributes = $this->getAllowAttributes($currentProduct);

        foreach ($allowedProducts as $product) {
            $productId = $product->getId();
            foreach ($allowAttributes as $attribute) {
                $productAttribute = $attribute->getProductAttribute();
                $productAttributeId = $productAttribute->getId();
                $attributeValue = $product->getData($productAttribute->getAttributeCode());
                /*if ($this->canDisplayShowOutOfStockStatus()) {
                    if ($product->isSalable()) {
                        $options['salable'][$productAttributeId][$attributeValue][] = $productId;
                    }
                    $options[$productAttributeId][$attributeValue][] = $productId;
                } else {
                    if ($product->isSalable()) {
                        $options[$productAttributeId][$attributeValue][] = $productId;
                    }
                }*/
				
		/********************* Salable Issue ************************/
		$product = $this->productRepository->get($product->getSku());
		$stockItem = $product->getExtensionAttributes()->getStockItem();
				
		if( $stockItem->getManageStock() && $this->getProductSalableQty->execute($product->getSku(), 1) > 0) {
			$options['salable'][$productAttributeId][$attributeValue][] = $productId;
		} 
				
		if( !$stockItem->getManageStock() ) {
			$options['salable'][$productAttributeId][$attributeValue][] = $productId;
		}
				
		$options[$productAttributeId][$attributeValue][] = $productId;
		/********************* Salable Issue ************************/
				
				
                $options['index'][$productId][$productAttributeId] = $attributeValue;
                
            }
        }
        $options['canDisplayShowOutOfStockStatus'] = $this->canDisplayShowOutOfStockStatus();
        return $options;
    }

    /**
     * Get allowed attributes
     *
     * @param Product $product
     * @return array
     */
    public function getAllowAttributes($product)
    {
        return ($product->getTypeId() == Configurable::TYPE_CODE)
            ? $product->getTypeInstance()->getConfigurableAttributes($product)
            : [];
    }

    /**
     * Returns if display out of stock status set or not in catalog inventory
     *
     * @return bool
     */
    private function canDisplayShowOutOfStockStatus(): bool
    {
        return (bool) $this->scopeConfig->getValue('cataloginventory/options/show_out_of_stock');
    }
	

}

@stefanskotte
Copy link

I will try this asap, still have issues with configurables seemingly out of stock even though the simples have returned to a positive qty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Product Component: ConfigurableProduct Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Reported on 2.4.4 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch
Projects
Archived in project