philbauch Posted December 27, 2019 Share Posted December 27, 2019 Hi, I wonder if there's an option to add some "Order by date added" to the order dropdown in a product list. Or as a filter in facetted search (e.g. "New products" Usually you always want to show your latest arrivals first, but PS orders obviously by id ASC, which means that oldest products are showing first. Any ideas welcome, thanks in advance, Phil Link to comment Share on other sites More sharing options...
PCQUATRO Posted December 28, 2019 Share Posted December 28, 2019 13 hours ago, philbauch said: Hi, I wonder if there's an option to add some "Order by date added" to the order dropdown in a product list. Or as a filter in facetted search (e.g. "New products" Usually you always want to show your latest arrivals first, but PS orders obviously by id ASC, which means that oldest products are showing first. Any ideas welcome, thanks in advance, Phil You can change it in Advanced Settings -> Products... And if you want to add a sort order, you can edit /modules/ps_facetedsearch/src/product/searchprovider.php and add some code in the getAvailableSortOrders() function... private function getAvailableSortOrders() { $sortPosAsc = new SortOrder('product', 'position', 'asc'); $sortNameAsc = new SortOrder('product', 'name', 'asc'); $sortNameDesc = new SortOrder('product', 'name', 'desc'); $sortPriceAsc = new SortOrder('product', 'price', 'asc'); $sortPriceDesc = new SortOrder('product', 'price', 'desc'); $sortDateAsc = new SortOrder('product', 'date_add', 'asc'); $sortDateDesc = new SortOrder('product', 'date_add', 'desc'); $translator = $this->module->getTranslator(); return [ $sortPosAsc->setLabel( $translator->trans('Relevance', [], 'Modules.Facetedsearch.Shop') ), $sortNameAsc->setLabel( $translator->trans('Name, A to Z', [], 'Shop.Theme.Catalog') ), $sortNameDesc->setLabel( $translator->trans('Name, Z to A', [], 'Shop.Theme.Catalog') ), $sortPriceAsc->setLabel( $translator->trans('Price, low to high', [], 'Shop.Theme.Catalog') ), $sortPriceDesc->setLabel( $translator->trans('Price, high to low', [], 'Shop.Theme.Catalog') ), $sortDateAsc->setLabel( $translator->trans('Data, do mais antigo para o mais recente', [], 'Modules.Facetedsearch.Shop') ), $sortDateDesc->setLabel( $translator->trans('Data, do mais recente para o mais antigo', [], 'Modules.Facetedsearch.Shop') ), ]; } Best Regards 2 2 Link to comment Share on other sites More sharing options...
philbauch Posted December 28, 2019 Author Share Posted December 28, 2019 Fantastic, lots of thanks! Starting step by step to get deeper in PS and it's structure, helped a lot. One last question concerning translations (although not that urgent, in the beginning shop will be in english only): Can new translation patterns easily be added in the backend? Or is it just the only way to download the xlf's and code it the files? Don't want to destroy nothing, and in the translations I haven't found e.g. "Date, newest first" or something like this... Thanks & best regards Phil Link to comment Share on other sites More sharing options...
PCQUATRO Posted December 28, 2019 Share Posted December 28, 2019 1 hour ago, philbauch said: Can new translation patterns easily be added in the backend? Or is it just the only way to download the xlf's and code it the files? Don't want to destroy nothing, and in the translations I haven't found e.g. "Date, newest first" or something like this... I didn´t find it etheir, it should be on Modules.Facetedsearch.Shop translations, if you look there it says 2 untranslated expressions but they don´t show up, that´s why i translated it in the code. I also looked into the xfl file but there are some fields there that i didn´t understood the logic! Best regards Link to comment Share on other sites More sharing options...
philbauch Posted December 29, 2019 Author Share Posted December 29, 2019 Same for me, translation system is really a mess in P.S. 1.7.... Anyway, coded it inline, too, as a workaround... Lets see what future brings. Anyway, thanks a lot again. Cheers, Phil Link to comment Share on other sites More sharing options...
bartes1987 Posted April 21, 2020 Share Posted April 21, 2020 On 12/28/2019 at 4:23 AM, PCQUATRO said: You can change it in Advanced Settings -> Products... And if you want to add a sort order, you can edit /modules/ps_facetedsearch/src/product/searchprovider.php and add some code in the getAvailableSortOrders() function... private function getAvailableSortOrders() { $sortPosAsc = new SortOrder('product', 'position', 'asc'); $sortNameAsc = new SortOrder('product', 'name', 'asc'); $sortNameDesc = new SortOrder('product', 'name', 'desc'); $sortPriceAsc = new SortOrder('product', 'price', 'asc'); $sortPriceDesc = new SortOrder('product', 'price', 'desc'); $sortDateAsc = new SortOrder('product', 'date_add', 'asc'); $sortDateDesc = new SortOrder('product', 'date_add', 'desc'); $translator = $this->module->getTranslator(); return [ $sortPosAsc->setLabel( $translator->trans('Relevance', [], 'Modules.Facetedsearch.Shop') ), $sortNameAsc->setLabel( $translator->trans('Name, A to Z', [], 'Shop.Theme.Catalog') ), $sortNameDesc->setLabel( $translator->trans('Name, Z to A', [], 'Shop.Theme.Catalog') ), $sortPriceAsc->setLabel( $translator->trans('Price, low to high', [], 'Shop.Theme.Catalog') ), $sortPriceDesc->setLabel( $translator->trans('Price, high to low', [], 'Shop.Theme.Catalog') ), $sortDateAsc->setLabel( $translator->trans('Data, do mais antigo para o mais recente', [], 'Modules.Facetedsearch.Shop') ), $sortDateDesc->setLabel( $translator->trans('Data, do mais recente para o mais antigo', [], 'Modules.Facetedsearch.Shop') ), ]; } Best Regards Thank you PCQUATRO. That's exactly what I was looking for. But I have one problem. After the changes in the file "searchprovider.php" the sort by date is displaying on category pages but not on the search result pages. How to add sort by date to serach result pages as well? Link to comment Share on other sites More sharing options...
PCQUATRO Posted April 21, 2020 Share Posted April 21, 2020 15 minutes ago, bartes1987 said: Thank you PCQUATRO. That's exactly what I was looking for. But I have one problem. After the changes in the file "searchprovider.php" the sort by date is displaying on category pages but not on the search result pages. How to add sort by date to serach result pages as well? Can you post images? Best Regards Link to comment Share on other sites More sharing options...
bartes1987 Posted April 21, 2020 Share Posted April 21, 2020 (edited) This is product listing on category page where the new sort options are displaying: This is product listing on search result page where the new sort options aren't displaying: Edited April 21, 2020 by bartes1987 (see edit history) Link to comment Share on other sites More sharing options...
PCQUATRO Posted April 21, 2020 Share Posted April 21, 2020 11 minutes ago, bartes1987 said: This is product listing on search result page where the new sort options aren't displaying: Have you cleared the cache on both the browser and prestashop? you can also try to delete /var/cache... What is your store´s url? Best Regards Link to comment Share on other sites More sharing options...
bartes1987 Posted April 21, 2020 Share Posted April 21, 2020 1 hour ago, PCQUATRO said: Have you cleared the cache on both the browser and prestashop? you can also try to delete /var/cache... What is your store´s url? Best Regards Yes, I cleared the cache on both: browser and the store. Store url is: https://ohbutik.pl/ Link to comment Share on other sites More sharing options...
PCQUATRO Posted April 21, 2020 Share Posted April 21, 2020 7 hours ago, bartes1987 said: Yes, I cleared the cache on both: browser and the store. Store url is: https://ohbutik.pl/ It looks like you have another search module on your shop, that code only works in the faceted search module, you have to search in your search module the code for sorting and change it accordingly. You can also try disabling it and enabling faceted search to see what you get... Best Regards Link to comment Share on other sites More sharing options...
bartes1987 Posted April 22, 2020 Share Posted April 22, 2020 (edited) 9 hours ago, PCQUATRO said: It looks like you have another search module on your shop, that code only works in the faceted search module, you have to search in your search module the code for sorting and change it accordingly. You can also try disabling it and enabling faceted search to see what you get... Best Regards I don't think so. I checked this method on other store: https://zero-procent.pl which uses the default theme and definitely has no other search or filter module and the results are the same. It displays correctly on category listings but doesn't work on the search result listings. Edited April 22, 2020 by bartes1987 (see edit history) Link to comment Share on other sites More sharing options...
PCQUATRO Posted April 22, 2020 Share Posted April 22, 2020 2 hours ago, bartes1987 said: I don't think so. I checked this method on other store: https://zero-procent.pl which uses the default theme and definitely has no other search or filter module and the results are the same. It displays correctly on category listings but doesn't work on the search result listings. As i told you, you must also find the code that controls the search module, witch in this case is in /src/core/product/search/SortOrdersCollection.php and change it accordingly. Best Regards Link to comment Share on other sites More sharing options...
bartes1987 Posted April 22, 2020 Share Posted April 22, 2020 Thank you PCQUATRO! There wasn't SortOrdersCollection.php file in that catalog but I found it in SortOrderFactory.php file. I made the changes and it's all right now. Link to comment Share on other sites More sharing options...
Amorino Posted August 16, 2020 Share Posted August 16, 2020 Hello, Thank you very much worked like a charm But how to override these changes so we don't loose them in the next update of the module ? I tried to create the same directory in MYTHEME/modules but seems like it does take only CSS and tpl changes according to this documentation https://devdocs.prestashop.com/1.7/themes/reference/overriding-modules/ Any idea please ? Thank you Link to comment Share on other sites More sharing options...
PCQUATRO Posted August 16, 2020 Share Posted August 16, 2020 2 hours ago, Amorino said: Any idea please ? Try this Best Regards Link to comment Share on other sites More sharing options...
Amorino Posted August 16, 2020 Share Posted August 16, 2020 Hello, Thank you I tried that but still didn't work The problem is when module will update I will surely loose my changes Best regards Link to comment Share on other sites More sharing options...
PCQUATRO Posted August 16, 2020 Share Posted August 16, 2020 3 minutes ago, Amorino said: I tried that but still didn't work The problem is when module will update I will surely loose my changes That is a way of overriding, you don´t loose overrides!! You can also save the changed files with another name, write down the changes, than when there is an update to the module just redo the changes. Best Regards Link to comment Share on other sites More sharing options...
Amorino Posted August 18, 2020 Share Posted August 18, 2020 Hello, Ok thank you Link to comment Share on other sites More sharing options...
Dhruv Patel Posted August 20, 2020 Share Posted August 20, 2020 On 12/28/2019 at 8:53 AM, PCQUATRO said: You can change it in Advanced Settings -> Products... And if you want to add a sort order, you can edit /modules/ps_facetedsearch/src/product/searchprovider.php and add some code in the getAvailableSortOrders() function... private function getAvailableSortOrders() { $sortPosAsc = new SortOrder('product', 'position', 'asc'); $sortNameAsc = new SortOrder('product', 'name', 'asc'); $sortNameDesc = new SortOrder('product', 'name', 'desc'); $sortPriceAsc = new SortOrder('product', 'price', 'asc'); $sortPriceDesc = new SortOrder('product', 'price', 'desc'); $sortDateAsc = new SortOrder('product', 'date_add', 'asc'); $sortDateDesc = new SortOrder('product', 'date_add', 'desc'); $translator = $this->module->getTranslator(); return [ $sortPosAsc->setLabel( $translator->trans('Relevance', [], 'Modules.Facetedsearch.Shop') ), $sortNameAsc->setLabel( $translator->trans('Name, A to Z', [], 'Shop.Theme.Catalog') ), $sortNameDesc->setLabel( $translator->trans('Name, Z to A', [], 'Shop.Theme.Catalog') ), $sortPriceAsc->setLabel( $translator->trans('Price, low to high', [], 'Shop.Theme.Catalog') ), $sortPriceDesc->setLabel( $translator->trans('Price, high to low', [], 'Shop.Theme.Catalog') ), $sortDateAsc->setLabel( $translator->trans('Data, do mais antigo para o mais recente', [], 'Modules.Facetedsearch.Shop') ), $sortDateDesc->setLabel( $translator->trans('Data, do mais recente para o mais antigo', [], 'Modules.Facetedsearch.Shop') ), ]; } Best Regards Thanks Man!!! It saved lots of time....😃 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now