Skip to content

Commit

Permalink
Additional filters possibility (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jade-GG authored Aug 25, 2023
1 parent 4ebd513 commit d44c92f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config/rapidez.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,10 @@
'slideover' => 'z-50',
],

// From Magento only "Yes/No, Dropdown, Multiple Select and Price" attribute types
// can be configured as filter. If you'd like to have a filter for an attribute
// with, for example, the type of "Text", you can specify the attribute code here.
'additional_filters' => [
// Attribute codes
],
];
8 changes: 8 additions & 0 deletions src/Models/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Rapidez\Core\Models;

use Illuminate\Database\Eloquent\Casts\Attribute as CastsAttribute;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;
use Rapidez\Core\Models\Scopes\Attribute\OnlyProductAttributesScope;
Expand All @@ -17,6 +18,13 @@ protected static function booting()
static::addGlobalScope(new OnlyProductAttributesScope);
}

protected function filter(): CastsAttribute
{
return CastsAttribute::make(
get: fn ($value) => $value || in_array($this->code, config('rapidez.additional_filters')),
)->shouldCache();
}

public static function getCachedWhere(callable $callback): array
{
if (! $attributes = config('cache.app.attributes.' . config('rapidez.store'))) {
Expand Down

0 comments on commit d44c92f

Please sign in to comment.