PrestaShop Forum

The best place in the world to ask questions about PrestaShop and get advice from our passionate community!

PrestaShop Forum

Jump to content

 

Sort attributes from a-z?

10 replies to this topic
#1
beate

    PrestaShop Apprentice

  • Members
  • PipPip
  • 65 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

Attached Files

  • Attached File  bug.png   21bytes   2023 downloads


#2
Peter Wilson

    PrestaShop Addict

  • Members
  • PipPipPip
  • 692 posts
Hi beate,

Which version of PrestaShop are you using?

I've just tested this on v1.0 RC4 and PrestaShop automatically lists attributes in alphabetical order, both on the Back Office and on the Front Office....
Help PrestaShop, make a donation ![/size]

#3
beate

    PrestaShop Apprentice

  • Members
  • PipPip
  • 65 posts
I use RC4... very strange...

But I inserted them on RC3. Does this matter?

#4
Peter Wilson

    PrestaShop Addict

  • Members
  • PipPipPip
  • 692 posts
It shouldn't matter, no. :blank:

Can you please post a screen capture of the list of the above attributes in the Back Office >> Catalog >> Attributes and groups ?

Thanks!
Help PrestaShop, make a donation ![/size]

#5
beate

    PrestaShop Apprentice

  • Members
  • PipPip
  • 65 posts
I'm sorry, this is not attributes and groupes, but features.

Here is a screenshot.

Attached Files

  • Attached File  bug.png   45bytes   2318 downloads


#6
Peter Wilson

    PrestaShop Addict

  • Members
  • PipPipPip
  • 692 posts
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. :)
Help PrestaShop, make a donation ![/size]

#7
beate

    PrestaShop Apprentice

  • Members
  • PipPip
  • 65 posts
Thank you, that would be great!

But I'm a developer, but I didn't find the place where to edit this.

#8
beate

    PrestaShop Apprentice

  • Members
  • PipPip
  • 65 posts
Is there some kind of fix in the pipeline? Would be great :)

#9
rsvp

    PrestaShop Apprentice

  • Members
  • PipPip
  • 31 posts
My features just organize themselves in no discernible order. They're just there, willy-nilly. What can be done? :long:

#10
vinoalvino

    PrestaShop Addict

  • Members
  • PipPipPip
  • 841 posts
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
Al mondo ci sono 11 tipi di persone: quelli che capiscono/non capiscono il codice binario e quelli che trovano tutti i moduli su prestamodules :P
-- Realizzo moduli e personalizzazioni per prestashop --

#11
Infordesign

    PrestaShop Newbie

  • Members
  • Pip
  • 24 posts
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.prestasho...duct_attributes

There you'll find how to correct BackOffice and FrontStore "Attribute sorting bug".
I N F O R D E S I G N ®

Infordesign - Unipessoal, Lda.
WEB: www.infordesign.com | MAIL: mail [at] infordesign [dot] com