Jump to content

Sort attributes from a-z?


Recommended Posts

Hi,
my products have attibutes like speaking time:

* 3h
* 3,5h
* 6h
* 4h
* 5h

And they are not sorted from a-z on AdminCatalog-Tab. I inserted them as I used it, but so its a little bit difficult to select. I would have hacked it, but didn't find the place where.

Thanks,
Beate

1143_ZzHW5evSrUgk8nOStXVd_t

Link to comment
Share on other sites

Ahh, OK, you mean Features.

I've just tested it and you're right, unlike Attributes, Features are _not_ automatically listed in alphabetical order.

This will be fixed for the RC5.

In the meantime, my colleague Philippe Sang will post a line of code to add, and where. It should be an easy fix even for non-developers. :)

Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...

Hi, sorry for my english ;-)


I make this change on: classes/Product.php

Near the end of file:

   /*
   * Select all features for a given language
   *
   * @param $id_lang Language id
   * @return array Array with feature's data
   */
   static public function getFrontFeaturesStatic($id_lang, $id_product)
   {
       return Db::getInstance()->ExecuteS('
       SELECT name, value, pf.id_feature
       FROM '._DB_PREFIX_.'feature_product pf
       LEFT JOIN '._DB_PREFIX_.'feature_lang fl ON (fl.id_feature = pf.id_feature AND fl.id_lang = '.intval($id_lang).')
       LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = '.intval($id_lang).')
       WHERE pf.id_product = '.intval($id_product));
   }



changed on:

   /*
   * Select all features for a given language
   *
   * @param $id_lang Language id
   * @return array Array with feature's data
   * MODIFICATO il 3/09/2008
   */
   static public function getFrontFeaturesStatic($id_lang, $id_product)
   {

       $result =  Db::getInstance()->ExecuteS('
       SELECT name, value, pf.id_feature
       FROM '._DB_PREFIX_.'feature_product pf
       LEFT JOIN '._DB_PREFIX_.'feature_lang fl ON (fl.id_feature = pf.id_feature AND fl.id_lang = '.intval($id_lang).')
       LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = '.intval($id_lang).')
       WHERE pf.id_product = '.intval($id_product).'
       ORDER BY `name`');

       /* Modify SQL result - hide 01. 02. */
       $resultsArray = array();
       foreach ($result AS $row)
       {
           $row['name'] = preg_replace('/^[0-9]+\./', '', $row['name']);
           $resultsArray[] = $row;
       }
       return $resultsArray;

   }



Now you can show ordered fautures.

If you need to force order you can use 01. 02. like category - example:

01.feature zzz
02.feature xxx

Link to comment
Share on other sites

  • 4 months later...

Hello!

I had the same problem with the latest SVN version.
To solve that (on front store):

Change getAttributesGroups function in "/classes/Product.php" to:

   public function getAttributesGroups($id_lang)
   {
       $result = Db::getInstance()->ExecuteS('
       SELECT ag.`id_attribute_group`, agl.`name` AS group_name, agl.`public_name` AS public_group_name, a.`id_attribute`, al.`name` AS attribute_name,
       a.`color` AS attribute_color, pa.`id_product_attribute`, pa.`quantity`, pa.`price`, pa.`ecotax`, pa.`weight`, pa.`default_on`, pa.`reference`
       FROM `'._DB_PREFIX_.'product_attribute` pa
       LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute`
       LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute`
       LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group`
       LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON a.`id_attribute` = al.`id_attribute`
       LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON ag.`id_attribute_group` = agl.`id_attribute_group`
       WHERE pa.`id_product` = '.intval($this->id).'
       AND al.`id_lang` = '.intval($id_lang).'
       AND agl.`id_lang` = '.intval($id_lang).'
       ORDER BY agl.`name`, al.`name`, pa.`id_product_attribute`');

          /* Modify SQL result - hide 01. 02. */
       $resultsArray = array();
       foreach ($result AS $row)
       {
           $row['attribute_name'] = preg_replace('/^[0-9]+\./', '', $row['attribute_name']);
           $resultsArray[] = $row;
       }
       return $resultsArray;
   }



To correct all PrestoShop code, see this post:
http://www.prestashop.com/forums/viewthread/11717/general_discussion/sort_product_attributes

There you'll find how to correct BackOffice and FrontStore "Attribute sorting bug".

Link to comment
Share on other sites

×
×
  • Create New...