LoadingTrait
Loads parameters and option counts for the eshop filter box.
The eshop has no category_parameter_rel (parameters are global), so unlike Bazaar there is no
per-category aggregation; there is a single question: which parameters actually occur in product
sets visible in the current list (category intersected with eligibility). One aggregation query
answers it and also provides the option counts
(ProductSetManager::fetchParameterValueCounts()).
Table of Contents
Properties
- $countsCache : array<string, array<int, array<string|int, int>>>
- $subtreeProductIdsCache : array<int, int>|null
Methods
- buildContext() : void
- loadParameterGroups() : array<string|int, mixed>
- loadParameters() : array<string|int, ParameterFormItem>
- fetchCounts() : array<int, array<string|int, int>>
- Returns value counts for the list narrowed by the given filters.
- resolveActiveParameterFilters() : array<int, array<int, object>>
- Returns active filters from the URL, grouped by parameter.
- resolveOptionCounts() : array<int, array<string|int, int>>
- Returns product counts per option, narrowed by active filters.
- resolveRangeBounds() : array<int, array{min: float, max: float}>
- Returns slider bounds for range parameters, taken from the already loaded facet counts, so it costs no extra query.
- resolveSubtreeProductIds() : array<int, int>
- Returns product ids in the category subtree, memoized because `ProductSetListTrait` and the filter box ask for the same data, which would otherwise be two raw queries per request.
Properties
$countsCache
private
array<string, array<int, array<string|int, int>>>
$countsCache
= []
counts memoized by filter signature
$subtreeProductIdsCache
private
array<int, int>|null
$subtreeProductIdsCache
= null
memoized category subtree product ids
Methods
buildContext()
protected
buildContext() : void
loadParameterGroups()
protected
loadParameterGroups() : array<string|int, mixed>
Return values
array<string|int, mixed>loadParameters()
protected
loadParameters() : array<string|int, ParameterFormItem>
Return values
array<string|int, ParameterFormItem>fetchCounts()
Returns value counts for the list narrowed by the given filters.
private
fetchCounts(ProductCategory|null $category, array<int, object> $extraFilters) : array<int, array<string|int, int>>
Filters are composed here (eligibility, category, passed facets) and sent to the Api as they are; ProductSetManager::fetchParameterValueCounts() resolves the ids of visible sets itself, because bare scalar ids would not pass the hydrator through the bridge.
Parameters
- $category : ProductCategory|null
- $extraFilters : array<int, object>
Return values
array<int, array<string|int, int>>resolveActiveParameterFilters()
Returns active filters from the URL, grouped by parameter.
private
resolveActiveParameterFilters() : array<int, array<int, object>>
They are built by the same handlers as the list (ParameterTrait), not by an own copy of the rules; otherwise the counts and the list could drift apart, silently.
Return values
array<int, array<int, object>>resolveOptionCounts()
Returns product counts per option, narrowed by active filters.
private
resolveOptionCounts() : array<int, array<string|int, int>>
IMPORTANT: for a facet P all active filters except the filters of P are applied. If P's own
filter applied too, a single-value parameter (brand, diagonal) would show zero everywhere,
because the ticked value and any other value cannot meet on one product; filter_match_all
has the same trap. For other parameters all filters apply, so ticking a port option reduces
processor counts to those that really have that port.
The number of queries is the number of active facets plus one, not one per option.
Return values
array<int, array<string|int, int>> —parameterId => [value => count]
resolveRangeBounds()
Returns slider bounds for range parameters, taken from the already loaded facet counts, so it costs no extra query.
private
resolveRangeBounds(array<int, array<string|int, int>> $counts) : array<int, array{min: float, max: float}>
NOTE: the upper bound is the largest value column value, i.e. the largest lower bound of a
stored range (facets carry no value2). That is enough for a slider, which is a guide and
not validation; the filter itself works with exact values. A module that needs an exact upper
bound fills $context->rangeBounds its own way.
Parameters without numeric values are skipped, so the fields stay two plain numbers.
Parameters
- $counts : array<int, array<string|int, int>>
Return values
array<int, array{min: float, max: float}>resolveSubtreeProductIds()
Returns product ids in the category subtree, memoized because `ProductSetListTrait` and the filter box ask for the same data, which would otherwise be two raw queries per request.
private
resolveSubtreeProductIds(ProductCategory $category) : array<int, int>
Parameters
- $category : ProductCategory