1

Set up your attributes order in "Attributes set" as you wish to be listed in frontend (product page and compare window). In product page attributes are listed in correct order (Additional information section). Now add this product to compare list. Compare it.

Attributes order should be the same like you set it up in "Attribute set" and same like in Additional information. In compare window attributes are in a different order. This need a fix since is a bug. Maybe a global position that can be changed for an attribute could solve elegant this issue. There is a position field but for Layering Navigation only.

2 Answers 2

1

This is how I solved the problem. Override this file

app\code\core\Mage\Catalog\Model\Resource\Product\Compare\Item\Collection.php

as

app\code\local\Mage\Catalog\Model\Resource\Product\Compare\Item\Collection.php

Around line 220, find "public function getComparableAttributes()"

Comment the original function and replace it with the following code

/** Function overridden by nadshez to fix sort order in comparison list */
public function getComparableAttributes()
{
    if (is_null($this->_comparableAttributes)) {
        $this->_comparableAttributes = array();
        $setIds = $this->_getAttributeSetIds();
        if ($setIds) {
            $select = $this->getConnection()->select()
                ->from(array('main_table' => $this->getTable('eav/attribute')))
                ->join(
                    array('additional_table' => $this->getTable('catalog/eav_attribute')),
                    'additional_table.attribute_id=main_table.attribute_id'
                )
                ->joinLeft(
                    array('al' => $this->getTable('eav/attribute_label')),
                    'al.attribute_id = main_table.attribute_id AND al.store_id = ' . (int) $this->getStoreId(),
                    array('store_label' => new Zend_Db_Expr('IFNULL(al.value, main_table.frontend_label)'))
                )
                ->joinLeft(
                    array('ai' => $this->getTable('eav/entity_attribute')), 
                    'ai.attribute_id = main_table.attribute_id'
                )
                ->where('additional_table.is_comparable=?', 1)
                ->where('ai.attribute_set_id IN(?)', $setIds)
                ->order(array('ai.attribute_group_id ASC', 'ai.sort_order ASC'));
            $attributesData = $this->getConnection()->fetchAll($select);
            if ($attributesData) {
                $entityType = 'catalog_product';
                Mage::getSingleton('eav/config')
                    ->importAttributesData($entityType, $attributesData);
                foreach ($attributesData as $data) {
                    $attribute = Mage::getSingleton('eav/config')
                        ->getAttribute($entityType, $data['attribute_code']);
                    $this->_comparableAttributes[$attribute->getAttributeCode()] = $attribute;
                }
                unset($attributesData);
            }
        }
    }
    return $this->_comparableAttributes;
}

That's it. Hope this helps. Kindly one up my answer if it resolved your problem. Thanks.

2

So the comparable attributes are built by the function Mage_Catalog_Model_Resource_Product_Compare_Item_Collection::getComparableAttributes

Now the function works as follows.

  1. Get attribute set ids,
  2. Get attribute ids from these set ids,
  3. Load attribute information from the database,
  4. Build the attribute array with the attribute code as key,

Now apart from only loading attributes that are in the set ids I cannot see anything that groups the attributes by set ids.

I would suggest that if you rewrite this function you could either add the group clause to the select or build the array _comparableAttributes in a different way. Doing either of these should solve your issue and group the attributes by set.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.