magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Swatches missing when all products are out of stock

Open robbie-thompson opened this issue 4 years ago • 23 comments

Preconditions (*)

  1. Magento 2.4.1

Steps to reproduce (*)

  1. Install sample data
  2. Set Admin > Stores > Configuration > Catalog > Inventory > Stock Options > Display Out of Stock Products = Yes
  3. Create configurable product with multiple sizes
  4. Change all simple/size products to have 0 quantity and out of stock status

Expected result (*)

  1. All sizes still show on the frontend, but disabled/crossed out. Similar to this, but instead all of them are crossed out: image

Actual result (*)

  1. No sizes show on the frontend, which then also removes product price since no options are available: image

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

robbie-thompson avatar Dec 11 '20 16:12 robbie-thompson

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


: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

m2-assistant[bot] avatar Dec 11 '20 16:12 m2-assistant[bot]

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

    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.

m2-assistant[bot] avatar Dec 14 '20 05:12 m2-assistant[bot]

@magento give me 2.4-develop instance

ajijshekh123 avatar Dec 14 '20 05:12 ajijshekh123

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

image

Thanks.

ajijshekh123 avatar Dec 14 '20 12:12 ajijshekh123

: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-engcom-team avatar Dec 14 '20 12:12 magento-engcom-team

@magento I am working on this

ajithkumar-maragathavel avatar Jan 17 '21 00:01 ajithkumar-maragathavel

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

nordcomputer avatar Jan 17 '21 14:01 nordcomputer

This is also an issue with 2.3.5

carlos-reynosa avatar Mar 04 '21 23:03 carlos-reynosa

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

df2k2 avatar Mar 07 '21 11:03 df2k2

@robbie-thompson did u got solution to above

ia-gaurav avatar May 15 '21 11:05 ia-gaurav

Do we have an update on this? It's still the same on 2.4.2

johnsw avatar Oct 18 '21 12:10 johnsw

@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

nordcomputer avatar Oct 18 '21 12:10 nordcomputer

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.

bigware avatar Jan 17 '22 04:01 bigware

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.

lano-vargas avatar Dec 05 '22 14:12 lano-vargas

I'm still having the same issue on Magento 2.4.5 does anyone has a fix ? Thank you !

magento2dev avatar Jan 19 '23 19:01 magento2dev

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:

    1. Add/Edit Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
    1. 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!
    1. If the issue is not relevant or is not reproducible any more, feel free to close it.

m2-assistant[bot] avatar May 31 '24 05:05 m2-assistant[bot]

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
Screenshot 2024-05-31 at 11 15 31

No sizes show on the frontend, which then also removes product price since no options are available

Hence Confirming the issue.

Thanks.

engcom-Bravo avatar May 31 '24 05:05 engcom-Bravo

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-12053 is successfully created for this GitHub issue.

github-jira-sync-bot avatar May 31 '24 07:05 github-jira-sync-bot

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

m2-assistant[bot] avatar May 31 '24 07:05 m2-assistant[bot]

:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-12053

github-jira-sync-bot avatar May 31 '24 07:05 github-jira-sync-bot

Issue is still present under 2.4.7-p5

gjportegies avatar Jun 17 '25 14:06 gjportegies