Jump to content

Edit Features order list


Recommended Posts

Is it possible to edit the order in which the product Features appears in the Data Sheet?

Example: In Admin I have the follow Features availble (in this order):

Height
Width
Depth
Weight
Size
Diameter
Form
Length

When I put in values for Height, Size, Diameter and Form they appear in this order in the Shop:

Size
Height
Form
Diameter

Why? And is it possible to edit this? Btw, using 1.1 Final.

Link to comment
Share on other sites

By the look of it (from my example above), the order of appearance of Features in the Shop is just haphazard. That seems odd, doesn't it? Is there perhaps some way of controlling this by the order in which one introduces the features in Admin? But it doesn't look like that either...

Link to comment
Share on other sites

  • 4 months later...

This is a quick hack to organize your features(in de same way you organize your categories):

Edit file classes/Product.php

Replace:

   /*
   * 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));
   }


With:

   /*
   * 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)
   {
       $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` ASC');

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



Now your can organize your features by putting the position in front of it, followed by a dot

For example:

01.Feature1
02.Feature2

  • Like 1
Link to comment
Share on other sites

  • 9 months later...

can someone help.. using this method in classes/product.php function getAttributesGroups to sort attributes and groups with '##.' prefixes, but unable to strip the numbers for display as im not familiar with this whole 'al.' syntax so i dont know what to change 'name' to to strip it

Link to comment
Share on other sites

  • 4 weeks later...
can someone help.. using this method in classes/product.php function getAttributesGroups to sort attributes and groups with '##.' prefixes, but unable to strip the numbers for display as im not familiar with this whole 'al.' syntax so i dont know what to change 'name' to to strip it


u can try this module ...

http://www.presto-changeo.com/attribute-modules/24-attribute-order.html#idTab5

it works fine ...




This way doesnt work for me ...

it works for the Categories but doesnt work in features ...

im using persian version of prestashop ...

i think the problem is caused by this but as i said i have no problem with sorting categories with this way ...

i tried english titles and persian both,
Link to comment
Share on other sites

  • 1 month later...

This no longer works in latest version (1.3.x)

I use:

   /*
   * 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).' order by name');

      $resultsArray = array();
       foreach ($result AS $row)
       {
                       $row['name'] = Product::hideFeaturePosition($row['name']);
           $resultsArray[] = $row;
       }
       return $resultsArray;

   }

       static public function hideFeaturePosition($name)
   {
       return preg_replace('/^[0-9]+\./', '', $name);
   } 



But no luck. The numbers stay visible. Weird though as I checked with the categories and that is still using the same code (and does work ;) )

Any idea's?

Link to comment
Share on other sites

  • 1 month later...

Hello,

don't work for me. i use 1.3 version

The prefix appear and filter order doesn't work...

my code

    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` ASC');

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



help me please...
thx

Link to comment
Share on other sites

  • 2 weeks later...

I just found another discussion talking about the same problem
http://www.prestashop.com/forums/viewthread/36968/P0/discussion_generale/gestion_de_lordre_daffichage_des_caracteristiques

However, they had a better UI presentation
by using:
FRUIT.01.Appellation
FRUIT.02.Origine
FRUIT.03….
AUTO.01.Puissance fiscale
AUTO.02.Nombre de portes
AUTO.03….
into:
FRUIT
Origine
Appellation
[…]

AUTO
Puissance fiscale
Nb de portes
[…]

Can someone help? Please

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...
This no longer works in latest version (1.3.x)

I use:

   /*
   * 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).' order by name');

      $resultsArray = array();
       foreach ($result AS $row)
       {
                       $row['name'] = Product::hideFeaturePosition($row['name']);
           $resultsArray[] = $row;
       }
       return $resultsArray;

   }

       static public function hideFeaturePosition($name)
   {
       return preg_replace('/^[0-9]+\./', '', $name);
   } 



But no luck. The numbers stay visible. Weird though as I checked with the categories and that is still using the same code (and does work ;) )

Any idea's?



You didn't change all the code
return Db::getInstance()->ExecuteS('

is still there

/Mats

Link to comment
Share on other sites

  • 1 month later...

Has anybody been able to get this to work on 1.3.2.3 or 1.3.3?

I've tried the code from this thread, as well as the code over on the French thread, and its not stripping out the numbers.

I really don't even need to have the features listed in a custom order, just listed in the order I entered them in!

Can anyone help please?

Link to comment
Share on other sites

Hi 5ummer5 - I realise the code provided is only supposed to be for the front end. On the french thread though, there is mention of modifying admin/tabs/AdminProducts.php (the displayFormFeatures function) to get it to work in the BO too - but no actual code is provided.

I was just wondering whether anyone has gotten it to work in the BO and if so, could they provide their code for it. I would save me a hell of a lot of messing about, especially as my php skills suck! :)

Link to comment
Share on other sites

  • 4 weeks later...

You can get the features to sort in the BO (01. 02. etc) by editing the first section of the displayList() function in admin/tabs/AdminFeatures.php so it looks like this (don't replace the whole function with this code - just add the 'Modded' part):

    
/* Report to AdminTab::displayList() for more details */
   public function displayList()
   {
       global $currentIndex;

       echo '

table.'&token;='.$this->token.'">'.$this->l('Add feature').'

token.'"> '.$this->l('Add feature value').'


       '.$this->l('Click on the feature name to view its values. Click again to hide them.').'

';

       $this->displayListHeader();
       echo '<input type="hidden" name="groupid" value="0">';

       if (!sizeof($this->_list))
           echo ''.$this->l('No features found.').'';
                   $irow = 0;

   //  ***********  Modded - added to sort features by 01.  02. etc  ************  //

       $tmp = Array();

       foreach($this->_list as &$ma)
           $tmp[] = &$ma["name"];

       array_multisort($tmp, $this->_list);         


   //  *********** / Modded - added to sort features by 01.  02. etc  ************  //


       foreach ($this->_list AS $tr)



This should work with v 1.3.x (tested on v 1.3.5)

Link to comment
Share on other sites

  • 4 weeks later...

Have another look at the instructions at the beginning of my post (immediately above your post).

You need to edit the file and insert the modded code section, then save it. Make sure you use a text editor (not a word-processor) for editing.

You also need to rename your features so they have a sort code in front of the name, eg:

01.Name of feature
02.Name of feature

Link to comment
Share on other sites

Thanks pixel. It works!

Before, I try to edit modded code at:

 $tmp[] = &$ma["name"];



and change to

 $tmp[] = &$ma["id_feature"];



I hope it will sort by id, but didn't work.

Before I was afraid the number will be displayed on front office, but it is not.

Thanks for the script. It works great for me.

PS: But it cause problem on Filter Search. The number is displayed. Still looking script to solve this.

Updated: To Remove number on Filter Search, change the code at coremanager/modules/filtersearch/filtersearch.module.php about line 166.

'.$group' 



to

'.preg_replace('/^[0-9]+\./', '',$group).' 

Link to comment
Share on other sites

Hi rastak,

The product features, by default sort by name on Front Office, but sort by ID on Back Office. The idea to change the script is to make the same sorting on Front Office and Back Office.

You have nothing to change on Front Office, but need to add some script on Back Office. See post #22 above to change script on Back Office.

After changed, one thing you have to do is to make some features like usual, but by add numbers (01, 02, etc) in front of the features name. Example: 01.Width, 02.Height, 03.Depth. On Back Office, number will be displayed. But I think it doesn't matter because just the website admin will look into back office.

On front office, number and dot (.) will be disappear, because there is default script from prestashop that eliminate the number.

Link to comment
Share on other sites

Do you mean you want to use number and dot (.) on front office?

If do so, you have to delete some script on prestashop core (I don't recommend this, but this will be work).

Go to prestashop/classes/product.php and go to about line 2339:

Original:

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



Then, delete all the script above. Make sure you don't delete } at the end of script (after return $resultsArray;).

So Now whatever you write on your feature will displayed as it is.

Link to comment
Share on other sites

  • 1 month later...

Hi there,

Can anyone help me re-ordering the feature list isng PS 1.4.0.15?
I've looked at the Classes/Product.php and it looks a bit different from what is quoted in earlier posts.

Here is the code, could someone help me modify it?

    /*
   * Select all features for a given language
   *
   * @param $id_lang Language id
   * @return array Array with feature's data
   */
   public static function getFrontFeaturesStatic($id_lang, $id_product)
   {
       if (!array_key_exists($id_product.'-'.$id_lang, self::$_frontFeaturesCache))
       {
           self::$_frontFeaturesCache[$id_product.'-'.$id_lang] = Db::getInstance(_PS_USE_SQL_SLAVE_)->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 = '.(int)$id_lang.')
           LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = '.(int)$id_lang.')
           WHERE pf.id_product = '.(int)$id_product);
       }
       return self::$_frontFeaturesCache[$id_product.'-'.$id_lang];
   }



Thanks in advance

Link to comment
Share on other sites

I waited for a while for someone to help me with this issue (reordering the features to my preferred order), but no-one offered to help. So I had another bash at it and I think it works using PS1.4.0.15 (RC6). Hopefully PS will implement changing the orders from the Backend instead.

Open and change classes/propduct.php in the prestashop root directory (not in the THEME). Note that this will need to be re-done every time you upgrade.

Change (around 2646):

public static function getFrontFeaturesStatic($id_lang, $id_product)
    {
        if (!array_key_exists($id_product.'-'.$id_lang, self::$_frontFeaturesCache))
        {
            self::$_frontFeaturesCache[$id_product.'-'.$id_lang] = Db::getInstance(_PS_USE_SQL_SLAVE_)->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 = '.(int)$id_lang.')
            LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = '.(int)$id_lang.')
            WHERE pf.id_product = '.(int)$id_product);
        }
        return self::$_frontFeaturesCache[$id_product.'-'.$id_lang];
    }



to:

public static function getFrontFeaturesStatic($id_lang, $id_product)
    {
        if (!array_key_exists($id_product.'-'.$id_lang, self::$_frontFeaturesCache))
        {
            self::$_frontFeaturesCache[$id_product.'-'.$id_lang] = Db::getInstance(_PS_USE_SQL_SLAVE_)->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 = '.(int)$id_lang.')
            LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = '.(int)$id_lang.')
            WHERE pf.id_product = '.(int)$id_product.'
                    ORDER BY `name`');
        }
        $resultsArray = array();
                foreach (self::$_frontFeaturesCache[$id_product.'-'.$id_lang] AS $row)
                {
                    $row['name'] = preg_replace('/^[0-9]+\./', '', $row['name']);
                    $resultsArray[] = $row;
                }
                return $resultsArray;;
    }



This does two things: sorts the features by alphabetical, ie 01.feature1, 02.feature2, 03.feature3.
Then strips the “01.” from each feature thus restoring the name.
For this to work you need to rename your features 01.feature1, 02.feature2, 03.feature3 for this to work.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...

Hi there,
rather than just sorting features in back office, is it possibile to code some "filtering" option? I mean, if i sell say cameras, books adn videogames, i'd like to see in backoffice>products>features page just the features list for a specified category. Is it possible?

Link to comment
Share on other sites

@rams: Have you find a solution to the compare list problem? I think you need to do some changes in the products-comparisation file. I dont have the knowlage myself to know exactly what to change but i hope someone else can help you as i am curious to know if this is possible to make :-)

Link to comment
Share on other sites

  • 4 weeks later...

Before

/*
   * 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));
   }


After

/*
   * 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).' order by pf.id_feature');
   }


Sorting Id Fuetured

  • Like 1
Link to comment
Share on other sites

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

everything is done
just add a new column on table features and call it sortfeatures then you have to change two files
classes/product.php & feature.php and just add to sort it by sortfeatures

this fixes also comparison problem... files will be available sood for bo and fo

Link to comment
Share on other sites

  • 1 month later...
  • 4 weeks later...
Hi, i currently have the 1.4.4.0 version of prestashop. Wich modification i have to make in order to dissapear the numbers from the product compare? Thank you!

Change Feature.php in classes from:

public static function getFeaturesForComparison($list_ids_product, $id_lang)
{
 $ids = '';
 foreach($list_ids_product as $id)
  $ids .= (int)($id).',';

 $ids = rtrim($ids, ',');

 if (empty($ids))
  return false;

 return Db::getInstance()->ExecuteS('
 SELECT * , COUNT(*) as nb
 FROM `'._DB_PREFIX_.'feature` f
 LEFT JOIN `'._DB_PREFIX_.'feature_product` fp ON f.`id_feature` = fp.`id_feature`
 LEFT JOIN `'._DB_PREFIX_.'feature_lang` fl ON f.`id_feature` = fl.`id_feature`
 WHERE fp.`id_product` IN ('.$ids.')
 AND `id_lang` = '.(int)($id_lang).'
 GROUP BY f.`id_feature`
 ORDER BY nb DESC');
}
}

to:

public static function getFeaturesForComparison($list_ids_product, $id_lang)
{
$ids = '';
foreach($list_ids_product as $id)
$ids .= (int)($id).',';

$ids = rtrim($ids, ',');

if (empty($ids))
return false;

$result = Db::getInstance()->ExecuteS('
SELECT * , COUNT(*) as nb
FROM `'._DB_PREFIX_.'feature` f
LEFT JOIN `'._DB_PREFIX_.'feature_product` fp ON f.`id_feature` = fp.`id_feature`
LEFT JOIN `'._DB_PREFIX_.'feature_lang` fl ON f.`id_feature` = fl.`id_feature`
WHERE fp.`id_product` IN ('.$ids.')
AND `id_lang` = '.(int)($id_lang).'
GROUP BY f.`id_feature`
ORDER BY `name` ASC');  

$resultsArray = array();
	foreach ($result AS $row)
	{
		$row['name'] = preg_replace('/^[0-9]+./', '', $row['name']);
		$resultsArray[] = $row;
	}
	return $resultsArray;;
}
}

Link to comment
Share on other sites

  • 4 weeks later...
  • 4 weeks later...
  • 4 weeks later...
  • 1 month later...

I created a new topic related to this, in a gist what I would like to do is properly override this function using the /override/classes/ folder.

 

Has anyone attempted or succeeded in this?

 

I tried the following code in a file I created /override/classes/Product.php but it doesn't work it still shows the numbers.

 

class Product extends ProductCore {
public static function getFrontFeaturesStatic($id_lang, $id_product)
{
 if (!array_key_exists($id_product.'-'.$id_lang, self::$_frontFeaturesCache))
 {
  self::$_frontFeaturesCache[$id_product.'-'.$id_lang] = Db::getInstance(_PS_USE_SQL_SLAVE_)->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 = '.(int)$id_lang.')
  LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = '.(int)$id_lang.')
  WHERE pf.id_product = '.(int)$id_product.' order by name ASC');
 }

 /* Added Array Function to remove the Numbers at the beginning of the Feature */
 $resultsArray = array();
 foreach (self::$_frontFeaturesCache[$id_product.'-'.$id_lang] AS $row) {
  $row['name'] = preg_replace('/^[0-9]+\./', '', $row['name']);
  $resultsArray[] = $row;
 }
 return $resultsArray;
}
}

Link to comment
Share on other sites

I have since made this work as I was trying above... new code listed below.

 

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` ASC');
   $resultsArray = array();
    foreach ($result AS $row)
    {
	    $row['name'] = product::hideFeaturePosition($row['name']);
	    $resultsArray[] = $row;
    }
    return $resultsArray;
   }
   static public function hideFeaturePosition($name)
   {
    return preg_replace('/^[0-9]+./', '', $name);
   }
   public function getFrontFeatures($id_lang)
   {
    return self::getFrontFeaturesStatic($id_lang, $this->id);
   }

 

currently using v1.4.4.0 and have not tested it on newer versions but I am sure to do so soon.

  • Like 4
Link to comment
Share on other sites

  • 1 month later...

Hey vayu,

 

I have not even messed with the backend area but I would see it as possible but it would be a lot more coding modifications... at least from what I have read about the backend it is setup a little different and made less for customization and more just about working as it is.

 

Just getting back from a couple of trade shows and etc, so hopefully I can start looking at this code again.

Link to comment
Share on other sites

Hi icyhot.

 

Yes, I have just tested Bradleys code and it works for me in the frontend. :-)

 

Vayu

 

Thanks vayu and Bradley!

But I have a simple question.

What do you guys mean by it works on the front side but not on the back side?

Isn't the front side what we care? I mean.. to me I don't care as long as the customers don't get confused.

I don't mind me (admin) seeing the features in the wrong order.

 

Am I getting something wrong here? or Am I on the right track?

Link to comment
Share on other sites

I am so sorry guys.. I created the Product.php file in /override/classes/

with the code posted on post #54 but I got the following error on my front store with a blank background.

 

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` ASC'); $resultsArray = array(); foreach ($result AS $row) { $row['name'] = product::hideFeaturePosition($row['name']); $resultsArray[] = $row; } return $resultsArray; } static public function hideFeaturePosition($name) { return preg_replace('/^[0-9]+./', '', $name); } public function getFrontFeatures($id_lang) { return self::getFrontFeaturesStatic($id_lang, $this->id); }
Link to comment
Share on other sites

Hi.

 

I think it is quite relevant for the user experience, that the order in the backend matches the order of the front end. I know it is not as important, but it will make more sence for the unexperinced user if they have the same order in both areas.

 

Bradley, it would be cool if you find a solution for this. :-)

 

Icyhot - I don't know why you get an error. However, what you have posted is not the error, but the actual function. If you go into config->config.inc.php change "display_errors" to true, then it will spit out what error you are getting.

 

Vayu

Link to comment
Share on other sites

Hi.

 

I think it is quite relevant for the user experience, that the order in the backend matches the order of the front end. I know it is not as important, but it will make more sence for the unexperinced user if they have the same order in both areas.

 

Bradley, it would be cool if you find a solution for this. :-)

 

Icyhot - I don't know why you get an error. However, what you have posted is not the error, but the actual function. If you go into config->config.inc.php change "display_errors" to true, then it will spit out what error you are getting.

 

Vayu

 

How did you get it to work?

Can you teach me?

So all you have to do is create the a php file and copy and paste his code in there.

and name it Product.php

and put it in the /override/classes/ folder..

 

Am I right?

Link to comment
Share on other sites

  • 3 weeks later...

This one is working. I adapted it from Rneo's post. Just change a little bit at the bottom of the SQL code. I'm working on ver 1.4

 

Before

WHERE pf.id_product = '.(int)$id_product);

 

After

WHERE pf.id_product = '.(int)$id_product.' ORDER BY pf.id_feature');

 

Before

/*
* 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));
}

After

/*
* 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).' order by pf.id_feature');
}

Sorting Id Fuetured

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...
This is a quick hack to organize your features(in de same way you organize your categories):

 

Edit file classes/Product.php

 

Replace:

/*
* 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));
}

With:

/*
* 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)
{
$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` ASC');

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

 

Now your can organize your features by putting the position in front of it, followed by a dot

 

For example:

 

01.Feature1

02.Feature2

 

Worked perfectly on 1.4.7. Thank you for this awesome trick.

Link to comment
Share on other sites

  • 1 month later...

i did some modification on newer presta, and it works too

 

public static function getFrontFeaturesStatic($id_lang, $id_product)
   {
       if (!array_key_exists($id_product.'-'.$id_lang, self::$_frontFeaturesCache))
       {
           self::$_frontFeaturesCache[$id_product.'-'.$id_lang] = Db::getInstance(_PS_USE_SQL_SLAVE_)->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 = '.(int)$id_lang.')
           LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = '.(int)$id_lang.')
           WHERE pf.id_product = '.(int)$id_product.'
           ORDER BY `name` ASC');

           /* Modify SQL result */
           $resultsArray = array();
           foreach (self::$_frontFeaturesCache[$id_product.'-'.$id_lang] AS $row)
           {
               $row['name'] = preg_replace('/^[0-9]+\./', '', $row['name']);
               $resultsArray[] = $row;
           }
           return $resultsArray;
       }
       return self::$_frontFeaturesCache[$id_product.'-'.$id_lang];
   }

 

on Feature, set em like this

 

01.Feature1

02.Feature2

 

hope this help :)

  • Like 2
Link to comment
Share on other sites

Need help please.

 

I can add a prefix to each feature in the BO and then list the Product Features in ascending order.

BUT I can't figure out how to strip the prefix.

 

e.g. myfeature1, myfeature2

becomes 001.myfeature1, 002myfeature2 etc

 

and this code works fine

 

public static function getFrontFeaturesStatic($id_lang, $id_product)
{
	if (!array_key_exists($id_product.'-'.$id_lang, self::$_frontFeaturesCache))
	{
		self::$_frontFeaturesCache[$id_product.'-'.$id_lang] = Db::getInstance(_PS_USE_SQL_SLAVE_)->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 = '.(int)$id_lang.')
		LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = '.(int)$id_lang.')
		WHERE pf.id_product = '.(int)$id_product.'
		ORDER BY `name` ASC');


	}
	return self::$_frontFeaturesCache[$id_product.'-'.$id_lang];
}

 

But I can't figure out how/where to insert this block of code (as mentioned earlier in the thread)

 

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

 

When I try this

 

public static function getFrontFeaturesStatic($id_lang, $id_product)
{
	if (!array_key_exists($id_product.'-'.$id_lang, self::$_frontFeaturesCache))
	{
		self::$_frontFeaturesCache[$id_product.'-'.$id_lang] = Db::getInstance(_PS_USE_SQL_SLAVE_)->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 = '.(int)$id_lang.')
		LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = '.(int)$id_lang.')
		WHERE pf.id_product = '.(int)$id_product.'
		ORDER BY `name` ASC');

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


	}
	return self::$_frontFeaturesCache[$id_product.'-'.$id_lang];
}

 

it just "kills" the features tab entirely. Nothing shows for that tab.

 

* PLUS * how can I also trim feature prefix on the Product Compare page?

I'd rather not fiddle with adding extra database columns if possible.

 

I am using PSvers 1.4.7.0

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

look into my code, above your post, hope that help :)

 

Oh, thank you. I didnt notice those updates. !

 

Before I try, can I ask - does this fix the problem for BOTH the product page and the product comparison page?

I need to list the features in a consistent order for both.

Link to comment
Share on other sites

I would like to have the attributes arranged in the order of size Small, Medium, Large, Xlarge but cannot get it to work.

The code above does not seem to work for attributes any ideas as the prefixes are not removed.

01.small = 01.small and so on I could easily just have 1,2,3,4 and put them in order but thats just not what I want.

Seems like a real oversite on the Prestashop side.

Link to comment
Share on other sites

I would like to have the attributes arranged in the order of size Small, Medium, Large, Xlarge but cannot get it to work.

The code above does not seem to work for attributes any ideas as the prefixes are not removed.

01.small = 01.small and so on I could easily just have 1,2,3,4 and put them in order but thats just not what I want.

Seems like a real oversite on the Prestashop side.

 

This thread is about Features, not Attributes. Two entirely different animals.

 

However, I can recommend the PrestoChangeo Attributes Wizard Module which does exactly what you want, and more.

Be aware though, that installing it DOES require quite a bit of core file modification, which could be an issue come upgrade time.

Link to comment
Share on other sites

This thread is about Features, not Attributes. Two entirely different animals.

 

However, I can recommend the PrestoChangeo Attributes Wizard Module which does exactly what you want, and more.

Be aware though, that installing it DOES require quite a bit of core file modification, which could be an issue come upgrade time.

 

 

Well aware of what this thread is about.

Thanks anyway!!!

Link to comment
Share on other sites

nope, that's only to modify product page

 

you'll need to modify this function too

public static function getFeaturesForComparison

 

same code, just need to copy paste the code there

Link to comment
Share on other sites

  • 2 months later...
  • 2 months later...
  • 2 years later...
  • 2 weeks later...

Disregard previous post - I've worked out my issue.

 

The problem was that in my database, in table "ps_features", the "position" values were all incorrect. 

 

The solution is to go into the table "ps_features_lang" and map out the names of your features and the "id_feature". Then, go back to the table "ps_features" and change the "position" values so that they are in the correct order.

Link to comment
Share on other sites

  • 5 months later...

Hello every one,

I have a little problem. 

I can;t find how to fix feature products problem. I added in an specificaly order all featured, but now always i find them random. Is hard to search between them when i add features to a product. 

Here i got a printscreen: http://prntscr.com/9lw9ot  - i want to keep the ID order, but somehow, they change the order and dublicated the position number

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