JerseyG Posted July 9, 2012 Share Posted July 9, 2012 (edited) Hi I have seen various articles on sorting items into alphabetical order but I have not seen a solution to my problem here. I am using tags to give me a break down of items used in a selected device. The list appears in item number and I would like it to be listed alphabetically. If you do a manual search you get a Sort by option, but nothing for tags. Any advice? Thanks in Advance G Edited July 31, 2012 by JerseyG (see edit history) Link to comment Share on other sites More sharing options...
shacker Posted July 12, 2012 Share Posted July 12, 2012 tags are ordereb by relevance. You can change in classes/tag.php search the function public static function getMainTags($id_lang, $nb = 10) and change ORDER BY times DESC to ORDER BY t.name ASC Link to comment Share on other sites More sharing options...
JerseyG Posted July 27, 2012 Author Share Posted July 27, 2012 Hi Shacker Thanks for your input, however reading back my post I can see that I have not explained myself correctly. If you go to my site www.fptg.co.uk you will note that I have sorted my tags into order. But if I then select a tagged item the items within that are in id order. Is it possible to arrange these into alphabetical order? Thanks in advance Geoff Link to comment Share on other sites More sharing options...
shacker Posted July 27, 2012 Share Posted July 27, 2012 you need to modify the search.php class in classes folder, and in this line public static function searchTag($id_lang, $tag, $count = false, $pageNumber = 0, $pageSize = 10, $orderBy = false, $orderWay = false, $useCookie = true) you have the order by and order way. replace for "name", "DESC" Link to comment Share on other sites More sharing options...
JerseyG Posted July 28, 2012 Author Share Posted July 28, 2012 Hi Shacker Again thank you for your time and help however I replaced "name" with "DESC" and my search failed totally. Is it possible for you to highlight where the changes should be made. Thanks in advance Geoff public static function searchTag($id_lang, $tag, $count = false, $pageNumber = 0, $pageSize = 10, $orderBy = false, $orderWay = false, $useCookie = true) { global $cookie; // Only use cookie if id_customer is not present if ($useCookie) $id_customer = (int)$cookie->id_customer; else $id_customer = 0; if (!is_numeric($pageNumber) OR !is_numeric($pageSize) OR !Validate::isBool($count) OR !Validate::isValidSearch($tag) OR $orderBy AND !$orderWay OR ($orderBy AND !Validate::isOrderBy($orderBy)) OR ($orderWay AND !Validate::isOrderBy($orderWay))) return false; if ($pageNumber < 1) $pageNumber = 1; if ($pageSize < 1) $pageSize = 10; if ($count) { $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT COUNT(DISTINCT pt.`id_product`) nb FROM `'._DB_PREFIX_.'product` p LEFT JOIN `'._DB_PREFIX_.'product_tag` pt ON (p.`id_product` = pt.`id_product`) LEFT JOIN `'._DB_PREFIX_.'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`) LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`) WHERE p.`active` = 1 AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN ( SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.(int)$id_customer.')').' AND t.`name` LIKE \'%'.pSQL($tag).'%\''); return isset($result['nb']) ? $result['nb'] : 0; } $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT DISTINCT p.*, pl.`description_short`, pl.`link_rewrite`, pl.`name`, tax.`rate`, i.`id_image`, il.`legend`, m.`name` manufacturer_name, 1 position, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 new FROM `'._DB_PREFIX_.'product` p INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = '.(int)Country::getDefaultCountryId().' AND tr.`id_state` = 0) LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`) LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) LEFT JOIN `'._DB_PREFIX_.'product_tag` pt ON (p.`id_product` = pt.`id_product`) LEFT JOIN `'._DB_PREFIX_.'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`) LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`) WHERE p.`active` = 1 AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN ( SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.(int)$id_customer.')').' AND t.`name` LIKE \'%'.pSQL($tag).'%\' ORDER BY position DESC'.($orderBy ? ', '.$orderBy : '').($orderWay ? ' '.$orderWay : '').' LIMIT '.(int)(($pageNumber - 1) * $pageSize).','.(int)$pageSize); if (!$result) return false; return Product::getProductsProperties((int)$id_lang, $result); } Link to comment Share on other sites More sharing options...
shacker Posted July 28, 2012 Share Posted July 28, 2012 public static function searchTag($id_lang, $tag, $count = false, $pageNumber = 0, $pageSize = 10,"name", "DESC", $useCookie = true) { Link to comment Share on other sites More sharing options...
JerseyG Posted July 28, 2012 Author Share Posted July 28, 2012 If I make the change I get:- 500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed. Link to comment Share on other sites More sharing options...
shacker Posted July 28, 2012 Share Posted July 28, 2012 sorry, y copy wrong: public static function searchTag($id_lang, $tag, $count = false, $pageNumber = 0, $pageSize = 10, $orderBy = "name", $orderWay = "DESC", $useCookie = true) { Link to comment Share on other sites More sharing options...
JerseyG Posted July 28, 2012 Author Share Posted July 28, 2012 Hi Shacker With that inserted I am back to square one. If you check the site you will see that if you select a tag the search shows the items in id order still :-( Geoff Link to comment Share on other sites More sharing options...
JerseyG Posted July 30, 2012 Author Share Posted July 30, 2012 Hi Shacker has been kind enough to try and help on this but the offered solution has not worked. I am trying to get the results of a tag to display in alphabetical order, I am sure we are working in the correct area as the wrong entry will stop the search working. The site is www.fptg.co.uk If you click on a tag you will see the results are still in id order. Any help would be appreciated as it will make this area look more professional. Again thanks to Shacker for his reply. Geoff Link to comment Share on other sites More sharing options...
JerseyG Posted July 31, 2012 Author Share Posted July 31, 2012 Hi Shacker Again thanks for your assistance, you put me the correct area. The following change will display your tag search results in alphabetical order. Classes/Search.php Line 582 ORDER BY name ASC'.($orderBy ? ', '.$orderBy : '').($orderWay ? ' '.$orderWay : '').' Thanks again and I hope this helps someone else Geoff 1 Link to comment Share on other sites More sharing options...
shacker Posted August 1, 2012 Share Posted August 1, 2012 oh, i forgot these line. Thanks a lot Link to comment Share on other sites More sharing options...
Szkudi Posted July 25, 2014 Share Posted July 25, 2014 Hi, I have a problem related to this topic but I couldn't find any other closer to what I need. I'd like to enable sorting all products in my shop (PS 1.6) by tags they have. For example I have 4 products (named A, B, C) and each of them have their own tag (Z, M, P). I'd like to add an option that would check tags of products and sort them by those tags. Anyone have an idea how to do that? Link to comment Share on other sites More sharing options...
Gomlers Posted January 27, 2017 Share Posted January 27, 2017 Hi Shacker Again thanks for your assistance, you put me the correct area. The following change will display your tag search results in alphabetical order. Classes/Search.php Line 582 ORDER BY name ASC'.($orderBy ? ', '.$orderBy : '').($orderWay ? ' '.$orderWay : '').' Thanks again and I hope this helps someone else Geoff Thank you for coming back with the solution. Made the problem much smaller for me Did also work on 1.6.1.0, even though the Line 582 was moved to 830-something in 1.6 - but still! Wish everyone posted the solution like you did here, when finding it... Link to comment Share on other sites More sharing options...
Recommended Posts