On product listing page, I need to rename the label of Sort by Option Position
to Most Popular
.
Below are the two files responsible for sorting
\vendor\magento\module-catalog\Block\Product\ProductList\Toolbar.php
\vendor\magento\module-catalog\Model\Config.php
In Toolbar.php
you can see
$this->_availableOrder = $this->_catalogConfig->getAttributeUsedForSortByArray();
which in turn calls getAttributeUsedForSortByArray()
from Config.php
that returns array of available attributes to sort listing collection.
In Config.php
it has below function where Position label is given
public function getAttributeUsedForSortByArray()
{
$options = ['position' => __('Position')];
foreach ($this->getAttributesUsedForSortBy() as $attribute) {
/* @var $attribute \Magento\Eav\Model\Entity\Attribute\AbstractAttribute */
$options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();
}
return $options;
}
- To change the label do I need to extend Model/Config.php in my
custom theme and change
$options = ['position' => __('Position')];
to$options = ['position' => __('My Custom label')];
? - Can this be done by extending
sorter.phtml
? - Can we change sort by options label from admin ?