优化magento属性筛选URL(layer filter)
一:config.xml 重写filter item
<?xml version="1.0"?>
<config>
<modules>
<More_LayerCatSeo>
<version>0.1.0</version>
</More_LayerCatSeo>
</modules>
<global>
<models>
<devopencatseo>
<class>More_LayerCatSeo_Model</class>
<resourceModel>devopencatseo_resource</resourceModel>
</devopencatseo>
<devopencatseo_resource>
<class>More_LayerCatSeo_Model_Resource</class>
</devopencatseo_resource>
<catalog>
<rewrite>
<layer_filter_item>More_LayerCatSeo_Model_Layer_Filter_Item</layer_filter_item>
</rewrite>
</catalog>
</models>
<helpers>
<devopencatseo>
<class>More_LayerCatSeo_Helper</class>
</devopencatseo>
</helpers>
</global>
</config>
二:实现方法:
app/code/local/More/LayerCatSeo/Model/Layer/Filter/
class More_LayerCatSeo_Model_Layer_Filter_Item extends Mage_Catalog_Model_Layer_Filter_Item
{
/**
* Get filter item url
*
* @return string
*/
public function getUrl()
{
if($this->getFilter()->getRequestVar() == "cat"){
$category_url = Mage::getModel('catalog/category')->load($this->getValue())->getUrl();
$return = $category_url;
$request = Mage::getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true));
if(strpos($request,'?') !== false ){
$query_string = substr($request,strpos($request,'?'));
}
else{
$query_string = '';
}
if(!empty($query_string)){
$return .= $query_string;
}
return $return;
}
else{
$query = array(
$this->getFilter()->getRequestVar()=>$this->getValue(),
Mage::getBlockSingleton('page/html_pager')->getPageVarName() => null // exclude current page from urls
);
return Mage::getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true, '_query'=>$query));
}
}
}
(责任编辑:最模板) |