craftcms / commerce

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

[5.x]: availableForPurchase() causing error #3459

Closed pimago closed 2 months ago

pimago commented 2 months ago

What happened?

Description

I updated to Craft and Commerce 5. When I load templates that use availableForPurchase() I get an error

Calling unknown method: craft\commerce\elements\db\ProductQuery::availableForPurchase()

This is my product query

{% set products = craft.products()
            .availableForPurchase()
            .hasVariant({ hasStock: true })
            .orderBy('defaultPrice DESC')
            .all() %}

Craft CMS version

5.0.4

Craft Commerce version

5.0.0-beta.3

PHP version

8.2.9

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

-

linear[bot] commented 2 months ago

PT-1643 [5.x]: availableForPurchase() causing error

lukeholder commented 2 months ago

The availableForPurchasable query param has been moved to the variant/purchasable

You would need to do:

{% set products = craft.products()
            .hasVariant({ hasStock: true, availableForPurchase: true })
            .orderBy('defaultPrice DESC')
            .all() %}

We will fix that in the upgrade guide before release. Thanks.