Skip to content

Commit

Permalink
Added test case for search in variants as well
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed Jun 21, 2024
1 parent f833f47 commit 1074251
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Foundation/Search/ProductSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,9 @@ public function getResults(int $limit = null): Collection
{
return is_null($limit) ? $this->getSearcher()->search() : $this->getSearcher()->simplePaginate($limit)->search()->getCollection();
}

public function includeVariants(): self
{
return $this;
}
}
22 changes: 22 additions & 0 deletions src/Foundation/Tests/ProductSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Konekt\Search\Searcher;
use Vanilo\Foundation\Models\MasterProduct;
use Vanilo\Foundation\Models\MasterProductVariant;
use Vanilo\Foundation\Models\Product;
use Vanilo\Foundation\Models\Taxon;
use Vanilo\Foundation\Search\ProductSearch;
Expand Down Expand Up @@ -691,4 +692,25 @@ public function it_can_be_extended_using_macros()
{
$finder = new ProductSearch();
}

/** @test */
public function it_can_optionally_include_variants()
{
factory(Product::class, 7)->create([
'state' => ProductState::ACTIVE,
]);
$master = factory(MasterProduct::class)->create([
'state' => ProductState::ACTIVE,
]);
factory(MasterProductVariant::class, 3)->create([
'state' => ProductState::ACTIVE,
'master_product_id' => $master->id,
]);

$this->assertCount(8, (new ProductSearch())->getResults());

$finder = new ProductSearch();
$finder->includeVariants();
$this->assertCount(11, $finder->getResults());
}
}

0 comments on commit 1074251

Please sign in to comment.