php Сustom类别过滤器解析URL类别过滤器按自定义过滤器按属性自定义过滤器自定义排序
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Сustom类别过滤器解析URL类别过滤器按自定义过滤器按属性自定义过滤器自定义排序相关的知识,希望对你有一定的参考价值。
<div class="sorter">
<?php if( $this->isExpanded() ): ?>
<div class="sort-by sorting">
<?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
<?php if( strrpos($current_url,'catalogsearch/result') != false and $_key == 'relevance' or strrpos($current_url,'catalogsearch/advanced') != false and $_key == 'relevance' ): ?>
<label><a href="<?php echo $this->getOrderUrl($_key, 'asc') ?>"><?php echo $this->__('Sort By') ?></a> </label>
<?php endif; ?>
<?php if( $_key == 'position' ): ?>
<label><a href="<?php echo $this->getOrderUrl($_key, 'asc') ?>"><?php echo $this->__('Sort By') ?></a> </label>
<?php endif; ?>
<?php endforeach; ?>
<ul>
<?php foreach($this->getAvailableOrders() as $_key=>$_order): if( $_key == 'price' ): ?>
<li <?php if($this->isOrderCurrent($_key) and $this->getCurrentDirection() == 'asc'): ?>class="active"<?php endif; ?>><a href="<?php echo $this->getOrderUrl($_key, 'asc') ?>"><?php echo $this->__('Increasing price') ?></a></li>
<li <?php if($this->isOrderCurrent($_key) and $this->getCurrentDirection() == 'desc'): ?>class="active"<?php endif; ?>><a href="<?php echo $this->getOrderUrl($_key, 'desc') ?>"><?php echo $this->__('Descending price') ?></a></li>
<?php endif; endforeach; ?>
</ul>
</div>
<?php endif; ?>
<?php if( strrpos($current_url,'catalogsearch/advanced') == false ): ?>
<?php
if(strpos($current_url,'?') !== false)
{
$current_url = $current_url.'&view-all=yes';
}else{
$current_url = $current_url.'?view-all=yes';
}
if( $attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product','label') ):
$current_url = $this->helper('core/url')->getCurrentUrl();
$url_arr = parse_url( $current_url );
if( $url_arr['query'] and strrpos( $current_url,'catalogsearch/result' ) != false )
{
$current_url_query = explode( '&', $url_arr['query'] );
foreach ( $current_url_query as $k => $url_var) {
if( stripos( $url_var, 'label' ) !== false ){
unset( $current_url_query[$k] );
}
}
$current_url_query = implode( '&', $current_url_query );
$filter_by_url = $url_arr['scheme'] . '://' . $url_arr['host'] . $url_arr['path'].'?'.$current_url_query;
}
elseif( $url_arr['query'] ){
$filter_by_url = $url_arr['scheme'] . '://' . $url_arr['host'] . $url_arr['path'];
}else{
$filter_by_url = $current_url;
}
?>
<div class="sort-by filters">
<label><a href="<?php echo $filter_by_url; ?>"><?php echo $this->__( 'Filter By' ); ?></a> </label>
<ul>
<?php
foreach( $attributeModel->getSource()->getAllOptions(false) as $filter):
$filter_url = '';
if( $url_arr['query'] )
{
$find_label = 0;
$current_url_query = explode( '&', $url_arr['query'] );
foreach ( $current_url_query as $k => $url_var) {
if( stripos( $url_var, 'label' ) !== false ){
$current_url_query[$k] = 'label='.$filter['value'];
$find_label = 1;
}
}
if( empty( $find_label ) ){
$current_url_query[] = 'label='.$filter['value'];
}
$current_url_query = implode( '&', $current_url_query );
$filter_url = $url_arr['scheme'] . '://' . $url_arr['host'] . $url_arr['path'].'?'.$current_url_query;
}
else
{
$filter_url = $url_arr['scheme'] . '://' . $url_arr['host'] . $url_arr['path'].'?label='.$filter['value'];
}
?>
<li <?php if( $_GET['label'] == $filter['value'] ): ?>class="active"<?php endif; ?>><a href="<?php echo $filter_url; ?>"><?php echo $filter['label']; ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
以上是关于php Сustom类别过滤器解析URL类别过滤器按自定义过滤器按属性自定义过滤器自定义排序的主要内容,如果未能解决你的问题,请参考以下文章