diff --git a/vendor/magento/module-catalog-inventory/Model/ResourceModel/StockStatusFilter.php b/vendor/magento/module-catalog-inventory/Model/ResourceModel/StockStatusFilter.php index 3922670f175..1c0d18f786f 100644 --- a/vendor/magento/module-catalog-inventory/Model/ResourceModel/StockStatusFilter.php +++ b/vendor/magento/module-catalog-inventory/Model/ResourceModel/StockStatusFilter.php @@ -10,10 +10,8 @@ namespace Magento\CatalogInventory\Model\ResourceModel; use Magento\CatalogInventory\Api\Data\StockStatusInterface; use Magento\CatalogInventory\Api\StockConfigurationInterface; use Magento\CatalogInventory\Model\Stock; -use Magento\CatalogInventory\Model\StockStatusApplierInterface; use Magento\Framework\App\ResourceConnection; use Magento\Framework\DB\Select; -use Magento\Framework\App\ObjectManager; /** * Generic in-stock status filter @@ -32,25 +30,16 @@ class StockStatusFilter implements StockStatusFilterInterface */ private $stockConfiguration; - /** - * @var StockStatusApplierInterface - */ - private $stockStatusApplier; - /** * @param ResourceConnection $resource * @param StockConfigurationInterface $stockConfiguration - * @param StockStatusApplierInterface|null $stockStatusApplier */ public function __construct( ResourceConnection $resource, - StockConfigurationInterface $stockConfiguration, - ?StockStatusApplierInterface $stockStatusApplier = null + StockConfigurationInterface $stockConfiguration ) { $this->resource = $resource; $this->stockConfiguration = $stockConfiguration; - $this->stockStatusApplier = $stockStatusApplier - ?? ObjectManager::getInstance()->get(StockStatusApplierInterface::class); } /** @@ -79,13 +68,7 @@ class StockStatusFilter implements StockStatusFilterInterface implode(' AND ', $joinCondition), [] ); - - if ($this->stockStatusApplier->hasSearchResultApplier()) { - $select->columns(["{$stockStatusTableAlias}.stock_status AS is_salable"]); - } else { - $select->where("{$stockStatusTableAlias}.stock_status = ?", StockStatusInterface::STATUS_IN_STOCK); - } - + $select->where("{$stockStatusTableAlias}.stock_status = ?", StockStatusInterface::STATUS_IN_STOCK); return $select; } } diff --git a/vendor/magento/module-catalog-inventory/Model/StockStatusApplier.php b/vendor/magento/module-catalog-inventory/Model/StockStatusApplier.php index 77d85034f14..597b8ad9160 100644 --- a/vendor/magento/module-catalog-inventory/Model/StockStatusApplier.php +++ b/vendor/magento/module-catalog-inventory/Model/StockStatusApplier.php @@ -9,6 +9,9 @@ namespace Magento\CatalogInventory\Model; /** * Search Result Applier getters and setters + * + * @deprecated - as the implementation has been reverted during the fix of ACP2E-748 + * @see \Magento\InventoryCatalog\Plugin\Catalog\Model\ResourceModel\Product\CollectionPlugin */ class StockStatusApplier implements StockStatusApplierInterface { @@ -23,6 +26,8 @@ class StockStatusApplier implements StockStatusApplierInterface * Set flag, if the request is originated from SearchResultApplier * * @param bool $status + * @deprecated + * @see \Magento\InventoryCatalog\Plugin\Catalog\Model\ResourceModel\Product\CollectionPlugin::beforeSetOrder */ public function setSearchResultApplier(bool $status): void { @@ -33,6 +38,8 @@ class StockStatusApplier implements StockStatusApplierInterface * Get flag, if the request is originated from SearchResultApplier * * @return bool + * @deprecated + * @see \Magento\InventoryCatalog\Plugin\Catalog\Model\ResourceModel\Product\CollectionPlugin::beforeSetOrder */ public function hasSearchResultApplier() : bool { diff --git a/vendor/magento/module-catalog-inventory/Model/StockStatusApplierInterface.php b/vendor/magento/module-catalog-inventory/Model/StockStatusApplierInterface.php index db5e6cff742..791ad9a0795 100644 --- a/vendor/magento/module-catalog-inventory/Model/StockStatusApplierInterface.php +++ b/vendor/magento/module-catalog-inventory/Model/StockStatusApplierInterface.php @@ -9,6 +9,9 @@ namespace Magento\CatalogInventory\Model; /** * Search Result Applier interface. + * + * @deprecated - as the implementation has been reverted during the fix of ACP2E-748 + * @see \Magento\InventoryCatalog\Plugin\Catalog\Model\ResourceModel\Product\CollectionPlugin */ interface StockStatusApplierInterface { @@ -17,6 +20,8 @@ interface StockStatusApplierInterface * Set flag, if the request is originated from SearchResultApplier * * @param bool $status + * @deprecated + * @see \Magento\InventoryCatalog\Plugin\Catalog\Model\ResourceModel\Product\CollectionPlugin::beforeSetOrder */ public function setSearchResultApplier(bool $status): void; @@ -24,6 +29,8 @@ interface StockStatusApplierInterface * Get flag, if the request is originated from SearchResultApplier * * @return bool + * @deprecated + * @see \Magento\InventoryCatalog\Plugin\Catalog\Model\ResourceModel\Product\CollectionPlugin::beforeSetOrder */ public function hasSearchResultApplier() : bool; } diff --git a/vendor/magento/module-elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php b/vendor/magento/module-elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php index 97cb92ab3b0..2355075bf41 100644 --- a/vendor/magento/module-elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php +++ b/vendor/magento/module-elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php @@ -6,20 +6,12 @@ namespace Magento\Elasticsearch\Model\ResourceModel\Fulltext\Collection; -use Magento\Catalog\Api\Data\ProductInterface; -use Magento\CatalogInventory\Model\StockStatusApplierInterface; -use Magento\CatalogInventory\Model\ResourceModel\StockStatusFilterInterface; use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplierInterface; use Magento\Framework\Api\Search\SearchResultInterface; -use Magento\Framework\App\Config\ScopeConfigInterface; -use Magento\Framework\App\ObjectManager; use Magento\Framework\Data\Collection; -use Magento\Framework\EntityManager\MetadataPool; /** * Resolve specific attributes for search criteria. - * - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class SearchResultApplier implements SearchResultApplierInterface { @@ -43,56 +35,22 @@ class SearchResultApplier implements SearchResultApplierInterface */ private $currentPage; - /** - * @var ScopeConfigInterface - */ - private $scopeConfig; - - /** - * @var MetadataPool - */ - private $metadataPool; - - /** - * @var StockStatusFilterInterface - */ - private $stockStatusFilter; - - /** - * @var StockStatusApplierInterface - */ - private $stockStatusApplier; - /** * @param Collection $collection * @param SearchResultInterface $searchResult * @param int $size * @param int $currentPage - * @param ScopeConfigInterface|null $scopeConfig - * @param MetadataPool|null $metadataPool - * @param StockStatusFilterInterface|null $stockStatusFilter - * @param StockStatusApplierInterface|null $stockStatusApplier */ public function __construct( Collection $collection, SearchResultInterface $searchResult, int $size, - int $currentPage, - ?ScopeConfigInterface $scopeConfig = null, - ?MetadataPool $metadataPool = null, - ?StockStatusFilterInterface $stockStatusFilter = null, - ?StockStatusApplierInterface $stockStatusApplier = null + int $currentPage ) { $this->collection = $collection; $this->searchResult = $searchResult; $this->size = $size; $this->currentPage = $currentPage; - $this->scopeConfig = $scopeConfig ?? ObjectManager::getInstance()->get(ScopeConfigInterface::class); - $this->metadataPool = $metadataPool ?? ObjectManager::getInstance()->get(MetadataPool::class); - $this->stockStatusFilter = $stockStatusFilter - ?? ObjectManager::getInstance()->get(StockStatusFilterInterface::class); - $this->stockStatusApplier = $stockStatusApplier - ?? ObjectManager::getInstance()->get(StockStatusApplierInterface::class); } /** @@ -105,13 +63,10 @@ class SearchResultApplier implements SearchResultApplierInterface return; } - $ids = $this->getProductIdsBySaleability(); - - if (count($ids) == 0) { - $items = $this->sliceItems($this->searchResult->getItems(), $this->size, $this->currentPage); - foreach ($items as $item) { - $ids[] = (int)$item->getId(); - } + $items = $this->sliceItems($this->searchResult->getItems(), $this->size, $this->currentPage); + $ids = []; + foreach ($items as $item) { + $ids[] = (int)$item->getId(); } $orderList = implode(',', $ids); $this->collection->getSelect() @@ -160,127 +115,4 @@ class SearchResultApplier implements SearchResultApplierInterface { return ($pageNumber - 1) * $pageSize; } - /** - * Fetch filtered product ids sorted by the saleability and other applied sort orders - * - * @return array - */ - private function getProductIdsBySaleability(): array - { - $ids = []; - - if (!$this->hasShowOutOfStockStatus()) { - return $ids; - } - - if ($this->collection->getFlag('has_stock_status_filter') - || $this->collection->getFlag('has_category_filter')) { - $categoryId = null; - $searchCriteria = $this->searchResult->getSearchCriteria(); - foreach ($searchCriteria->getFilterGroups() as $filterGroup) { - foreach ($filterGroup->getFilters() as $filter) { - if ($filter->getField() === 'category_ids') { - $categoryId = $filter->getValue(); - break 2; - } - } - } - - if ($categoryId) { - $resultSet = $this->categoryProductByCustomSortOrder($categoryId); - foreach ($resultSet as $item) { - $ids[] = (int)$item['entity_id']; - } - } - } - - return $ids; - } - - /** - * Fetch product resultset by custom sort orders - * - * @param int $categoryId - * @return array - * @throws \Magento\Framework\Exception\LocalizedException - * @throws \Exception - */ - private function categoryProductByCustomSortOrder(int $categoryId): array - { - $storeId = $this->collection->getStoreId(); - $searchCriteria = $this->searchResult->getSearchCriteria(); - $sortOrders = $searchCriteria->getSortOrders() ?? []; - $sortOrders = array_merge(['is_salable' => \Magento\Framework\DB\Select::SQL_DESC], $sortOrders); - - $connection = $this->collection->getConnection(); - $query = clone $connection->select() - ->reset(\Magento\Framework\DB\Select::ORDER) - ->reset(\Magento\Framework\DB\Select::LIMIT_COUNT) - ->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET) - ->reset(\Magento\Framework\DB\Select::COLUMNS); - $query->from( - ['e' => $this->collection->getTable('catalog_product_entity')], - ['e.entity_id'] - ); - $this->stockStatusApplier->setSearchResultApplier(true); - $query = $this->stockStatusFilter->execute($query, 'e', 'stockItem'); - $query->join( - ['cat_index' => $this->collection->getTable('catalog_category_product_index_store' . $storeId)], - 'cat_index.product_id = e.entity_id' - . ' AND cat_index.category_id = ' . $categoryId - . ' AND cat_index.store_id = ' . $storeId, - ['cat_index.position'] - ); - foreach ($sortOrders as $field => $dir) { - if ($field === 'name') { - $entityTypeId = $this->collection->getEntity()->getTypeId(); - $entityMetadata = $this->metadataPool->getMetadata(ProductInterface::class); - $linkField = $entityMetadata->getLinkField(); - $query->joinLeft( - ['product_var' => $this->collection->getTable('catalog_product_entity_varchar')], - "product_var.{$linkField} = e.{$linkField} AND product_var.attribute_id = - (SELECT attribute_id FROM eav_attribute WHERE entity_type_id={$entityTypeId} - AND attribute_code='name')", - ['product_var.value AS name'] - ); - } elseif ($field === 'price') { - $query->joinLeft( - ['price_index' => $this->collection->getTable('catalog_product_index_price')], - 'price_index.entity_id = e.entity_id' - . ' AND price_index.customer_group_id = 0' - . ' AND price_index.website_id = (Select website_id FROM store WHERE store_id = ' - . $storeId . ')', - ['price_index.max_price AS price'] - ); - } - $columnFilters = []; - $columnsParts = $query->getPart('columns'); - foreach ($columnsParts as $columns) { - $columnFilters[] = $columns[2] ?? $columns[1]; - } - if (in_array($field, $columnFilters, true)) { - $query->order(new \Zend_Db_Expr("{$field} {$dir}")); - } - } - - $query->limit( - $searchCriteria->getPageSize(), - $searchCriteria->getCurrentPage() * $searchCriteria->getPageSize() - ); - - return $connection->fetchAssoc($query) ?? []; - } - - /** - * Returns if display out of stock status set or not in catalog inventory - * - * @return bool - */ - private function hasShowOutOfStockStatus(): bool - { - return (bool) $this->scopeConfig->getValue( - \Magento\CatalogInventory\Model\Configuration::XML_PATH_SHOW_OUT_OF_STOCK, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - } }