diff --git a/config/rapidez.php b/config/rapidez.php index d4973f6d8..50f5ff3a6 100644 --- a/config/rapidez.php +++ b/config/rapidez.php @@ -111,6 +111,7 @@ 'sales_order_address' => Rapidez\Core\Models\SalesOrderAddress::class, 'sales_order_item' => Rapidez\Core\Models\SalesOrderItem::class, 'sales_order_payment' => Rapidez\Core\Models\SalesOrderPayment::class, + 'search_query' => Rapidez\Core\Models\SearchQuery::class, ], // The fully qualified class names of the widgets. diff --git a/routes/web.php b/routes/web.php index f41651c56..5df4725bd 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,6 +2,7 @@ use Rapidez\Core\Http\Controllers\FallbackController; use Rapidez\Core\Http\Controllers\HealthcheckController; +use Rapidez\Core\Http\Controllers\SearchController; use Rapidez\Core\Http\Middleware\AuthenticateHealthCheck; Route::get('healthcheck', HealthcheckController::class)->middleware(AuthenticateHealthCheck::class); @@ -9,6 +10,6 @@ Route::middleware('web')->group(function () { Route::view('cart', 'rapidez::cart.overview')->name('cart'); Route::view('checkout', 'rapidez::checkout.overview')->name('checkout'); - Route::view('search', 'rapidez::search.overview')->name('search'); + Route::get('search', SearchController::class)->name('search'); Route::fallback(FallbackController::class); }); diff --git a/src/Http/Controllers/SearchController.php b/src/Http/Controllers/SearchController.php new file mode 100644 index 000000000..5184a01b1 --- /dev/null +++ b/src/Http/Controllers/SearchController.php @@ -0,0 +1,31 @@ + Str::lower($request->q), + 'store_id' => config('rapidez.store'), + ], ['popularity' => 1]); + + if (! $searchQuery->exists) { + $searchQuery->save(); + + return view('rapidez::search.overview'); + } + + $searchQuery->increment('popularity'); + + if ($searchQuery->is_active === 1 && $searchQuery->redirect) { + return redirect($searchQuery->redirect, 301); + } + + return view('rapidez::search.overview'); + } +} diff --git a/src/Models/SearchQuery.php b/src/Models/SearchQuery.php new file mode 100644 index 000000000..7bc85b849 --- /dev/null +++ b/src/Models/SearchQuery.php @@ -0,0 +1,16 @@ +