|
@@ -5,6 +5,7 @@ namespace Webkul\Shop\Http\Controllers\API;
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
use Webkul\Category\Repositories\CategoryRepository;
|
|
use Webkul\Category\Repositories\CategoryRepository;
|
|
|
use Webkul\Marketing\Jobs\UpdateCreateSearchTerm as UpdateCreateSearchTermJob;
|
|
use Webkul\Marketing\Jobs\UpdateCreateSearchTerm as UpdateCreateSearchTermJob;
|
|
|
|
|
+use Webkul\Marketing\Services\SearchLogService;
|
|
|
use Webkul\Product\Repositories\ProductRepository;
|
|
use Webkul\Product\Repositories\ProductRepository;
|
|
|
use Webkul\Shop\Http\Resources\ProductResource;
|
|
use Webkul\Shop\Http\Resources\ProductResource;
|
|
|
|
|
|
|
@@ -17,7 +18,8 @@ class ProductController extends APIController
|
|
|
*/
|
|
*/
|
|
|
public function __construct(
|
|
public function __construct(
|
|
|
protected CategoryRepository $categoryRepository,
|
|
protected CategoryRepository $categoryRepository,
|
|
|
- protected ProductRepository $productRepository
|
|
|
|
|
|
|
+ protected ProductRepository $productRepository,
|
|
|
|
|
+ protected SearchLogService $searchLogService
|
|
|
) {}
|
|
) {}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -44,12 +46,19 @@ class ProductController extends APIController
|
|
|
'visible_individually' => 1,
|
|
'visible_individually' => 1,
|
|
|
]));
|
|
]));
|
|
|
|
|
|
|
|
|
|
+ $this->searchLogService->recordWhenSuggested(
|
|
|
|
|
+ request()->query('suggest'),
|
|
|
|
|
+ $searchData['original_query'],
|
|
|
|
|
+ $query,
|
|
|
|
|
+ $products->total()
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
if (! empty($query)) {
|
|
if (! empty($query)) {
|
|
|
/**
|
|
/**
|
|
|
* Update or create search term only if
|
|
* Update or create search term only if
|
|
|
* there is only one filter that is query param
|
|
* there is only one filter that is query param
|
|
|
*/
|
|
*/
|
|
|
- if (count(request()->except(['mode', 'sort', 'limit'])) == 1) {
|
|
|
|
|
|
|
+ if (count(request()->except(['mode', 'sort', 'limit', 'suggest'])) == 1) {
|
|
|
UpdateCreateSearchTermJob::dispatch([
|
|
UpdateCreateSearchTermJob::dispatch([
|
|
|
'term' => $query,
|
|
'term' => $query,
|
|
|
'results' => $products->total(),
|
|
'results' => $products->total(),
|
|
@@ -67,7 +76,10 @@ class ProductController extends APIController
|
|
|
*/
|
|
*/
|
|
|
protected function resolveSearchQueryData($searchEngine): array
|
|
protected function resolveSearchQueryData($searchEngine): array
|
|
|
{
|
|
{
|
|
|
- if (request()->query('suggest', '') === '0') {
|
|
|
|
|
|
|
+ if (
|
|
|
|
|
+ ! request()->has('suggest')
|
|
|
|
|
+ || request()->query('suggest') !== '0'
|
|
|
|
|
+ ) {
|
|
|
return [
|
|
return [
|
|
|
'original_query' => request()->query('query', ''),
|
|
'original_query' => request()->query('query', ''),
|
|
|
'effective_query' => null,
|
|
'effective_query' => null,
|