Есть JavaScript, который преобразует ссылку в соответствии с выбранными параметрами фильтра:
$(document).ready(function(){
// Фильтр
var filterBlock = $(".filter");
var filter = new Filter2('filter2');
filterBlock.find("input").change(function(){
var blockOffset = filterBlock.offset();
var boxOffset = $(this).offset();
$(".notice",filterBlock).show().animate({
'top':(-blockOffset.top+boxOffset.top)+'px'
});
//if ($(":checked",filterBlock).length<1) { $(".notice",filterBlock).hide(); }
filter.save();
var url = 'filter/'+filter.items.join('/')+'/price/'+$("#price_from",filterBlock).val()+'/'+$("#price_to",filterBlock).val();
$(".notice a,a.button",filterBlock).attr('href',url);
});
if (filterBlock.length>0) {
var priceRange = $('.slider',filterBlock).slider({
range:true,
step:100,
min:$("#price_from").attr('rel'),
max:$("#price_to").attr('rel'),
values:[ parseInt($("#price_from").val()), parseInt($("#price_to").val()) ],
create:function(e,ui){
$(e.target).wrapInner('<div class="in"></div>');
},
slide: function(event,ui) {
$("#price_from").val(ui.values[0]);
$("#price_to").val(ui.values[1]);
},
change: function(event,ui) {
$("#price_from").change();
}
});
$(".reset",filterBlock).click(function(){
$("input",filterBlock).attr('checked',false);
$("#price_from").val($("#price_from").attr('rel'));
$("#price_to").val($("#price_to").attr('rel'));
priceRange.slider( "values" , [ parseInt($("#price_from").val()), parseInt($("#price_to").val()) ] );
$(".notice",filterBlock).hide();
filter.clear();
});
}
});
function Filter2(name) {
this.name = name;
this.items = [];
var block = $(".filter");
var counter = $("#found_count",block);
this._init = function(){
var cookie = $.cookie(this.name);
this.items = cookie ? $.parseJSON(cookie) : [];
if (!this.items) {
$.cookie(this.name, null);
}
//counter.text(this.count());
}
this.count = function(){
$.post('https://dress-sport.ru/filter/total',{},function(data){
counter.text(data);
if (data>0) {
counter.parent().find("a").show();
} else {
counter.parent().find("a").hide();
}
});
}
this.save = function() {
var items = [];
block.find("input:checked").each(function(i,item){
items[i] = $(item).val();
});
this.items = items;
$.cookie(this.name, $.toJSON(items), {expires:30,path:'/'});
$.cookie(this.name+'_price_from', $("#price_from",block).val(), {expires:30,path:'/'});
$.cookie(this.name+'_price_to', $("#price_to",block).val(), {expires:30,path:'/'});
this.count();
}
this.clear = function() {
this.items = [];
$.cookie(this.name, null);
$.cookie(this.name+'_price_from', null);
$.cookie(this.name+'_price_to', null);
counter.text(0);
}
this._init();
}
var MI = 0;
Сам контроллер фильтра:
<?php
/**
* Filter
*
* @author dandelion <web.dandelion@gmail.com>
*/
class App_Filter extends Controller
{
protected $itemsPerPage = 30;
function indexAction(array $params)
{
/**
* Параметры
*/
$page = 1;
if(in_array('page',$params))
{
$pageInd = array_search('page',$params);
if(isset($params[$pageInd+1]))
$page = $params[$pageInd+1];
unset($params[$pageInd]);
unset($params[$pageInd+1]);
}
if (!$page)
$page = 1;
$items = (array)json_decode(@$_COOKIE['filter'],true);
$start = ($page-1)*$this->itemsPerPage;
$products = $this->model->product->getByCriterias(array_values($items),$total,@$_COOKIE['filter_price_from'],@$_COOKIE['filter_price_to'], $start, $this->itemsPerPage);
foreach ($products as $product)
{
$product->code_brief = "<p>Артикул: $product->code </p>".$product->brief;
$this->tpl->assignBlockVars('product', array(
'ID' => $product->id,
'KEY' => $product->key,
'NAME' => $product->name,
'BRIEF' => nl2br($product->code_brief),
'LABEL' => $product->label,
'PRICE' => $product->price,
'PRICE_OLD' => $product->price_old,
'AMOUNT' => $product->brief
));
if ($product->picture)
{
$this->tpl->assignBlockVars('product.picture', array(
'SRC' => $product->picture
));
$photos = explode('|',$product->album);
foreach ($photos as $photo)
{
if ($photo)
$this->tpl->assignBlockVars('product.album', array(
'SRC' => $photo
));
}
}
if ($product->price)
$this->tpl->assignBlockVars('product.price');
if ($product->price_old)
$this->tpl->assignBlockVars('product.price_old');
/**
* Params
*/
$params = (array)json_decode($product->params,true);
foreach ($params as $param)
{
if (!empty($param['values']))
{
$this->tpl->assignBlockVars('product.param', array(
'NAME' => $param['name']
));
foreach ($param['values'] as $i=>$value)
{
$this->tpl->assignBlockVars('product.param.val', array(
'NUM' => $i,
'NAME' => @$value['value'],
'PRICE' => !empty($value['price']) ? $value['price'] : $product->price,
'PRICE_OLD' => !empty($value['price_old']) ? $value['price_old'] : (empty($value['price']) ? $product->price_old : '')
));
if ($i==0 && !empty($value['price']))
{
$this->tpl->appendBlockVars('product', array(
'PRICE' => @$value['price'],
'PRICE_OLD' => @$value['price_old']
));
if (!$product->price && !empty($value['price']))
$this->tpl->assignBlockVars('product.price');
if (!$product->price_old && !empty($value['price_old']))
$this->tpl->assignBlockVars('product.price_old');
}
}
}
}
}
/**
* Навигация
*/
$paginator = new Paginator(array(
'countPerPage' => $this->itemsPerPage,
'countOfEntries'=> $total,
'currentPage' => $page,
'countOfFirstPages'=> 5,
'countOfLastPages' => 5,
'countOfMiddlePages'=> 4,
'template' => $this->tpl
));
$paginator->compile();
$this->tpl->assignVar('TOTAL',$total);
}
function totalAction(array $params)
{
$items = (array)json_decode(@$_COOKIE['filter'],true);
$this->model->product->getByCriterias(array_values($items),$total,@$_COOKIE['filter_price_from'],@$_COOKIE['filter_price_to'],0,100);
die((string)$total);
}
}
Как заставить фильтр обрабатывать содержимое адресной строки и выводить контент в соответствии с параметрами из адресной строки? Ссылка формируется вида:
https://{DOMAIN}/filter/117/price/0/50000
Благодарен за любую помощь и наводку!