Skip to content

Commit

Permalink
Advancements
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed Jun 21, 2024
1 parent 1074251 commit ddd5f37
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Foundation/Search/ProductSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Vanilo\Channel\Contracts\Channel;
use Vanilo\MasterProduct\Contracts\MasterProduct;
use Vanilo\MasterProduct\Models\MasterProductProxy;
use Vanilo\MasterProduct\Models\MasterProductVariantProxy;
use Vanilo\Product\Contracts\Product;
use Vanilo\Product\Models\ProductProxy;
use Vanilo\Product\Models\ProductStateProxy;
Expand All @@ -42,6 +43,8 @@ class ProductSearch

protected Builder $masterProductQuery;

protected ?Builder $variantQuery = null;

protected ?string $orderBy = null;

public function __construct()
Expand Down Expand Up @@ -86,6 +89,10 @@ public function withinTaxon(Taxon $taxon): self
$query->where('id', $taxon->id);
});

if (null !== $this->variantQuery) {

}

return $this;
}

Expand Down Expand Up @@ -152,6 +159,7 @@ public function nameContains(string $term): self
{
$this->productQuery->where('name', 'like', "%$term%");
$this->masterProductQuery->where('name', 'like', "%$term%");
$this->variantQuery?->where('name', 'like', "%$term%");

return $this;
}
Expand Down Expand Up @@ -333,7 +341,8 @@ public function getSearcher(string|array $columns = null): Searcher

return $this->searcher
->add($this->productQuery, $columns, $orderBy)
->add($this->masterProductQuery, $columns, $orderBy);
->add($this->masterProductQuery, $columns, $orderBy)
->when(null !== $this->variantQuery, fn($search) => $search->add($this->variantQuery));
}

public function simplePaginate(int $perPage = 15, array $columns = ['*'], string $pageName = 'page', int $page = null): Paginator
Expand All @@ -354,6 +363,8 @@ public function getResults(int $limit = null): Collection

public function includeVariants(): self
{
$this->variantQuery = MasterProductVariantProxy::query();

return $this;
}
}

0 comments on commit ddd5f37

Please sign in to comment.