Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make and use "filterable" attribute #326

Merged
merged 3 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/rapidez.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,6 @@
'slideover' => 'z-50',
],

// Attribute codes of attributes that need to be filtered but can't be set as filterable in magento
'extra-filters' => [],
Jade-GG marked this conversation as resolved.
Show resolved Hide resolved
];
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.extra-filters')),
)->shouldCache();
}
royduin marked this conversation as resolved.
Show resolved Hide resolved

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