I am new to Prestashop and I am trying to add a new "Sort by" field ( where by default you have: "Relevance" , "Name, A to Z" , "Name, Z to A", "Price, low to high", "Price, high to low" )
As you guys know, the functionality is located in the module called: "Ps_facetedsearch" , link here.
I tried:
- Editing the module files, this works, but I can't upgrade the module anymore if I want to keep the functionality.
- Overriding, but can't seem to get it working, it still uses the same old module, not the overriden one.
So my questions are:
- How can you add the additional "Sort by" field in the products listing (front) in a most elegant/easiest way possible?I would love to hear for any other approaches to this problem.
- Can you do this without override/s, if you, for e.g, have bought another module that overrides the main module ( "Ps_facetedsearch", so that two overrides would not conflict)
Any tips are appreciated!!!
PrestaShop version: 1.7.4.2
The lines in the Ps_facetedsearch module that I need to copy/paste in order to add an additional "Sort by" field:
private function getAvailableSortOrders()
{
return [
(new SortOrder('product', 'position', 'asc'))->setLabel(
$this->module->getTranslator()->trans('Relevance', array(), 'Modules.Facetedsearch.Shop')
),
(new SortOrder('product', 'name', 'asc'))->setLabel(
$this->module->getTranslator()->trans('Name, A to Z', array(), 'Shop.Theme.Catalog')
),
(new SortOrder('product', 'name', 'desc'))->setLabel(
$this->module->getTranslator()->trans('Name, Z to A', array(), 'Shop.Theme.Catalog')
),
(new SortOrder('product', 'price', 'asc'))->setLabel(
$this->module->getTranslator()->trans('Price, low to high', array(), 'Shop.Theme.Catalog')
),
(new SortOrder('product', 'price', 'desc'))->setLabel(
$this->module->getTranslator()->trans('Price, high to low', array(), 'Shop.Theme.Catalog')
)
// copy and paste here for another one, but lose the upgradability
// of a module.
];
}
Found in Ps_FacetedsearchProductSearchProvider.php (lines 117-136)