-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Issue 36096: Layered Navigation does not filter products properly #36102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.4-develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,22 @@ | |
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\AdvancedSearch\Model\ResourceModel; | ||
|
||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb; | ||
use Magento\Framework\Search\Request\IndexScopeResolverInterface; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\Framework\Model\ResourceModel\Db\Context; | ||
use Magento\Framework\EntityManager\MetadataPool; | ||
use Magento\Catalog\Api\Data\CategoryInterface; | ||
use Magento\Catalog\Model\Indexer\Category\Product\AbstractAction; | ||
use Magento\Catalog\Model\Indexer\Product\Price\DimensionCollectionFactory; | ||
use Magento\Framework\App\ObjectManager; | ||
use Magento\Framework\EntityManager\MetadataPool; | ||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb; | ||
use Magento\Framework\Model\ResourceModel\Db\Context; | ||
use Magento\Framework\Search\Request\Dimension; | ||
use Magento\Catalog\Model\Indexer\Category\Product\AbstractAction; | ||
use Magento\Framework\Search\Request\IndexScopeResolverInterface; | ||
use Magento\Framework\Search\Request\IndexScopeResolverInterface as TableResolver; | ||
use Magento\Catalog\Model\Indexer\Product\Price\DimensionCollectionFactory; | ||
use Magento\Store\Model\Indexer\WebsiteDimensionProvider; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
|
||
/** | ||
* @api | ||
|
@@ -150,6 +152,63 @@ public function getPriceIndexData($productIds, $storeId) | |
return $priceProductsIndexData[$websiteId]; | ||
} | ||
|
||
/** | ||
* Return array of inventory data products | ||
* | ||
* @param null|array $productIds | ||
* @return array | ||
* @since 100.1.0 | ||
*/ | ||
protected function _getCatalogProductInventoryData($productIds = null) | ||
{ | ||
$connection = $this->getConnection(); | ||
$catalogProductIndexInventorySelect = []; | ||
|
||
foreach ($this->dimensionCollectionFactory->create() as $dimensions) { | ||
if (!isset($dimensions[WebsiteDimensionProvider::DIMENSION_NAME]) || | ||
$this->websiteId === null || | ||
$dimensions[WebsiteDimensionProvider::DIMENSION_NAME]->getValue() === $this->websiteId) { | ||
$select = $connection->select()->from( | ||
$this->tableResolver->resolve('cataloginventory_stock_status', $dimensions), | ||
['product_id', 'website_id', 'stock_status'] | ||
); | ||
if ($productIds) { | ||
$select->where('product_id IN (?)', $productIds); | ||
} | ||
$catalogProductIndexInventorySelect[] = $select; | ||
} | ||
} | ||
|
||
$catalogProductIndexInventoryUnionSelect = $connection->select()->union($catalogProductIndexInventorySelect); | ||
|
||
$result = []; | ||
foreach ($connection->fetchAll($catalogProductIndexInventoryUnionSelect) as $row) { | ||
$result[$row['website_id']][$row['product_id']] = (int) $row['stock_status']; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Retrieve inventory data for product | ||
* | ||
* @param null|array $productIds | ||
* @param int $websiteId | ||
* @return array | ||
*/ | ||
public function getInventoryIndexData($productIds, $websiteId = null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. introduce the public function make the Semantic test failed. @sidolov Can you give us some advice about that ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Backward capability don't allow introduce new public methods to class marked as |
||
{ | ||
$this->websiteId = $websiteId; | ||
$inventoryProductsIndexData = $this->_getCatalogProductInventoryData($productIds); | ||
$this->websiteId = null; | ||
|
||
if (!isset($inventoryProductsIndexData[(int) $websiteId])) { | ||
return []; | ||
} | ||
|
||
return $inventoryProductsIndexData[(int) $websiteId]; | ||
} | ||
|
||
/** | ||
* Prepare system index data for products. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Elasticsearch\SearchAdapter\Query\Builder; | ||
|
||
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeProvider; | ||
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\ResolverInterface | ||
as FieldNameResolver; | ||
use Magento\Elasticsearch\Model\Adapter\FieldMapperInterface; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\Search\RequestInterface; | ||
|
||
/** | ||
|
@@ -41,6 +44,11 @@ class Sort | |
*/ | ||
private $fieldNameResolver; | ||
|
||
/** | ||
* @var ScopeConfigInterface | ||
*/ | ||
private $scopeConfig; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
|
@@ -54,17 +62,20 @@ class Sort | |
/** | ||
* @param AttributeProvider $attributeAdapterProvider | ||
* @param FieldNameResolver $fieldNameResolver | ||
* @param ScopeConfigInterface $scopeConfig | ||
* @param array $skippedFields | ||
* @param array $map | ||
*/ | ||
public function __construct( | ||
AttributeProvider $attributeAdapterProvider, | ||
FieldNameResolver $fieldNameResolver, | ||
ScopeConfigInterface $scopeConfig, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
ScopeConfigInterface $scopeConfig = null and: $this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class); |
||
array $skippedFields = [], | ||
array $map = [] | ||
) { | ||
$this->attributeAdapterProvider = $attributeAdapterProvider; | ||
$this->fieldNameResolver = $fieldNameResolver; | ||
$this->scopeConfig = $scopeConfig; | ||
$this->skippedFields = array_merge(self::DEFAULT_SKIPPED_FIELDS, $skippedFields); | ||
$this->map = array_merge(self::DEFAULT_MAP, $map); | ||
} | ||
|
@@ -80,7 +91,8 @@ public function __construct( | |
*/ | ||
public function getSort(RequestInterface $request) | ||
{ | ||
$sorts = []; | ||
$sorts = $this->getSortBySaleability(); | ||
|
||
/** | ||
* Temporary solution for an existing interface of a fulltext search request in Backward compatibility purposes. | ||
* Scope to split Search request interface on two different 'Search' and 'Fulltext Search' contains in MC-16461. | ||
|
@@ -124,4 +136,39 @@ public function getSort(RequestInterface $request) | |
|
||
return $sorts; | ||
} | ||
|
||
/** | ||
* Prepare sort by saleability. | ||
* | ||
* @return array | ||
*/ | ||
public function getSortBySaleability() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. introduce the public function. @sidolov Can you give us some advice about that ? |
||
{ | ||
$sorts = []; | ||
|
||
if ($this->hasShowOutOfStockStatus()) { | ||
$attribute = $this->attributeAdapterProvider->getByAttributeCode('is_salable'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should declare the constant for the |
||
$fieldName = $this->fieldNameResolver->getFieldName($attribute); | ||
$sorts[] = [ | ||
$fieldName => [ | ||
'order' => 'desc' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
] | ||
]; | ||
} | ||
|
||
return $sorts; | ||
} | ||
|
||
/** | ||
* 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 | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be private function
_getCatalogProductInventoryData
change togetCatalogProductInventoryData
as Magento standard code.