Try the Demo

Magento

eCommerce Software for Online Growth

Magento Forum

Our new hosted solution for small & emerging businesses
   
Layered navigation - URL changes
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

I am attempting to change the URL in the layered navigation so it doesn’t use ID numbers (but instead use the text value of the attribute being filtered)

So I would like to change http://localhost/magento115/cat1/subcat11?color=6 to http://localhost/magento115/cat1/subcat11?color=white

On one end of this spectrum is this code in app/code/core/Mage/Catalog/Model/Layer/Filter/Attribute.php function apply()

protected  function _getOptionText($optionId)
    
{
        
return $this->getAttributeModel()->getFrontend()->getOption($optionId);
    
}


 
public function apply(Zend_Controller_Request_Abstract $request$filterBlock)
    
{
        $filter 
$request->getParam($this->_requestVar);
        
//$fitler = the number (id, for instance '6') of the attribute
        
$text $this->_getOptionText($filter);
       
//$text = outputs the text value (color , for instance 'white')
        
if ($filter && $text{
            
/*$entityIds = Mage::getSingleton('catalogindex/attribute')->getFilteredEntities($this->getAttributeModel(), $filter, $this->_getFilterEntityIds());
            if ($entityIds) {
                $this->getLayer()->getProductCollection()
                    ->addFieldToFilter('entity_id', array('in' => $entityIds));

                $this->getLayer()->getState()->addFilter(
                    $this->_createItem($text, $filter)
                );
                $this->_items = array();
            }*/
            
Mage::getSingleton('catalogindex/attribute')->applyFilterToCollection(
                
$this->getLayer()->getProductCollection(),
                
$this->getAttributeModel(),
                
$filter
            
);
            
$this->getLayer()->getState()->addFilter($this->_createItem($text$filter));
            
$this->_items = array();
        
}
        
return $this;
    
}

In this example, I need a way to get the id from the text (which is the opposite of how the above code works).

The function _getOptionText (also above) does the opposite of this as well.

Any ideas on how to accomplish this?

 Signature 

@ My Magento Blog

- Handy tutorials on programming and designing Magento. A continual work in progress!
- Now with a new design, new hosting and a new domain! Check it out!

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

I was hoping someone has some idea of how I would be able to take an attribute name/value (’color’ and ‘white’ for instance) and get an ID from it? (Some method I don’t know about or haven’t thought about?)

 Signature 

@ My Magento Blog

- Handy tutorials on programming and designing Magento. A continual work in progress!
- Now with a new design, new hosting and a new domain! Check it out!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Thissel
Sr. Member
 
Total Posts:  79
Joined:  2007-11-06
 

Hey nikefido

I am having the exact same question.
Have you found a way to do it yet?

Best regards.

 Signature 

Mathias Hoffmann
Companion Internet Solutions

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
 
© Copyright 2012 Magento Inc.
Privacy Policy|Terms of Service
Magento Community Count
701238 users|865 users currently online|497293 forum posts