craftcms / commerce

Fully integrated ecommerce for Craft CMS.
https://craftcms.com/commerce
Other
215 stars 169 forks source link

[5.x]: Example templates not correctly checking stock #3510

Closed TheFunkyMonk closed 1 month ago

TheFunkyMonk commented 1 month ago

What happened?

Description

In the Commerce 5 example templates, I noticed most of our products were showing "out of stock" on the front end. If I'm understanding the stock setup correctly, having the "Inventory" toggle turned off for a variant is used to indicate unlimited/infinite stock (which also is what displays the ∞ in the table column).

Looking at the check in products/_includes/grid.twig, I see it's using variant.stock as the check for whether a variant is in stock, but looking at the docs it seems variant.hasStock() is the correct way to check now (which functions as I'd expect in my template).

Craft CMS version

5.1.4

Craft Commerce version

5.0.6

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

No response

linear[bot] commented 1 month ago

PT-1748 [5.x]: Example templates not correctly checking stock

lukeholder commented 1 month ago

Thanks this is fixed for the next release. You can use this in your templates in the meantime:

{% if variant.inventoryTracked %}({{ variant.stock ? variant.stock ~ ' available' : 'out of stock'}}){% endif %}
lukeholder commented 1 month ago

5.0.7 is now out and fixes this issue. Thanks!