| Line 23... |
Line 23... |
| 23 |
/**
|
23 |
/**
|
| 24 |
* index method
|
24 |
* index method
|
| 25 |
*
|
25 |
*
|
| 26 |
* @return void
|
26 |
* @return void
|
| 27 |
*/
|
27 |
*/
|
| 28 |
public function index() {
|
28 |
public function index($user_id=null) {
|
| 29 |
$user_id = $this->request->query('user_id');
|
- |
|
| 30 |
$this->response->type('json');
|
29 |
$this->response->type('json');
|
| 31 |
$this->layout = 'ajax';
|
30 |
$this->layout = 'ajax';
|
| - |
|
31 |
$limit = 20;
|
| 32 |
// $this->Product->recursive = -1;
|
32 |
$this->StoreProduct->recursive = -1;
|
| 33 |
$this->StoreProduct->recursive = 1;
|
33 |
$count = $this->StoreProduct->find('count');
|
| - |
|
34 |
$this->StoreProduct->Behaviors->attach('Containable');
|
| 34 |
$this->Paginator->settings = array('limit'=>300);
|
35 |
$this->Paginator->settings = array('contain'=>array('Product'),'limit'=>$limit,'fields'=>array('Product.category_id','StoreProduct.id','StoreProduct.title','StoreProduct.thumbnail','StoreProduct.price','StoreProduct.cashback','StoreProduct.available_price'));
|
| 35 |
$result = array('products' => $this->Paginator->paginate());
|
36 |
$result = array('products' => $this->Paginator->paginate(),'maxresults'=>ceil($count/$limit));
|
| 36 |
$callback = $this->request->query('callback');
|
37 |
$callback = $this->request->query('callback');
|
| 37 |
$this->set(array(
|
38 |
$this->set(array(
|
| 38 |
'result' => $result,
|
39 |
'result' => $result,
|
| 39 |
'callback' => $callback,
|
40 |
'callback' => $callback,
|
| 40 |
'_serialize' => array('result')
|
41 |
'_serialize' => array('result')
|
| 41 |
));
|
42 |
));
|
| 42 |
$this->render('/Elements/jsonp');
|
43 |
$this->render('/Elements/jsonp');
|
| 43 |
}
|
44 |
}
|
| 44 |
|
45 |
|
| 45 |
public function bycategory() {
|
46 |
public function bycategory($userId=null) {
|
| 46 |
$userId = $this->request->query('user_id');
|
- |
|
| 47 |
// $userId = 1;//delete me
|
- |
|
| 48 |
$this->loadModel('UserCategory');
|
47 |
$this->loadModel('UserCategory');
|
| 49 |
$options = array('conditions' => array('user_id'=>$userId),'recursive'=>-1);
|
48 |
$options = array('conditions' => array('user_id'=>$userId),'recursive'=>-1);
|
| 50 |
$userCategories = $this->UserCategory->find('all',$options);
|
49 |
$userCategories = $this->UserCategory->find('all',$options);
|
| 51 |
$this->response->type('json');
|
50 |
$this->response->type('json');
|
| 52 |
$this->layout = 'ajax';
|
51 |
$this->layout = 'ajax';
|
| - |
|
52 |
$limit = 20;
|
| 53 |
$conditions = null;
|
53 |
$conditions = null;
|
| - |
|
54 |
$this->StoreProduct->recursive = -1;
|
| - |
|
55 |
$this->StoreProduct->Behaviors->attach('Containable');
|
| - |
|
56 |
$products = array();
|
| 54 |
if(!empty($userCategories)){
|
57 |
if(!empty($userCategories)){
|
| 55 |
foreach ($userCategories as $key => $value) {
|
58 |
foreach ($userCategories as $key => $value) {
|
| 56 |
$categoryIds[] = $value['UserCategory']['category_id'];
|
59 |
$categoryIds[] = $value['UserCategory']['category_id'];
|
| - |
|
60 |
$conditions = array('Product.category_id'=>$value['UserCategory']['category_id']);
|
| - |
|
61 |
$this->Paginator->settings = array('contain'=>array('Product'),'limit'=>$limit,'fields'=>array('Product.category_id','StoreProduct.id','StoreProduct.title','StoreProduct.thumbnail','StoreProduct.price','StoreProduct.cashback','StoreProduct.available_price'),'conditions'=>$conditions);
|
| - |
|
62 |
// $products[$value['UserCategory']['category_id']]['products'] = $this->Paginator->paginate();
|
| - |
|
63 |
$rows = $this->Paginator->paginate();
|
| - |
|
64 |
foreach($rows AS $key => $product){
|
| - |
|
65 |
$products[$value['UserCategory']['category_id']][$key][] = $product;
|
| - |
|
66 |
}
|
| 57 |
}
|
67 |
}
|
| 58 |
$conditions = array('Product.category_id'=>$categoryIds);
|
- |
|
| 59 |
}
|
- |
|
| 60 |
$this->StoreProduct->recursive = -1;
|
- |
|
| 61 |
$this->StoreProduct->Behaviors->attach('Containable');
|
- |
|
| 62 |
$this->Paginator->settings = array('contain'=>array('Product'),'limit'=>50,'fields'=>array('Product.category_id','StoreProduct.id','StoreProduct.title','StoreProduct.thumbnail','StoreProduct.price','StoreProduct.cashback','StoreProduct.available_price'),'conditions'=>$conditions);
|
68 |
}
|
| 63 |
$result = array('products' => $this->Paginator->paginate(),'categories'=>$categoryIds);
|
69 |
$result = array('products' => $products);//,'categories'=>$categoryIds);
|
| 64 |
$callback = $this->request->query('callback');
|
70 |
$callback = $this->request->query('callback');
|
| 65 |
$this->set(array(
|
71 |
$this->set(array(
|
| 66 |
'result' => $result,
|
72 |
'result' => $result,
|
| 67 |
'callback' => $callback,
|
73 |
'callback' => $callback,
|
| 68 |
'_serialize' => array('result')
|
74 |
'_serialize' => array('result')
|