From 1721d15610597bf408eefc7ee123e8015412df16 Mon Sep 17 00:00:00 2001 From: Glenn Jacobs Date: Wed, 23 Jun 2021 15:54:56 +0100 Subject: [PATCH] Bug/search filter issue master (#404) * Merge master * Fixing non-detection of filters * Fix ProductFamily creation * Apply fixes from StyleCI (#403) Co-authored-by: Glenn Jacobs Co-authored-by: Alec Co-authored-by: Glenn Jacobs --- .../Products/Actions/CreateProductFamily.php | 16 +++++++++------- .../Actions/Searching/Search.php | 19 ++++++++++++++----- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/Core/Products/Actions/CreateProductFamily.php b/src/Core/Products/Actions/CreateProductFamily.php index 42017bb88..4b12bf448 100644 --- a/src/Core/Products/Actions/CreateProductFamily.php +++ b/src/Core/Products/Actions/CreateProductFamily.php @@ -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()); } diff --git a/src/Core/Search/Drivers/Elasticsearch/Actions/Searching/Search.php b/src/Core/Search/Drivers/Elasticsearch/Actions/Searching/Search.php index e22200b3d..1a693d2d7 100644 --- a/src/Core/Search/Drivers/Elasticsearch/Actions/Searching/Search.php +++ b/src/Core/Search/Drivers/Elasticsearch/Actions/Searching/Search.php @@ -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();