49 private $resourceConnection;
54 private $conditionManager;
59 private $storeManager;
79 $this->conditionManager = $conditionManager;
96 if (
$type !== self::FILTER_BY_JOIN &&
$type !== self::FILTER_BY_WHERE) {
97 throw new \InvalidArgumentException(sprintf(
'Invalid filter type: %s',
$type));
102 $type === self::FILTER_BY_JOIN
103 ? $this->applyFilterByJoin($filter,
$select)
104 : $this->applyFilterByWhere($filter,
$select);
120 $mainTableAlias = $this->extractTableAliasFromSelect(
$select);
123 [
'visibility_filter' => $this->resourceConnection->getTableName(
'catalog_product_index_eav')],
124 $this->conditionManager->combineQueries(
126 sprintf(
'%s.entity_id = visibility_filter.entity_id', $mainTableAlias),
127 $this->conditionManager->generateCondition(
128 'visibility_filter.attribute_id',
130 $this->getVisibilityAttributeId()
132 $this->conditionManager->generateCondition(
133 'visibility_filter.value',
134 is_array($filter->getValue()) ?
'in' :
'=',
137 $this->conditionManager->generateCondition(
138 'visibility_filter.store_id',
140 $this->storeManager->getStore()->getId()
160 $mainTableAlias = $this->extractTableAliasFromSelect(
$select);
163 $this->conditionManager->combineQueries(
165 $this->conditionManager->generateCondition(
166 sprintf(
'%s.attribute_id', $mainTableAlias),
168 $this->getVisibilityAttributeId()
170 $this->conditionManager->generateCondition(
171 sprintf(
'%s.value', $mainTableAlias),
172 is_array($filter->getValue()) ?
'in' :
'=',
175 $this->conditionManager->generateCondition(
176 sprintf(
'%s.store_id', $mainTableAlias),
178 $this->storeManager->getStore()->getId()
192 private function getVisibilityAttributeId()
194 $attr = $this->eavConfig->getAttribute(
196 self::VISIBILITY_FILTER_FIELD
199 return (
int)
$attr->getId();
208 private function extractTableAliasFromSelect(Select
$select)
210 $fromArr = array_filter(
212 function ($fromPart) {
217 return $fromArr ? array_keys($fromArr)[0] :
null;
apply(Select $select, FilterInterface $filter, $type)
__construct(ResourceConnection $resourceConnection, ConditionManager $conditionManager, StoreManagerInterface $storeManager, EavConfig $eavConfig)
const VISIBILITY_FILTER_FIELD