Subversion Repositories SmartDukaan

Rev

Rev 13532 | Rev 13550 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 13532 Rev 13541
Line 15... Line 15...
15
 */
15
 */
16
	public $components = array('Paginator');
16
	public $components = array('Paginator');
17
 
17
 
18
	public function beforeFilter() {
18
	public function beforeFilter() {
19
		parent::beforeFilter();
19
		parent::beforeFilter();
-
 
20
		$this->Auth->allow('bycategory');
20
		$callback = $this->request->query('callback');
21
		$callback = $this->request->query('callback');
21
	}
22
	}
22
/**
23
/**
23
 * index method
24
 * index method
24
 *
25
 *
25
 * @return void
26
 * @return void
26
 */
27
 */
27
	public function index() {
28
	public function index() {
-
 
29
		$user_id = $this->request->query('user_id');
28
		$this->response->type('json');
30
		$this->response->type('json');
29
		$this->layout = 'ajax';
31
		$this->layout = 'ajax';
30
		// $this->Product->recursive = -1;
32
		// $this->Product->recursive = -1;
31
		$this->StoreProduct->recursive = 1;
33
		$this->StoreProduct->recursive = 1;
-
 
34
		$this->Paginator->settings = array('limit'=>300);
32
		$result = array('products' => $this->Paginator->paginate());
35
		$result = array('products' => $this->Paginator->paginate());
33
		$callback = $this->request->query('callback');
36
		$callback = $this->request->query('callback');
34
		$this->set(array(
37
		$this->set(array(
35
		    'result' => $result,
38
		    'result' => $result,
36
		    'callback' => $callback,
39
		    'callback' => $callback,
37
		    '_serialize' => array('result')
40
		    '_serialize' => array('result')
-
 
41
		));
-
 
42
		$this->render('/Elements/jsonp');
-
 
43
	}
-
 
44
 
-
 
45
	public function bycategory() {
-
 
46
		$userId = $this->request->query('user_id');
-
 
47
		// $userId = 1;//delete me 
-
 
48
		$this->loadModel('UserCategory');
-
 
49
		$options = array('conditions' => array('user_id'=>$userId),'recursive'=>-1);
-
 
50
		$userCategories = $this->UserCategory->find('all',$options);		
-
 
51
		$this->response->type('json');
-
 
52
		$this->layout = 'ajax';
-
 
53
		$conditions = null;
-
 
54
		if(!empty($userCategories)){
-
 
55
			foreach ($userCategories as $key => $value) {
-
 
56
				$categoryIds[] = $value['UserCategory']['category_id'];
-
 
57
			}
-
 
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);
-
 
63
		$result = array('products' => $this->Paginator->paginate(),'categories'=>$categoryIds);
-
 
64
		$callback = $this->request->query('callback');
-
 
65
		$this->set(array(
-
 
66
		    'result' => $result,
-
 
67
		    'callback' => $callback,
-
 
68
		    '_serialize' => array('result')
38
		));
69
		));
39
		$this->render('/Elements/jsonp');
70
		$this->render('/Elements/jsonp');
40
	}
71
	}
41
 
72
 
42
/**
73
/**