selectContainerFactory = $selectContainerFactory; $this->fullTextSearchCheck = $fullTextSearchCheck; $this->customAttributeFilterCheck = $customAttributeFilterCheck; $this->filtersExtractor = $filtersExtractor; $this->scopeConfig = $scopeConfig; $this->resource = $resource; } /** * Builds SelectContainer with all required data * * @param RequestInterface $request * @return SelectContainer * @throws \DomainException * @throws \InvalidArgumentException * @throws \Magento\Framework\Exception\LocalizedException */ public function buildByRequest(RequestInterface $request) { $nonCustomAttributesFilters = []; $customAttributesFilters = []; $visibilityFilter = null; foreach ($this->filtersExtractor->extractFiltersFromQuery($request->getQuery()) as $filter) { if ($this->customAttributeFilterCheck->isCustom($filter)) { if ($filter->getField() === VisibilityFilter::VISIBILITY_FILTER_FIELD) { $visibilityFilter = clone $filter; } else { $customAttributesFilters[] = clone $filter; } } else { $nonCustomAttributesFilters[] = clone $filter; } } $data = [ 'select' => $this->resource->getConnection()->select(), 'nonCustomAttributesFilters' => $nonCustomAttributesFilters, 'customAttributesFilters' => $customAttributesFilters, 'dimensions' => $request->getDimensions(), 'isFullTextSearchRequired' => $this->fullTextSearchCheck->isRequiredForQuery($request->getQuery()), 'isShowOutOfStockEnabled' => $this->isSetShowOutOfStockFlag(), 'usedIndex' => $request->getIndex() ]; if ($visibilityFilter !== null) { $data['visibilityFilter'] = $visibilityFilter; } return $this->selectContainerFactory->create($data); } /** * Checks if show_out_of_stock flag is enabled in current configuration * * @return bool */ private function isSetShowOutOfStockFlag() { return $this->scopeConfig->isSetFlag( 'cataloginventory/options/show_out_of_stock', ScopeInterface::SCOPE_STORE ); } }