Skip to content

Commit

Permalink
Merge branch 'develop' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-kuendig committed Oct 9, 2024
2 parents df3f1e4 + e10d07f commit 938c08e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 17 additions & 5 deletions classes/index/mysql/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 . '"']);
Expand Down
2 changes: 2 additions & 0 deletions updates/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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+'

0 comments on commit 938c08e

Please sign in to comment.