Skip to content

Commit

Permalink
Added the withinChannel[s] methods to the ProductSearch class
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed Sep 7, 2023
1 parent 7912799 commit 15f8763
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Added the `mapInto()` method to the `RelationAdjustmentCollection` class, which forwards the call to the underlying Eloquent collection
- Added the `Channelable` behavior to Foundation Product, MasterProduct and Taxonomy classes
- Added and extended Foundation Channel model that contains the known relationships to the "channelable" models
- Added the `withinChannel[s]` methods to the ProductSearch class

## 3.x Series

Expand Down
20 changes: 20 additions & 0 deletions src/Foundation/Search/ProductSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Illuminate\Support\Collection;
use Konekt\Search\Facades\Search;
use Konekt\Search\Searcher;
use Vanilo\Channel\Contracts\Channel;
use Vanilo\Foundation\Models\Taxon;
use Vanilo\MasterProduct\Contracts\MasterProduct;
use Vanilo\MasterProduct\Models\MasterProductProxy;
Expand Down Expand Up @@ -123,6 +124,25 @@ public function orWithinTaxons(array $taxons): self
return $this;
}

public function withinChannel(Channel $channel): self
{
return $this->withinChannels($channel);
}

public function withinChannels(Channel ...$channels): self
{
$channelIds = collect($channels)->pluck('id');

$this->productQuery->whereHas('channels', function ($query) use ($channelIds) {
$query->whereIn('id', $channelIds);
});
$this->masterProductQuery->whereHas('channels', function ($query) use ($channelIds) {
$query->whereIn('id', $channelIds);
});

return $this;
}

public function nameContains(string $term): self
{
$this->productQuery->where('name', 'like', "%$term%");
Expand Down

0 comments on commit 15f8763

Please sign in to comment.