working with cakephp pagination with advance filter -
i working on ecommerce website need advance filter price, types.
controller
public function index($category) { $this->set('category',$category); $this->loadmodel("product"); $conditions['product.category'] = $category; if(!empty($this->request->data['filter']['materialtype'])) { foreach($this->request->data['filter']['materialtype'] $v) { $this->set('v',$v); $conditions['or'][]['product.materialtype like'] ="%$v%"; } } $this->set('agetproduct',$this->paginate($conditions));
}
initial query working fine
1 select `product`.`id`, `product`.`category`, `product`.`materialtype`, `product`.`occasion`, `product`.`collections`, `product`.`stone`, `product`.`sku`, `product`.`name`, `product`.`goldkaratage`, `product`.`weight`, `product`.`stoneweight`, `product`.`diamondcaratage`, `product`.`diamondcolor`, `product`.`diamondclarity`, `product`.`picture1`, `product`.`picture2`, `product`.`picture3`, `product`.`picture4`, `product`.`picture5`, `product`.`picture6`, `product`.`price`, `product`.`description`, `product`.`featured`, `product`.`action` `mookim`.`products` `product` `product`.`category` = 'pendant' limit 12 2 select count(*) `count` `mookim`.`products` `product` `product`.`category` = 'pendant'
when click on advance filter checkbox following query generate fine mysql query contains 14 record 12 products set on first page , rest on second page
1 select `product`.`id`, `product`.`category`, `product`.`materialtype`, `product`.`occasion`, `product`.`collections`, `product`.`stone`, `product`.`sku`, `product`.`name`, `product`.`goldkaratage`, `product`.`weight`, `product`.`stoneweight`, `product`.`diamondcaratage`, `product`.`diamondcolor`, `product`.`diamondclarity`, `product`.`picture1`, `product`.`picture2`, `product`.`picture3`, `product`.`picture4`, `product`.`picture5`, `product`.`picture6`, `product`.`price`, `product`.`description`, `product`.`featured`, `product`.`action` `mookim`.`products` `product` `product`.`category` = 'pendant' , ((`product`.`materialtype` '%yellow gold%') or (`product`.`materialtype` '%white gold%') or (`product`.`materialtype` '%silver%')) limit 12 2 select count(*) `count` `mookim`.`products` `product` `product`.`category` = 'pendant' , ((`product`.`materialtype` '%yellow gold%') or (`product`.`materialtype` '%white gold%') or (`product`.`materialtype` '%silver%'))
but see next product of filter query when click on next page query changed see following query contains record of sql table
1 select `product`.`id`, `product`.`category`, `product`.`materialtype`, `product`.`occasion`, `product`.`collections`, `product`.`stone`, `product`.`sku`, `product`.`name`, `product`.`goldkaratage`, `product`.`weight`, `product`.`stoneweight`, `product`.`diamondcaratage`, `product`.`diamondcolor`, `product`.`diamondclarity`, `product`.`picture1`, `product`.`picture2`, `product`.`picture3`, `product`.`picture4`, `product`.`picture5`, `product`.`picture6`, `product`.`price`, `product`.`description`, `product`.`featured`, `product`.`action` `mookim`.`products` `product` `product`.`category` = 'pendant' limit 12, 12 5 5 1 2 select count(*) `count` `mookim`.`products` `product` `product`.`category` = 'pendant'
public function index($category) { $this->set('category',$category); $this->loadmodel("product"); $conditions['product.category'] = $category;
controller
if(!empty($this->params['url']['data']['filter']['materialtype'])) { foreach ($this->params['url']['data']['filter']['materialtype'] $v){ $conditions['or'][]['product.materialtype like'] ="%$v%"; } } $this->paginate = array('limit' => 12,'conditions' => $conditions); $agetproduct = $this->paginate($this->modelclass); $this->set(compact('agetproduct')); }
view use form method get
<?php echo $this->form->create('filter', array('url'=>array('controller'=>'products', 'action'=>'index',$category),'id'=>'filter','autocomplete'=>'off','type'=>'get'));?>
Comments
Post a Comment