feat(catalog): add is_enabled attribute to categories and filter items accordingly
This commit is contained in:
@@ -15,6 +15,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
'tenant_code',
|
||||
'categoria_id',
|
||||
'nombre',
|
||||
'is_enabled',
|
||||
])]
|
||||
class Category extends Model
|
||||
{
|
||||
@@ -22,6 +23,10 @@ class Category extends Model
|
||||
|
||||
protected $table = 'categorias';
|
||||
|
||||
protected $attributes = [
|
||||
'is_enabled' => true,
|
||||
];
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
@@ -29,6 +34,7 @@ class Category extends Model
|
||||
{
|
||||
return [
|
||||
'categoria_id' => 'integer',
|
||||
'is_enabled' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,15 @@ class FeaturedGroupService
|
||||
{
|
||||
$query = CatalogItem::query()
|
||||
->where('catalog_items.tenant_code', $featuredGroup->tenant_code)
|
||||
->where(function (Builder $query): void {
|
||||
$query
|
||||
->whereDoesntHave('category')
|
||||
->orWhereHas(
|
||||
'category',
|
||||
fn (Builder $categoryQuery): Builder => $categoryQuery
|
||||
->where('is_enabled', true),
|
||||
);
|
||||
})
|
||||
->with([
|
||||
'inventory',
|
||||
'attachments',
|
||||
|
||||
Reference in New Issue
Block a user