Alphabetic Option Value Ordering in Magento’s Layered Navigation

Magento will by default order layered navigation options by position. To use alphabetic values first and foremost, do the following:

Override the Eav_Entity_Attribute_Source_Table model

<global>
    <models>
        <eav>
            <rewrite>
        	    <entity_attribute_source_table>Namespace_Module_Model_Eav_Entity_Attribute_Source_Table</entity_attribute_source_table>
        	</rewrite>
        </eav>
    </models>
</global>

PHP

Override the getAllOptions method as follows:

<?php
class Namespace_Module_Model_Eav_Entity_Attribute_Source_Table extends Mage_Eav_Model_Entity_Attribute_Source_Table
{
    public function getAllOptions($withEmpty = true, $defaultValues = false)
    {
        $storeId = $this->getAttribute()->getStoreId();
        if (!is_array($this->_options)) {
            $this->_options = array();
        }
        if (!is_array($this->_optionsDefault)) {
            $this->_optionsDefault = array();
        }
        if (!isset($this->_options[$storeId])) {
            $collection = Mage::getResourceModel('eav/entity_attribute_option_collection')
                ->setAttributeFilter($this->getAttribute()->getId())
                ->setStoreFilter($this->getAttribute()->getStoreId());

            $collection->getSelect()->order(['main_table.sort_order asc', 'value asc']);
            $collection->load();

            $this->_options[$storeId]        = $collection->toOptionArray();
            $this->_optionsDefault[$storeId] = $collection->toOptionArray('default_value');
        }



        $options = ($defaultValues ? $this->_optionsDefault[$storeId] : $this->_options[$storeId]);
        if ($withEmpty) {
            array_unshift($options, array('label' => '', 'value' => ''));
        }

        return $options;
    }
}

This uses sort order first, then uses value to order the attribute options.

Adding Values For Multiselect Attributes in Magento

Add this to your XML;

<global>
 <sales>
            <quote>
                <item>
                    <product_attributes>
                        <location />
                    </product_attributes>
                </item>
            </quote>
        </sales>
	</global>
  • This makes the product attributes accessible to the Mage_Sales_Model_Quote_Config class’ getProductAttributes() method. This reads in the sales/quote/item/product_attributes node.

  • This is called by the _assignProducts method of the “`Mage_Sales_Model_Resource_Quote_Item_Collection’s _assignProducts() method, where it adds all of the attributes to the product collection of the quote item collection.

Copy the attributes to the quote item

Unlike copying from quote items to order items, there isn’t an XML method to do this – it has to be accomplished through an observer. Add the following to the config (with the observer / method substituted):

<frontend>
    <events>
         <sales_quote_item_set_product>
             <observers>
                 <observer_name>
                        <class>model/observer</class>
                        <method>addAttributesToQuoteItem</method>
                 </observer_name>
             </observers>
         </sales_quote_item_set_product>
    </events>
</frontend>

Then create the following method for the observer above:

    public function addAttributesToQuoteItem($observer){
        $quoteItem = $observer->getQuoteItem();
        $product = $observer->getProduct();
        $quoteItem->setLocation($product->getLocation());
    }