presta-rocks Posted February 7, 2012 Share Posted February 7, 2012 How to sort product by product reference? I'm type in my product-sort.tpl this code <option value="{$link->addSortDetails($request, 'reference', 'asc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'reference' AND $orderway eq 'ASC'}selected="selected"{/if}>{l s='ref: A to Z'}</option> but it doesn't work(when i select ref it's sort by defult order) Presta ver. 1.4.6.2 Link to comment Share on other sites More sharing options...
CartExpert.net Posted February 8, 2012 Share Posted February 8, 2012 Hello, The value of the option should not be a link. It should be reference:asc Link to comment Share on other sites More sharing options...
presta-rocks Posted February 9, 2012 Author Share Posted February 9, 2012 Hello, The value of the option should not be a link. It should be reference:asc Do you mean this: <option value="reference:asc" {if $orderby eq 'reference' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='reference: A to Z'}</option> <option value="reference:desc" {if $orderby eq 'reference' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='reference: z to a'}</option> It's not working Link to comment Share on other sites More sharing options...
CartExpert.net Posted February 9, 2012 Share Posted February 9, 2012 You will need to edit the classes that display products, handle the situation when orderBy is reference and set the $orderByPrefix. Link to comment Share on other sites More sharing options...
presta-rocks Posted February 9, 2012 Author Share Posted February 9, 2012 You will need to edit the classes that display products, handle the situation when orderBy is reference and set the $orderByPrefix. I wast trying this before i post this topic and it's was not working even if i type order by p.reference i mysql query. But i;m using layered navigation and i finally find a solution. This is what i made. 1. In product-sort.tpl of template im type this <option value="{$link->addSortDetails($request, 'reference', 'asc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'reference' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Reference: A to Z'}</option> <option value="{$link->addSortDetails($request, 'reference', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'reference' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='Reference: Z to A'}</option> 2.In classes/Tools.php i method getProductsOrder i made this changes first change $list = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity''); to $list = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity', 7 => 'reference'); second change if ($value == 'id_product' || $value == 'date_add' || $value == 'date_upd' || $value == 'price') to if ($value == 'id_product' || $value == 'date_add' || $value == 'date_upd' || $value == 'price' || $value == 'reference') 1 Link to comment Share on other sites More sharing options...
DylzEn Posted August 1, 2012 Share Posted August 1, 2012 Thank you for sharing, marcinsz101, that works very well! Do you know how can I set a default sort type when I open the product list? That is, I don't want to display the sort bar but I want the products to be ordered by reference by default. Thanks to anyone who could help me. Link to comment Share on other sites More sharing options...
jpac Posted October 23, 2012 Share Posted October 23, 2012 Hi, Is this solution also working for you in version 1.5.17? I don't manage to get product lists sorted by reference. thanks Link to comment Share on other sites More sharing options...
nuacco Posted January 17, 2013 Share Posted January 17, 2013 (edited) thank you @marcinsz101, works perfectly in 1.5.1 Edited January 17, 2013 by nuacco (see edit history) Link to comment Share on other sites More sharing options...
Kashi Posted February 27, 2013 Share Posted February 27, 2013 Thank you for sharing this marcinsz101 Just for the record, It works in 1.5.3.1 as well. Link to comment Share on other sites More sharing options...
oorbx Posted April 4, 2013 Share Posted April 4, 2013 Can somebody explain to me, where to insert that 2 rows into file : "themes/default/product-sort.tpl" I am using prestashop 1.5.3.1, and i insert and replace like marcinsz101 posted, but maybe somewhere i made mistake ? I insert that 2 rows into product-sort-tpl and i can see in front office, but when is sort it, it automatically turn to sort by name. thanks for reply. Link to comment Share on other sites More sharing options...
RobboR Posted May 22, 2013 Share Posted May 22, 2013 (edited) Thank you for sharing this marcinsz101 Just for the record, It works in 1.5.3.1 as well. Hi Kashibabu! could you tell us how did you makes it works in PS 1.5.3.1? I tried but i run into the same oorbx's troubles: when i choose the "reference" option automatically the sort list turn to sort by name: A to Z In product-sort.tpl I put options in this way: <option value="reference:asc" {if $orderby eq 'reference' AND $orderway eq 'asc'}selected="selected"{/if}>Reference: A to Z</option> <option value="reference:desc" {if $orderby eq 'reference' AND $orderway eq 'desc'}selected="selected"{/if}>Reference: Z to A</option> Edited May 22, 2013 by RobboR (see edit history) Link to comment Share on other sites More sharing options...
RobboR Posted May 27, 2013 Share Posted May 27, 2013 (edited) Can somebody explain to me, where to insert that 2 rows into file : "themes/default/product-sort.tpl" I am using prestashop 1.5.3.1, and i insert and replace like marcinsz101 posted, but maybe somewhere i made mistake ? I insert that 2 rows into product-sort-tpl and i can see in front office, but when is sort it, it automatically turn to sort by name. thanks for reply. Hi! try to add the new array value in function productSort() you find it in ps_root/classes/controller/FrontController.php $order_by_values = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity', 7 => 'reference'); For PS's best practice you should copy and paste the whole function in "FrontController.php" file (override folder): ps_root/override/classes/controller/FrontController.php file <?php class FrontController extends FrontControllerCore { public function productSort() { // $this->orderBy = Tools::getProductsOrder('by', Tools::getValue('orderby')); // $this->orderWay = Tools::getProductsOrder('way', Tools::getValue('orderway')); // 'orderbydefault' => Tools::getProductsOrder('by'), // 'orderwayposition' => Tools::getProductsOrder('way'), // Deprecated: orderwayposition // 'orderwaydefault' => Tools::getProductsOrder('way'), $stock_management = Configuration::get('PS_STOCK_MANAGEMENT') ? true : false; // no display quantity order if stock management disabled $order_by_values = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity', 7 => 'reference'); $order_way_values = array(0 => 'asc', 1 => 'desc'); $this->orderBy = Tools::strtolower(Tools::getValue('orderby', $order_by_values[(int)Configuration::get('PS_PRODUCTS_ORDER_BY')])); $this->orderWay = Tools::strtolower(Tools::getValue('orderway', $order_way_values[(int)Configuration::get('PS_PRODUCTS_ORDER_WAY')])); if (!in_array($this->orderBy, $order_by_values)) $this->orderBy = $order_by_values[0]; if (!in_array($this->orderWay, $order_way_values)) $this->orderWay = $order_way_values[0]; $this->context->smarty->assign(array( 'orderby' => $this->orderBy, 'orderway' => $this->orderWay, 'orderbydefault' => $order_by_values[(int)Configuration::get('PS_PRODUCTS_ORDER_BY')], 'orderwayposition' => $order_way_values[(int)Configuration::get('PS_PRODUCTS_ORDER_WAY')], // Deprecated: orderwayposition 'orderwaydefault' => $order_way_values[(int)Configuration::get('PS_PRODUCTS_ORDER_WAY')], 'stock_management' => (int)$stock_management)); } } // *** END Class override If you have to change query because you added customized additional fields (for me are "author" and "year" for example) you should change query you find in ps_root/classes/Category.php and ps_root/classes/Search.php files: paste function getProducts() in ps_root/override/classes/Category.php a and function find() in ps_root/override/classes/Search.php and customize it Hope this help bye! Edited May 27, 2013 by RobboR (see edit history) Link to comment Share on other sites More sharing options...
lily+ Posted May 30, 2013 Share Posted May 30, 2013 Does anyone know if is there any way to order products by their position in THE DEFAULT category. I am asking because I have child categories (subcategories), and the products don't get ordered in the front as in theback. Link to comment Share on other sites More sharing options...
darkgriever Posted June 23, 2013 Share Posted June 23, 2013 (edited) <p> I wast trying this before i post this topic and it's was not working even if i type order by p.reference i mysql query. But i;m using layered navigation and i finally find a solution. This is what i made. 1. In product-sort.tpl of template im type this </p> <option and="" eq="" if="" orderby="" orderway="" selected="selected" value="{$link->addSortDetails($request, 'reference', 'asc')|escape:'htmlall':'UTF-8'}">{l s='Reference: A to Z'}</option><option and="" eq="" if="" orderby="" orderway="" selected="selected" value="{$link->addSortDetails($request, 'reference', 'desc')|escape:'htmlall':'UTF-8'}">{l s='Reference: Z to A'}</option> <p> 2.In classes/Tools.php i method getProductsOrder i made this changes first change $list = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity''); to $list = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity', 7 => 'reference'); second change if ($value == 'id_product' || $value == 'date_add' || $value == 'date_upd' || $value == 'price') to if ($value == 'id_product' || $value == 'date_add' || $value == 'date_upd' || $value == 'price' || $value == 'reference') </p><p> </p> <p> </p> <p>it work for me using the above solution but using this</p> <option value="reference:asc" {if $orderby eq 'reference' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='reference: A to Z'}</option> <option value="reference:desc" {if $orderby eq 'reference' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='reference: z to a'}</option> Edited June 23, 2013 by darkgriever (see edit history) Link to comment Share on other sites More sharing options...
vahidafshari Posted December 14, 2013 Share Posted December 14, 2013 which item can be Instead of reference? can i use most product viewed? Link to comment Share on other sites More sharing options...
fobostec Posted September 26, 2014 Share Posted September 26, 2014 Do you mean this: <option value="reference:asc" {if $orderby eq 'reference' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='reference: A to Z'}</option> <option value="reference:desc" {if $orderby eq 'reference' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='reference: z to a'}</option> It's not working The same like that post: http://www.prestashop.com/forums/topic/190057-sort-products-by-id-product/ Link to comment Share on other sites More sharing options...
GenZai Posted February 7, 2015 Share Posted February 7, 2015 Hi, I think there is a problem with version 1.6 as the sorting by reference actually sorts by product ID. Link to comment Share on other sites More sharing options...
Welele Posted February 8, 2016 Share Posted February 8, 2016 Hello everyone. It is possible sort the products order by EAN-13 or UPC field?? I dont use this fields and I would like sort the orders invoice because my store and stock is too big. Reference numbers and another fields are disordered. I need a new field to sort. Thanks and regards Link to comment Share on other sites More sharing options...
Welele Posted February 9, 2016 Share Posted February 9, 2016 Please. I need help. Is this possible? Best regards 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