Skip to content

Commit cb80c2b

Browse files
committed
Check default sorting in category configuration first, before checking it in configuration. #10772
1 parent e649b4c commit cb80c2b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

app/code/Magento/Catalog/Helper/Product/ProductList.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class ProductList
2929
* @var \Magento\Framework\App\Config\ScopeConfigInterface
3030
*/
3131
protected $scopeConfig;
32+
protected $coreRegistry;
3233

3334
/**
3435
* Default limits per page
@@ -41,9 +42,11 @@ class ProductList
4142
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
4243
*/
4344
public function __construct(
44-
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
45+
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
46+
\Magento\Framework\Registry $coreRegistry
4547
) {
4648
$this->scopeConfig = $scopeConfig;
49+
$this->coreRegistry = $coreRegistry;
4750
}
4851

4952
/**
@@ -97,6 +100,12 @@ public function getDefaultViewMode($options = [])
97100
*/
98101
public function getDefaultSortField()
99102
{
103+
$currentCategory = $this->coreRegistry->registry('current_category');
104+
if($currentCategory){
105+
$currentCategorySortBy = $currentCategory->getDefaultSortBy();
106+
return $currentCategorySortBy;
107+
}
108+
100109
return $this->scopeConfig->getValue(
101110
\Magento\Catalog\Model\Config::XML_PATH_LIST_DEFAULT_SORT_BY,
102111
\Magento\Store\Model\ScopeInterface::SCOPE_STORE

0 commit comments

Comments
 (0)