6 declare(strict_types=1);
10 use Magento\CatalogSearch\Model\Adapter\Mysql\Aggregation\DataProvider\SelectBuilderForAttribute\
11 ApplyStockConditionToSelect;
33 private $scopeResolver;
43 private $applyStockConditionToSelect;
48 private $customerSession;
70 $this->scopeResolver = $scopeResolver;
71 $this->applyStockConditionToSelect = $applyStockConditionToSelect;
72 $this->customerSession = $customerSession;
73 $this->scopeConfig = $scopeConfig;
85 if (
$attribute->getAttributeCode() ===
'price') {
87 $store = $this->scopeResolver->getScope($currentScope);
89 throw new \RuntimeException(
'Illegal scope resolved');
91 $table = $this->resource->getTableName(
'catalog_product_index_price');
94 ->where(
'main_table.customer_group_id = ?', $this->customerSession->getCustomerGroupId())
95 ->where(
'main_table.website_id = ?',
$store->getWebsiteId());
97 $currentScopeId = $this->scopeResolver->getScope($currentScope)->getId();
98 $table = $this->resource->getTableName(
99 'catalog_product_index_eav' . (
$attribute->getBackendType() ===
'decimal' ?
'_decimal' :
'')
102 $subSelect->from([
'main_table' =>
$table], [
'main_table.entity_id',
'main_table.value'])
104 ->where(
'main_table.attribute_id = ?',
$attribute->getAttributeId())
105 ->where(
'main_table.store_id = ? ', $currentScopeId);
106 if ($this->isAddStockFilter()) {
107 $subSelect = $this->applyStockConditionToSelect->execute($subSelect);
110 $parentSelect = $this->resource->getConnection()->select();
111 $parentSelect->from([
'main_table' => $subSelect], [
'main_table.value']);
121 private function isAddStockFilter()
123 $isShowOutOfStock = $this->scopeConfig->isSetFlag(
124 'cataloginventory/options/show_out_of_stock',
128 return false === $isShowOutOfStock;
__construct(ResourceConnection $resource, ScopeResolverInterface $scopeResolver, ApplyStockConditionToSelect $applyStockConditionToSelect, Session $customerSession, ScopeConfigInterface $scopeConfig)