Skip to content

Commit 3e607c9

Browse files
authored
MAGETWO-75329: Make default sorting fully working when setup on category level #10937
2 parents 9b68524 + 36590b4 commit 3e607c9

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class ProductList
3030
*/
3131
protected $scopeConfig;
3232

33+
/**
34+
* @var \Magento\Framework\Registry
35+
*/
36+
private $coreRegistry;
37+
3338
/**
3439
* Default limits per page
3540
*
@@ -41,9 +46,11 @@ class ProductList
4146
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
4247
*/
4348
public function __construct(
44-
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
49+
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
50+
\Magento\Framework\Registry $coreRegistry = null
4551
) {
4652
$this->scopeConfig = $scopeConfig;
53+
$this->coreRegistry = $coreRegistry ?: \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Framework\Registry::class);
4754
}
4855

4956
/**
@@ -97,6 +104,11 @@ public function getDefaultViewMode($options = [])
97104
*/
98105
public function getDefaultSortField()
99106
{
107+
$currentCategory = $this->coreRegistry->registry('current_category');
108+
if ($currentCategory) {
109+
return $currentCategory->getDefaultSortBy();
110+
}
111+
100112
return $this->scopeConfig->getValue(
101113
\Magento\Catalog\Model\Config::XML_PATH_LIST_DEFAULT_SORT_BY,
102114
\Magento\Store\Model\ScopeInterface::SCOPE_STORE

0 commit comments

Comments
 (0)