magento2
magento2 copied to clipboard
Swatches missing when all products are out of stock
Preconditions (*)
- Magento 2.4.1
Steps to reproduce (*)
- Install sample data
- Set Admin > Stores > Configuration > Catalog > Inventory > Stock Options > Display Out of Stock Products = Yes
- Create configurable product with multiple sizes
- Change all simple/size products to have 0 quantity and out of stock status
Expected result (*)
- All sizes still show on the frontend, but disabled/crossed out. Similar to this, but instead all of them are crossed out:

Actual result (*)
- No sizes show on the frontend, which then also removes product price since no options are available:

This behaviour has been reported many times before, however it has been addressed in 2.3 by crossing swatches out instead of not rendering them at all like it used to. This is definitely a step in the right direction, however it is still half-complete as you would expect this logic to apply for all the swatches - not just some of the time.
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.
- [X] 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”.
Hi @robbie-thompson. Thank you for your report. To help us process this issue please make sure that you provided the following information:
- Summary of the issue
- Information on your environment
- Steps to reproduce
- Expected and actual results
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
@magento give me 2.4-develop instance - upcoming 2.4.x release
For more details, please, review the Magento Contributor Assistant documentation.
Please, add a comment to assign the issue: @magento I am working on this
- Join Magento Community Engineering Slack and ask your questions in #github channel.
:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
:clock10: You can find the schedule on the Magento Community Calendar page.
:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.
:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel
:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel
Hi @ajijshekh123. 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).
Details
If the issue has a valid description, the labelIssue: Format is validwill be added to the issue automatically. Please, edit issue description if needed, until labelIssue: Format is validappears. -
[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add
Issue: Clear Descriptionlabel to the issue by yourself. -
[ ] 3. Add
Component: XXXXXlabel(s) to the ticket, indicating the components it may be related to. -
[ ] 4. Verify that the issue is reproducible on
2.4-developbranchDetails
- Add the comment@magento give me 2.4-develop instanceto deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-developbranch, please, add the labelReproduced 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: Confirmedonce 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 @ajijshekh123. Thank you for your request. I'm working on Magento instance for you.
Hi @ajijshekh123, here is your Magento Instance: https://6436f328a81cd600bac8a41f0ff576a3-2-4-develop.instances.magento-community.engineering Admin access: https://6436f328a81cd600bac8a41f0ff576a3-2-4-develop.instances.magento-community.engineering/admin_a377 Login: 0c3820ec Password: 41c4a8f50567
Hi @robbie-thompson,
As per your scenario, I have reproduced this issue on the latest Magento 2.4 instance. Whenever all the simple products, Set the status "Out of Stock" with Qty "0". The system is not displayed any of the size attributes with strike symbol but The system is displayed blank configurable products.
Screenshot:


Thanks.
:white_check_mark: Confirmed by @ajijshekh123
Thank you for verifying the issue. Based on the provided information internal tickets MC-39873 were created
Issue Available: @ajijshekh123, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
@magento I am working on this
@ajithkumar-maragathavel Maybe it helps: i made an module, that shows the price and the swatches, when all child-products are out of stock: https://github.com/nordcomputer/magento2-showoutofstockprice
You can switch, if you want to show the swatches in the backend. But it doesnt work with the classic select-field.
This is also an issue with 2.3.5
I think I know what is causing this issue. I ran into an issue about 8 months ago when working with swatches...
There's a query that obtains the swatch attribute codes, but the query will only return results if options exist. The file: app/code/Magento/Swatches/Model/SwatchAttributeCodes.php contains code that is a bit misleading. There are functions with names like: getCodes() and getSwatchAttributeCodes(), but what is a bit misleading (though it is documented) is the fact that only attributes that are swatches and HAS options will be returned.
With that said, let me point out where this is being used in conjunction with configurable products: https://github.com/magento/magento2/blob/c36492997ce9aa7949ef59b201da1be2ebe537bc/app/code/Magento/Swatches/Model/SwatchAttributesProvider.php#L63
The problematic function that I was using was https://github.com/magento/magento2/blob/c36492997ce9aa7949ef59b201da1be2ebe537bc/app/code/Magento/Swatches/Model/SwatchAttributeCodes.php#L70:
/**
* Returns list of known swatch attribute codes. Check cache and database.
* Key is attribute_id, value is attribute_code
*
* @return array
*/
public function getCodes()
I found a different way to validate if an attribute was a swatch type, and then things worked. Hopefully this gives a path to resolution.
Note I was using magento 2.3.5-p1
Additional update:
the getCodes() function may be running into issues relating to this: https://github.com/magento/magento2/issues/32322
@robbie-thompson did u got solution to above
Do we have an update on this? It's still the same on 2.4.2
@johnsw It seems, the problem is still occuring in 2.4.2 - I am trying to keep the extension up to date, as long, its necessary: https://github.com/nordcomputer/magento2-showoutofstockprice
I found the reason and simple solution why swatches don't show when all are out of stock.
The issue is Magento checks the function isSaleable() regardless if the item is configurable or not. Here are few fixes.
In file:
https://github.com/magento/magento2/blob/c36492997ce9aa7949ef59b201da1be2ebe537bc/app/code/Magento/Catalog/view/frontend/templates/product/view/form.phtml
Remove both $_product->isSaleable() &&
in file:
https://github.com/magento/magento2/blob/c36492997ce9aa7949ef59b201da1be2ebe537bc/app/code/Magento/Catalog/view/frontend/templates/product/view/addtocart.phtml
After $_product->isSaleable() add || $_product->getTypeID() == \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE
I haven't been able to get the price to show though.
I'm having issues on 2.3.5 but only if you have a different source, on default source seems to be working fine, this is an issue only when you create a custom source and assign the product to it and it isn't fetching all out of stock the data. I've noticed that the out of stock option is in jsonSwatchConfig but not in jsonConfig.
I'm still having the same issue on Magento 2.4.5 does anyone has a fix ? Thank you !
Hi @engcom-Bravo. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:
-
- Add/Edit
Area: XXXXXlabel to the ticket, indicating the functional areas it may be related to.
- Add/Edit
-
- Verify that the issue is reproducible on
2.4-developbranchDetails
- Add the comment@magento give me 2.4-develop instanceto deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-developbranch, please, add the labelReproduced 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!
- Verify that the issue is reproducible on
-
- If the issue is not relevant or is not reproducible any more, feel free to close it.
- Join Magento Community Engineering Slack and ask your questions in #github channel.
Hi @robbie-thompson,
Thanks for your reporting and collaboration.
We have verified the issue in Latest 2.4-develop instance and the issue is reproducible.Kindly refer the screenshots.
Steps to reproduce
- Install sample data
- Set Admin > Stores > Configuration > Catalog > Inventory > Stock Options > Display Out of Stock Products = Yes
- Create configurable product with multiple sizes
- Change all simple/size products to have 0 quantity and out of stock status
No sizes show on the frontend, which then also removes product price since no options are available
Hence Confirming the issue.
Thanks.
:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-12053 is successfully created for this GitHub issue.
:white_check_mark: Confirmed by @engcom-Bravo. Thank you for verifying the issue.
Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-12053
Issue is still present under 2.4.7-p5