Jump to content

PS 1.7.8 Multiple Feature Values Sorting in the front end


Recommended Posts

Hello Prestashop Forum,

We have a PS site that deals in food items, and it's important that the nutritional information is displayed.
So we added a Feature for Nutritional Values, and added all the values via that. There's 9 values in total, and they should be displayed in that order, starting from 1, going all the way down to 9.

However, Prestashop seems to automatically alphabeticize Feature Values.
So the features are displayed correctly, only the ordering is messed up. It does not seem to be a theme thing either, as the standard PS theme also orders multiple Feature Values in alphabetical order.

scrnsht-multiplefeaturevalues-alphabetical.png.cb8526759488501ecf0746cad76821cc.png

We've tried changing to custom values or predefined values, but this does not seem to make a difference.

In the backend of the shop, in the product itself, it seems to be ordered in the way we imported it. But on the front end, it orders them in an alphabetical way.

I've already tried fiddling around with the classes/Product.php file and a few others, but nothing seems to do the trick.

Hopefully someone here can help us along a little bit.

Link to comment
Share on other sites

Just now, Prestashop Addict said:

Hi, how do you want to sort string like number values especially when you have only numbers and some with g?

Hi, it's not just number values. The word in front of the numbers are part of the value.

The Feature is called Voedingswaardes, meaning Nutritional Values in Dutch.

7350ea053af3c74203829df20853cbc6.png.4222b885d815c26adcc4e6d02a1e3a7d.png

There's multiple feature values, and in the backend they are showing in the right order.

e20ae4af1b019d3abfd8d72123364cfd.png.3ea8517addd607126600e242a75b7dd8.png

However, in the front end, they show up in the different order.

Link to comment
Share on other sites

55 minutes ago, Prestashop Addict said:

Ok you want to display them in ID order?

Yes exactly, I want to display them in the front end the way they're ordered in the back end also.
Is this easily done by editing a php file, or will some changes to the values themselves have to be made?

Link to comment
Share on other sites

8 minutes ago, Prestashop Addict said:

2 solutions

  1. override php class Feature.php method getFeatures() (php skill needed)
  2. override theme template product-details.tpl (smarty and php skill need)

The first sounds better, as this function should stay present if a switch in templates does ever happen.
However, should any PHP changes regarding the ordering of the values not take place in the FeatureValue.php instead of the Feature.php?

Link to comment
Share on other sites

5 minutes ago, Prestashop Addict said:

If you don't have skills on php and Prestashop override, I recommend you to ask a professional, this modification is not expensive 😉

Don't worry, I do have some skill in PHP and overrides. :)

It's just that the Feature.php doesn't call to any of the database tables that makes use of the Feature values or their IDs.
I do believe you that it may need to be changed there, but a simple point in the right direction could make the difference.
To my knowledge, the only tables that contains the IDs of these feature values are feature_value and feature_value_lang.

The values all have an ID in the backend that matches the one in the Database, so it should be possible to order them in such a manner.

But when looking through Feature.php, I cannot find anything that calls upon feature_value_lang in any way, while FeatureValue.php does, quite obiously even.

    public static function getFeatureValuesWithLang($idLang, $idFeature, $custom = false)
    {
        return Db::getInstance()->executeS('
			SELECT *
			FROM `' . _DB_PREFIX_ . 'feature_value` v
			LEFT JOIN `' . _DB_PREFIX_ . 'feature_value_lang` vl
				ON (v.`id_feature_value` = vl.`id_feature_value` AND vl.`id_lang` = ' . (int) $idLang . ')
			WHERE v.`id_feature` = ' . (int) $idFeature . '
				' . (!$custom ? 'AND (v.`custom` IS NULL OR v.`custom` = 0)' : '') . '
			ORDER BY vl.`value` ASC
		');
    }

When I change the ORDER BY at the end and place the file in the override folder, it doesn't change anything.
It does notice the override, as the file appears in the override section of the backend, but it unfortunately doesn't seem to change much.

There must be a small change I'm still missing here.

Link to comment
Share on other sites

4 minutes ago, Prestashop Addict said:

Did you try to change order of features entries in admin Attributes & Features?

I did, they're sorted by ID in the backend. However there does not seem to be a function to drag and drop for feature values, as there is for features themselves.
In the features overview you can edit the position, but in the value overview, this simply seems to be done by either ID or Name, and either Ascending or Descending. Not sure if it has much impact on the front end, though.

screenshot-admin-featurevalues.png.448d5dffa970d10da37633d7780068bf.png

I'm a little stumped, because it almost seems that everywhere the order of the values is correct, except when it gets loaded onto the front end of the shop.

Link to comment
Share on other sites

On 6/7/2024 at 4:23 PM, Prestashop Addict said:

Works fine for me

Order of features, you can change it

image.thumb.png.09d12b730005651c76fdd0fda312a104.png

 

In BO product sheet PS displays sorted by name

image.thumb.png.2cf66e9e0e9c6b7757335e502ef4c9bf.png

 

But in front my order is good

image.png.31af453b05cdcfbe3a50ec9ab2354636.png

 

but you cannot sort by values 😞

 

I see, the feature sorting indeed works as intended, but the feature value sorting is unfortunately not there...

I'm going to try and find out if it's possible in some other way, but thank you for your help so far at least! :)

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...