Jump to content

Changing attributes order in 1.4


tjjunior

Recommended Posts

To change the order of attributes in 1.4 (specifically 1.4.0.15) here's what I did:

Add a new column in the database table ps_attribute_lang. I used a name of orderby and type TinyInt. I then added in the order number that I wanted (e.g. all of the Smalls get 1, Mediums get 2, Larges 3 etc) in the orderby column.

In override -> classes I added a new file called Product.php:

<?php

class Product extends ProductCore
{

/**
   * Get all available attribute groups
   *
   * @param integer $id_lang Language id
   * @return array Attribute groups
   */
public function getAttributesGroups($id_lang)
   {
       return Db::getInstance()->ExecuteS('
       SELECT ag.`id_attribute_group`, ag.`is_color_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`, pa.`unit_price_impact`, pa.`minimal_quantity`
       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` = '.(int)($this->id).'
       AND al.`id_lang` = '.(int)($id_lang).'
       AND agl.`id_lang` = '.(int)($id_lang).'
       ORDER BY al.`orderby`');
   }
}




And in override ->controllers I added a file called ProductController.php (quoted in next post due to size):

Link to comment
Share on other sites

Still too big to copy in entirety so here's the important parts:

class ProductController extends ProductControllerCore
{


   public function process()
   {
       parent::process();
       global $cart;


...

//                    foreach($groups AS &$group)
//                        natcasesort($group['attributes']);
...
}



Basically the whole function process from the original controller (controllers -> ProductController.php) except comment out the two lines shown. My approach does move the Color attribute above the Size attribute, but that didn't bother me much. Hope it helps someone.

Link to comment
Share on other sites

  • 2 months later...

OK, I found the way to do it!
Just got the function "public function process()" from the class ProductController.php in the folder 'controllers' then copied it into 'override/controllers' and commented the part you mentioned..
Thank you!!

Link to comment
Share on other sites

  • 4 weeks later...

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