craftcms / commerce

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

[5.x]: Undefined column: 7 ERROR: column "sortOrder" does not exist #3554

Closed merlindiavova closed 4 months ago

merlindiavova commented 4 months ago

What happened?

Description

When creating a new order status, an error occurs

2024-06-23 13:50:52 [web.ERROR] [yii\db\Exception] SQLSTATE[42703]: Undefined column: 7 ERROR: column "sortorder" does not exist LINE 1: SELECT MAX(sortOrder) ^ HINT: Perhaps you meant to reference the column "ylf_commerce_orderstatuses.sortOrder". The SQL being executed was: SELECT MAX(sortOrder) FROM "ylf_commerce_orderstatuses" WHERE "storeId"='1' {"trace":["#0 /vendor/yiisoft/yii2/db/Command.php(1325): yii\\db\\Schema->convertException()","#1 /vendor/yiisoft/yii2/db/Command.php(1186): yii\\db\\Command->internalExecute()","#2 /vendor/yiisoft/yii2/db/Command.php(443): yii\\db\\Command->queryInternal()","#3 /vendor/yiisoft/yii2/db/Query.php(497): yii\\db\\Command->queryScalar()","#4 /vendor/craftcms/cms/src/db/Query.php(375): yii\\db\\Query->queryScalar()","#5 /vendor/yiisoft/yii2/db/Query.php(428): craft\\db\\Query->queryScalar()","#6 /vendor/craftcms/commerce/src/controllers/OrderStatusesController.php(130): yii\\db\\Query->max()","#7 [internal function]: craft\\commerce\\controllers\\OrderStatusesController->actionSave()","#8 /vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()","#9 /vendor/yiisoft/yii2/base/Controller.php(178): yii\\base\\InlineAction->runWithParams()","#10 /vendor/yiisoft/yii2/base/Module.php(552): yii\\base\\Controller->runAction()","#11 /vendor/craftcms/cms/src/web/Application.php(349): yii\\base\\Module->runAction()","#12 /vendor/craftcms/cms/src/web/Application.php(650): craft\\web\\Application->runAction()","#13 /vendor/craftcms/cms/src/web/Application.php(311): craft\\web\\Application->_processActionRequest()","#14 /vendor/yiisoft/yii2/base/Application.php(384): craft\\web\\Application->handleRequest()","#15 /web/index.php(12): yii\\base\\Application->run()","#16 {main}"],"memory":1998368,"exception":"[object] (yii\\db\\Exception(code: 42703): SQLSTATE[42703]: Undefined column: 7 ERROR: column \"sortorder\" does not exist\nLINE 1: SELECT MAX(sortOrder)\n ^\nHINT: Perhaps you meant to reference the column \"ylf_commerce_orderstatuses.sortOrder\".\nThe SQL being executed was: SELECT MAX(sortOrder)\nFROM \"ylf_commerce_orderstatuses\"\nWHERE \"storeId\"='1' at /vendor/yiisoft/yii2/db/Schema.php:676)\n[previous exception] [object] (PDOException(code: 42703): SQLSTATE[42703]: Undefined column: 7 ERROR: column \"sortorder\" does not exist\nLINE 1: SELECT MAX(sortOrder)\n ^\nHINT: Perhaps you meant to reference the column \"ylf_commerce_orderstatuses.sortOrder\". at /vendor/yiisoft/yii2/db/Command.php:1320)"}

The offending file line seems to be vendor/craftcms/commerce/src/controllers/OrderStatusesController.php on line 130. $orderStatus->sortOrder = (new Query())->from(Table::ORDERSTATUSES)->where(['storeId' => $storeId])->max('sortOrder') + 1;

Steps to reproduce

  1. Create a new Order Status and press Save

Expected behavior

An Orde

Actual behavior

Please see description above.

Craft CMS version

Craft Pro 5.2.3

Craft Commerce version

5.0.11.1

PHP version

8.3.7

Operating system and version

Arch | Linux 6.9.2-arch1-1

Database type and version

Postgres 16

Image driver and version

GD 8.3.7

Installed plugins and versions

linear[bot] commented 4 months ago

PT-1886 [5.x]: Undefined column: 7 ERROR: column "sortOrder" does not exist

lukeholder commented 4 months ago

Thanks for reporting. 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#dd535c1b9935808f33f0eb836fde6cc6a2564bff",
  "...": "..."
}

Then run composer update.

We will update this ticket once the release it out.

nfourtythree commented 3 months ago

Hi

Commerce version 5.0.12 has been released with this update included.

Thanks!