refactor(catalog): extract visible items query

This commit is contained in:
2026-08-25 09:02:54 -03:00
parent e27f7bb166
commit d9635d47ba
4 changed files with 88 additions and 59 deletions

View File

@@ -24,7 +24,7 @@ class CatalogService
{
public function __construct(
protected AttachmentService $attachmentService,
private readonly CatalogItemAllowanceService $allowances,
private readonly VisibleCatalogItemsQuery $visibleCatalogItems,
) {}
/**
@@ -262,8 +262,8 @@ class CatalogService
'bundleComponents.variant.catalogItem',
]);
$paginator = $this->allowances
->applyProductVisibilityPolicy($query)
$paginator = $this->visibleCatalogItems
->apply($query)
->orderByRaw(
'CASE WHEN LOWER(nombre) = ? THEN 0 WHEN LOWER(nombre) LIKE ? THEN 1 ELSE 2 END',
[$normalizedTerm, $startsWithPattern],
@@ -299,8 +299,8 @@ class CatalogService
'bundleComponents.variant.catalogItem',
]);
return $this->allowances
->applyProductVisibilityPolicy($query)
return $this->visibleCatalogItems
->apply($query)
->orderBy('nombre')
->paginate(perPage: $perPage, pageName: 'page', page: $page);
}