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

[5.x]: hasStock: true not working correctly on all products #3668

Closed
bartrylant opened this issue Sep 11, 2024 · 5 comments
Closed

[5.x]: hasStock: true not working correctly on all products #3668

bartrylant opened this issue Sep 11, 2024 · 5 comments

Comments

@bartrylant
Copy link

bartrylant commented Sep 11, 2024

What happened?

Description

I'm running

{% craft.products().hasVariant({hasStock: true}).all() %}

However, some products that do have stock, are not shown. I have absolutely no idea why and I cannot see anything those products have in common. If I go through all variants and get the stock for every variant with variant.stock, I get the corrects numbers. It just seems like the hasStock: true parameter doesn't work as it should.

Steps to reproduce

  1. Run {% craft.products().hasVariant({hasStock: true}).all() %}

Expected behavior

Show products that have variants with stock

Actual behavior

Some products that have variants with stock, don't get shown.

Craft CMS version

5.4.2

Craft Commerce version

5.1.1

PHP version

8.3.8

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

Copy link

linear bot commented Sep 11, 2024

@bartrylant
Copy link
Author

I noticed this happens with products/variants that are imported with Feed Me. If stock was edited with Feed Me, you have to run craft resave/products to get the correct stock on the front-end.

@lukeholder
Copy link
Member

Thanks for reporting this. We have fixed this for the next release.

To get the fix early, change your craftcms/commerce requirement in composer.json to:

"require": {
  "craftcms/commerce": "5.x-dev#dabeeb5470c4db92e2f5ec75b5f05b99efc0123d as 5.1.1",
  "...": "..."
}

Then run composer update.

We will update this ticket once the release is out.

@lukeholder lukeholder reopened this Sep 13, 2024
@lukeholder
Copy link
Member

Please note, you will still need to resave you products, but this will fix the issue going forward as stock is updated.

@lukeholder lukeholder self-assigned this Sep 13, 2024
@nfourtythree
Copy link
Contributor

Commerce 5.1.2 has now been released with this fix included.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants