diff --git a/classes/index/mysql/MySQL.php b/classes/index/mysql/MySQL.php index 7eb30b4b9..af28f6206 100644 --- a/classes/index/mysql/MySQL.php +++ b/classes/index/mysql/MySQL.php @@ -5,6 +5,7 @@ use Cache; use DB; use Event; +use Illuminate\Foundation\Application; use Illuminate\Support\Collection; use October\Rain\Database\Schema\Blueprint; use OFFLINE\Mall\Classes\CategoryFilter\Filter; @@ -101,7 +102,7 @@ public function create(string $index) ); $table->index(['index', 'published'], 'idx_published_index'); }); - + // Allow the index table to be extended with custom columns Event::fire('mall.index.mysql.extendTable', [$table]); } catch (Throwable $e) { @@ -166,14 +167,14 @@ protected function persist(string $index, Entry $entry) 'customer_group_prices' => $data['customer_group_prices'] ?? [], 'created_at' => $data['created_at'] ?? now(), ]; - + // Allow the index data to be extended with custom information $customIndexData = Event::fire('mall.index.extendData', [$data]); if(!empty($customIndexData) && is_array($customIndexData[0])) { $indexData = array_merge($indexData, $customIndexData[0]); } - + $this->db()->updateOrCreate([ 'index' => $index, 'product_id' => $productId, @@ -286,11 +287,22 @@ protected function handleOrder($order, $db) array_shift($parts); $nested = implode('.', $parts); + $expression = DB::raw($field); + + /** + * Laravel 10 changed the way expressions are converted to strings + * @see https://laravel.com/docs/10.x/upgrade#database-expressions + */ + $laravelMajorVersion = (int) (explode('.', Application::VERSION)[0] ?? 0); + if ($laravelMajorVersion >= 10) { + $expression = $expression->getValue(DB::connection()->getQueryGrammar()); + } + // Apply the right cast for this value. This makes sure, that prices are sorted as floats, not as strings. if (isset($this->columnCasts[$field])) { - $orderBy = sprintf('CAST(JSON_EXTRACT(%s, ?) as %s) %s', DB::raw($field), $this->columnCasts[$field], $order->direction()); + $orderBy = sprintf('CAST(JSON_EXTRACT(%s, ?) as %s) %s', $expression, $this->columnCasts[$field], $order->direction()); } else { - $orderBy = sprintf('JSON_EXTRACT(%s, ?) %s', DB::raw($field), $order->direction()); + $orderBy = sprintf('JSON_EXTRACT(%s, ?) %s', $expression, $order->direction()); } $db->orderByRaw($orderBy, ['$.' . '"' . $nested . '"']); diff --git a/updates/version.yaml b/updates/version.yaml index 5371748e0..6f54be8c7 100644 --- a/updates/version.yaml +++ b/updates/version.yaml @@ -611,3 +611,5 @@ v3.5.3: - 'Fixed guest signup' v3.5.4: - 'Refactgored built-in validation rule' +v3.5.5: + - 'Fix raw query for Laravel 10+'