diff --git a/app/Criteria/ProductSearch.php b/app/Criteria/ProductSearch.php index b548657c5..0846f7de5 100644 --- a/app/Criteria/ProductSearch.php +++ b/app/Criteria/ProductSearch.php @@ -10,10 +10,10 @@ class ProductSearch extends Criterion public function query(Builder $query): Builder { return $query->whereFullText([ - 'name', - 'description_html', - 'description_short', - 'search_values', + 'products.name', + 'products.description_html', + 'products.description_short', + 'products.search_values', ], $this->value); } } diff --git a/tests/Feature/ProductSearchDatabaseTest.php b/tests/Feature/ProductSearchDatabaseTest.php index 3ddb0382a..22eacf7a6 100644 --- a/tests/Feature/ProductSearchDatabaseTest.php +++ b/tests/Feature/ProductSearchDatabaseTest.php @@ -80,6 +80,34 @@ public function testIndexIdsSearch($user): void ->assertJsonCount(2, 'data'); } + /** + * @dataProvider authProvider + */ + public function testIndexSearch($user): void + { + $this->{$user}->givePermissionTo('products.show'); + + Product::factory()->create([ + 'public' => true, + 'name' => 'First', + ]); + + Product::factory()->create([ + 'public' => true, + 'created_at' => Carbon::now()->addHour(), + 'name' => 'Second', + ]); + + // This test check if there is no SQL error that 'name' is ambiguous + $this + ->actingAs($this->{$user}) + ->json('GET', '/products', [ + 'search' => 'First', + 'sort' => 'attribute.data-wydania:desc', + ]) + ->assertOk(); + } + /** * @dataProvider authProvider */