Skip to content

Commit

Permalink
Bug/search filter issue master (#404)
Browse files Browse the repository at this point in the history
* Merge master

* Fixing non-detection of filters

* Fix ProductFamily creation

* Apply fixes from StyleCI (#403)

Co-authored-by: Glenn Jacobs <glennjacobs@users.noreply.github.com>

Co-authored-by: Alec <hello@itsalec.co.uk>
Co-authored-by: Glenn Jacobs <glennjacobs@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 23, 2021
1 parent aac0b6d commit 1721d15
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
16 changes: 9 additions & 7 deletions src/Core/Products/Actions/CreateProductFamily.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ public function handle()
{
$productFamily = ProductFamily::create($this->validated());

$attributes = Attribute::system()->get()->map(function ($attribute) {
return $attribute->encoded_id;
})->merge($this->attribute_ids ?? []);
if (is_array($this->attribute_ids)) {
$attributes = Attribute::system()->get()->map(function ($attribute) {
return $attribute->encoded_id;
})->merge($this->attribute_ids ?? []);

AttachModelToAttributes::run([
'model' => $productFamily,
'attribute_ids' => $attributes->toArray(),
]);
AttachModelToAttributes::run([
'model' => $productFamily,
'attribute_ids' => $attributes->toArray(),
]);
}

return $productFamily->load($this->resolveEagerRelations());
}
Expand Down
19 changes: 14 additions & 5 deletions src/Core/Search/Drivers/Elasticsearch/Actions/Searching/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,20 @@ public function handle()
$this->set('index', "{$prefix}_{$index}_{$language}");
}

$this->filters = $this->filters ? collect(explode(',', $this->filters))->mapWithKeys(function ($filter) {
[$label, $value] = explode(':', $filter);

return [$label => $value];
})->toArray() : [];
// Handle request filters
if (! $this->filters) {
// Get our filterable attributes.
$filterable = \GetCandy::attributes()->getFilterable()->pluck('handle')->toArray();
$filterable[] = 'price';

$this->filters = $this->only($filterable);
} else {
$this->filters = $this->filters ? collect(explode(',', $this->filters))->mapWithKeys(function ($filter) {
[$label, $value] = explode(':', $filter);

return [$label => $value];
})->toArray() : [];
}

$this->aggregates = $this->aggregates ?: [];
$this->language = $this->language ?: app()->getLocale();
Expand Down

0 comments on commit 1721d15

Please sign in to comment.