Jump to content

sort the attributes alphabetically


ilario

Recommended Posts

hello
i use prestashop 8.2, product v2, in the filter combinations, i would like to put the attributes in alphabetical order, in the "show dropdown menu" and if possible in the button add a checkbox that selects them all as in the generation of
combinations. thanks a lot

attribute desc.png

Edited by ilario (see edit history)
Link to comment
Share on other sites

Sort attributes alphabetically in the dropdown menu

Override or customize the template:
Locate the template file that renders the filter combinations dropdown. This is often found in the admin/themes folder or the module's folder.

Open the relevant .tpl or .html.twig file.
Sort the attribute list before rendering it. For example, in PHP, you can use usort() to order the array of attributes alphabetically.

Modify the controller:
If the attribute data is retrieved from a controller, modify the query or function to include an ORDER BY clause (for example, ORDER BY name ASC).

Cache and Test:
After making modifications, clear the PrestaShop cache (under "Advanced Parameters > Performance") and test the attributes are displayed alphabetically.

Link to comment
Share on other sites

32 minutes ago, pallavigodse said:

Sort attributes alphabetically in the dropdown menu

Override or customize the template:
Locate the template file that renders the filter combinations dropdown. This is often found in the admin/themes folder or the module's folder.

Open the relevant .tpl or .html.twig file.
Sort the attribute list before rendering it. For example, in PHP, you can use usort() to order the array of attributes alphabetically.

Modify the controller:
If the attribute data is retrieved from a controller, modify the query or function to include an ORDER BY clause (for example, ORDER BY name ASC).

Cache and Test:
After making modifications, clear the PrestaShop cache (under "Advanced Parameters > Performance") and test the attributes are displayed alphabetically.

hello thank you very much for the answer,

I tried to search in the theme folder both default and new-theme, but I did not find the right file.

could you tell me if there is a particular module that controls the products/combination section.

 

Link to comment
Share on other sites

  • 3 months later...
On 1/21/2025 at 8:41 PM, ilario said:

hello thank you very much for the answer,

I tried to search in the theme folder both default and new-theme, but I did not find the right file.

could you tell me if there is a particular module that controls the products/combination section.

 

To achieve this, you need to make a single line change in the core file. Here is the path below.

https://github.com/PrestaShop/PrestaShop/blob/8.2.0/src/Adapter/Attribute/Repository/AttributeRepository.php#L124

You need to replace this line with the code below.

->addOrderBy('al.name', 'ASC')

Result:

 

Screenshot (53).png

Link to comment
Share on other sites

42 minutes ago, Webkul Solutions said:

To achieve this, you need to make a single line change in the core file. Here is the path below.

https://github.com/PrestaShop/PrestaShop/blob/8.2.0/src/Adapter/Attribute/Repository/AttributeRepository.php#L124

You need to replace this line with the code below.

->addOrderBy('al.name', 'ASC')

Result:

 

Screenshot (53).png

hi Webkul

thanks a lot for the answer,

it works but halfway see image, it lists the attributes almost in alphabetical order, but in a strange way

order alf.png

Link to comment
Share on other sites

12 hours ago, musicmaster said:

Si noti che nella pagina degli attributi (catalog->attributes) è possibile definire l'ordine degli attributi

hi thanks for the reply,

but the attributes are already in order for the front, but in B.O I need them in alphabetical order to find them faster

Link to comment
Share on other sites

On 5/16/2025 at 12:31 PM, ilario said:

hi Webkul

thanks a lot for the answer,

it works but halfway see image, it lists the attributes almost in alphabetical order, but in a strange way

order alf.png

Can you please share a screenshot of your attribute list in the back office (Instead of product editing)?

Link to comment
Share on other sites

50 minutes ago, ilario said:

 

papers.png

Thanks for sharing the image.

We have checked again at our end & everything is working fine once we implement the changes as we shared with you.

Can you please share the code image where you made changes?

Link to comment
Share on other sites

Posted (edited)
59 minutes ago, ilario said:

 

papers.png

The attributes in that screenshot are not in order. You need to manually drag them into order using the Cross in the position column, then they will be in order in the B.O and shop view.

No code editing is needed

Edited by Ray UK (see edit history)
Link to comment
Share on other sites

7 minutes ago, Webkul Solutions said:

Thanks for sharing the image.

We have checked again at our end & everything is working fine once we implement the changes as we shared with you.

Can you please share the code image where you made changes?

of course , thanks

 

code.png

Link to comment
Share on other sites

1 minute ago, Ray UK said:

The attributes in that screenshot are not in order. You need to manually drag them into order using the Cross in the position column, then they will be in order in the B.O and shop view.

Ray UK in front must remain so they are positioned correctly, in front they must not be in alphabetical order, I only need that in B.O.

Link to comment
Share on other sites

3 minutes ago, ilario said:

Ray UK in front must remain so they are positioned correctly, in front they must not be in alphabetical order, I only need that in B.O.

Ahh sorry i must have missed that bit.  Yes what I suggest will sort them in the Front and Back.

Link to comment
Share on other sites

2 minuti fa, Ray UK ha detto:

Inoltre, se stai utilizzando l'ultimo prestashop, puoi abilitare la "Pagina del prodotto sperimentale" e questa ha un "Seleziona tutto" per le combinazioni.

Screenshot2025-05-19at15-19-45ProductsNorthWestEcigs.png.b383cb4e5abe5878776f48e5791d855c.png

sì grazie lo uso già, è esattamente lì che sto cercando di modificarli e metterli in ordine alfabetico

Link to comment
Share on other sites

On 5/16/2025 at 7:17 AM, Webkul Solutions said:

To achieve this, you need to make a single line change in the core file. Here is the path below.

https://github.com/PrestaShop/PrestaShop/blob/8.2.0/src/Adapter/Attribute/Repository/AttributeRepository.php#L124

You need to replace this line with the code below.

->addOrderBy('al.name', 'ASC')

Result:

 

Screenshot (53).png

Would this change also order the column "Combination"?  Or is there a way to add a "Sortable" to that column.  It's annoying that when adding a new option, regardless of the name, it's always added to the bottom with no way of sorting them. (Im using the experimental product page)

SortOrderNorthWestEcigs.png.b38946cb32404b874b66a9863d39ee8f.png

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...