craftcms / commerce

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

[5.x]: ->hasVariant(['hasStock' => true]) throws a DB error of Unknown column 'purchasables_stores.hasUnlimitedStock' #3505

Closed sunscreem closed 1 week ago

sunscreem commented 2 weeks ago

What happened?

Description

When running the following query:


\craft\commerce\elements\Product::find()->status(Product::STATUS_ENABLED)->hasVariant(['hasStock' => true])->all()

The following error is thrown:


SQLSTATE[42S22]: Column not found: 1054 Unknown column 'purchasables_stores.hasUnlimitedStock' in 'where clause'
The SQL being executed was: SELECT COUNT(*)
FROM `elements` `elements`
[rest of query]

Steps to reproduce

  1. Clean install Craft 5 & Craft Commerce.
  2. Create somewhere to run the above code (I used a module)
  3. Run the query above.

Expected behavior

Return an array of "in stock" products.

Actual behavior

Throws the above error.

Craft CMS version

5.1.4

Craft Commerce version

5.0.6

PHP version

8.2

Operating system and version

No response

Database type and version

mysql

Image driver and version

No response

Installed plugins and versions

linear[bot] commented 2 weeks ago

PT-1741 [5.x]: ->hasVariant(['hasStock' => true]) throws a DB error of Unknown column 'purchasables_stores.hasUnlimitedStock'

lukeholder commented 1 week ago

Thanks for reporting this!

We have fixed the error.

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

"require": {
  "craftcms/commerce": "5.x-dev#5348e43b58a9ee2b0335de999337bdb9cdbeff68 as 5.0.6",
  "...": "..."
}

Then run composer update.

We will update this ticket once the next release is out.

Thanks!

sunscreem commented 1 week ago

@lukeholder Thank you - That's it working with the fix.

lukeholder commented 1 week ago

5.0.7 is now out with this fix! Thanks.