Jump to content

[SOLVED] Sort Attributes by Order Created


Recommended Posts

So I looked through pages of search on this forum and I have not been able to find a fix.

I have downloaded and implemented the 2 products.php filse that reverts the ordering of attributes by id instead by name. This works great when adding attributes manually. This however does nothing for when using The Combination Generator as this still Orders them Alphabetically causing my attributes to get created in alphabetical order.

Is there a fix for this somewhere? I tried looking for the SQL code that generates the combination Generator page but I'm afraid I can't find where that is.

Any Ideas would be much appreciated!

Rush

Link to comment
Share on other sites

ok I got it fixed... The change below will display the Attributes in the Attributes Generator page in the order the attributes were created! So just make sure you create them like you want them (ie: S, M, L, XL)

In classes/Attribute.php

Change:

static public function getAttributes($id_lang, $notNull = false)
{
return Db::getInstance()->ExecuteS('
SELECT ag.*, agl.*, a.`id_attribute`, al.`name`, agl.`name` AS `attribute_group`
FROM `'._DB_PREFIX_.'attribute_group` ag
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.intval($id_lang).')
LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute_group` = ag.`id_attribute_group`
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.intval($id_lang).')
'.($notNull ? 'WHERE a.`id_attribute` IS NOT NULL AND al.`name` IS NOT NULL' : '').'
ORDER BY agl.`name` ASC, al.`name` ASC');
}

TO:

static public function getAttributes($id_lang, $notNull = false)
{
return Db::getInstance()->ExecuteS('
SELECT ag.*, agl.*, a.`id_attribute`, al.`name`, agl.`name` AS `attribute_group`
FROM `'._DB_PREFIX_.'attribute_group` ag
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.intval($id_lang).')
LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute_group` = ag.`id_attribute_group`
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.intval($id_lang).')
'.($notNull ? 'WHERE a.`id_attribute` IS NOT NULL AND al.`name` IS NOT NULL' : '').'
ORDER BY a.`id_attribute` ASC, al.`name` ASC');
}

To see the Attributes sorted in the correct order in the Attributes & groups screen as well in

classes/AttributeGroup.php

Change:

static public function getAttributes($id_lang, $id_attribute_group)
{
return Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'attribute` a
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.intval($id_lang).')
WHERE a.`id_attribute_group` = '.intval($id_attribute_group).'
ORDER BY `name`');
}

To:

static public function getAttributes($id_lang, $id_attribute_group)
{
return Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'attribute` a
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.intval($id_lang).')
WHERE a.`id_attribute_group` = '.intval($id_attribute_group).'
ORDER BY '.$id_attribute_group.'');
}

hope this helps!

  • Like 1
Link to comment
Share on other sites

×
×
  • Create New...