Skip to content

Commit

Permalink
Fixed #3367 MySQL 5.7 error when ensuring discount sort order
Browse files Browse the repository at this point in the history
  • Loading branch information
nfourtythree committed Jan 12, 2024
1 parent 460675c commit 111c418
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## Unreleased

- Fixed a SQL error that could occur when updating to Commerce 4.4.0 on MySQL. ([#3367](https://github.com/craftcms/commerce/issues/3367))
- Fixed a PHP error that occurred when saving a discount. ([#3364](https://github.com/craftcms/commerce/issues/3364))

## 4.4.0 - 2024-01-11

- Craft Commerce now requires Craft CMS 4.6.0 or later.
Expand Down
8 changes: 6 additions & 2 deletions src/services/Discounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,12 @@ public function ensureSortOrder(): void
} else {
$sql = <<<SQL
UPDATE $table a
JOIN (SELECT id, [[sortOrder]], ROW_NUMBER() OVER (ORDER BY [[sortOrder]] ASC, id ASC) as rownumber
FROM $table) b ON a.id = b.id
JOIN (
SELECT id, [[sortOrder]], (@ROW_NUMBER := @ROW_NUMBER + 1) as rownumber
FROM $table,
(SELECT @ROW_NUMBER := 0) AS X
ORDER BY [[sortOrder]] ASC, id ASC
) b ON a.id = b.id
SET [[a.sortOrder]] = b.rownumber
SQL;
}
Expand Down

0 comments on commit 111c418

Please sign in to comment.