Subversion Repositories SmartDukaan

Rev

Rev 17471 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
14517 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Exceptionalnlcs Controller
5
 *
6
 * @property Exceptionalnlc $Exceptionalnlc
7
 * @property PaginatorComponent $Paginator
8
 */
9
class FeaturedDealsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
	public function beforeFilter() {
19
		parent::beforeFilter();
20
//		Configure::load('live');
21
		$this->apihost = Configure::read('pythonapihost');
22
	}
23
/**
24
 * admin_index method
25
 *
26
 * @return void
27
 */
28
	public function admin_index() {
29
		$page = $this->request->query('page');
30
		if(!isset($page)){
31
			$page = 1;
32
		}
33
		$limit = Configure::read('admindashboardlimit');
34
		$offset = ($page - 1)*$limit;
35
		$url = $this->apihost."featuredDeals/getFeaturedDeals/?limit=$limit&offset=$offset";
36
		$response = $this->make_request($url,null);
37
		$this->set('featureddeals', $response);
38
		$this->set('page',$page);
39
	}
40
 
41
/**
42
 * admin_view method
43
 *
44
 * @throws NotFoundException
45
 * @param string $id
46
 * @return void
47
 */
48
	public function admin_search() {
49
		$type = $this->request->query('type');
50
		$search = $this->request->query('search');				
51
		$url = $this->apihost."Catalog/searchProducts/?class=".Inflector::pluralize($this->name)."&$type=$search";
17342 naman 52
		$url = $this->apihost."Catalog/searchProducts/?class=".Inflector::pluralize($this->name)."&$type=$search";
53
		debug($url);
14517 anikendra 54
		$response = $this->make_request($url,null);
55
		$this->set('featureddeals', $response);
56
		$this->set('page',1);
57
		$this->render('admin_index');
58
	}
59
 
60
/**
61
 * admin_add method
62
 *
63
 * @return void
64
 */
65
	public function admin_add() {
14533 anikendra 66
		if ($this->request->is('post')) {			
17342 naman 67
			// date_default_timezone_set('UTC'); 
17471 manish.sha 68
			$otherrank = array();
69
			$othercat = array();
70
			$othercat['mobilerank'] = $this->request->data['FeaturedDeal']['Mobiles'];
71
			$othercat['tabletrank'] = $this->request->data['FeaturedDeal']['Tablets'];
72
			$othercat['accessrank'] = $this->request->data['FeaturedDeal']['Accessories'];
73
			$rankandcat['3'] = $othercat['mobilerank'];
74
			$rankandcat['5'] = $othercat['tabletrank'];
75
			$rankandcat['6'] = $othercat['accessrank'];
14517 anikendra 76
			$this->request->data['FeaturedDeal']['startDate'] = 1000*mktime($this->request->data['FeaturedDeal']['startDate']['hour'],$this->request->data['FeaturedDeal']['startDate']['min'],0,$this->request->data['FeaturedDeal']['startDate']['month'],$this->request->data['FeaturedDeal']['startDate']['day'],$this->request->data['FeaturedDeal']['startDate']['year']);
77
			$this->request->data['FeaturedDeal']['endDate'] = 1000*mktime($this->request->data['FeaturedDeal']['endDate']['hour'],$this->request->data['FeaturedDeal']['endDate']['min'],0,$this->request->data['FeaturedDeal']['endDate']['month'],$this->request->data['FeaturedDeal']['endDate']['day'],$this->request->data['FeaturedDeal']['endDate']['year']);
17342 naman 78
			$form_val = array();
79
			$form_val['skuBundleId'] = $this->request->data['FeaturedDeal']['skuBundleId'];
17471 manish.sha 80
			//$form_val['rank'] = $this->request->data['FeaturedDeal']['rankDetails'][0];
17342 naman 81
			$form_val['thresholdPrice'] = $this->request->data['FeaturedDeal']['thresholdPrice'];
82
			$form_val['startDate'] = $this->request->data['FeaturedDeal']['startDate'];
83
			$form_val['endDate'] = $this->request->data['FeaturedDeal']['endDate'];
17471 manish.sha 84
			$form_val['otherInfo'] = $rankandcat;
85
			//debug($form_val);
17342 naman 86
 
14517 anikendra 87
			$url = $this->apihost."featuredDeals/addFeaturedDeals";
17471 manish.sha 88
			$response = $this->make_request($url,json_encode($form_val,JSON_NUMERIC_CHECK));
89
			//debug($response);
17342 naman 90
			// unset($this->request->data['FeaturedDeal']['type']);
91
			// foreach ($this->request->data['FeaturedDeal']['rankDetails'] as $key => $value) {
92
			// 	if(empty($value)){
93
			// 		unset($this->request->data['FeaturedDeal']['rankDetails'][$key]);
94
			// 	}
95
			// }
96
			// $this->log(print_r($this->request->data,1),'featuredeals');
97
			// // $url = $this->apihost."featuredDeals/addFeaturedDeals";
98
			// // $data = $this->request->data['FeaturedDeal'];
99
			// // $url = $this->generateMultiUrl($url,$data);
100
			// debug($url);
101
			// // $jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
102
			// // $jsonVar = json_encode($form_val,JSON_NUMERIC_CHECK);
103
			// // $response = $this->make_request($url,$jsonVar);
104
 
14517 anikendra 105
			if (key($response)) {
106
				$this->Session->setFlash(current($response));
107
				return $this->redirect(array('action' => 'index'));
108
			} else {
109
				$this->Session->setFlash(current($response));
110
			}	
111
		}
112
	}
113
 
114
/**
115
 * admin_edit method
116
 *
117
 * @throws NotFoundException
118
 * @param string $id
119
 * @return void
120
 */
121
	public function admin_edit($id = null) {
122
		if (!$this->Exceptionalnlc->exists($id)) {
123
			throw new NotFoundException(__('Invalid exceptionalnlc'));
124
		}
125
		if ($this->request->is(array('post', 'put'))) {
126
			if ($this->Exceptionalnlc->save($this->request->data)) {
127
				$this->Session->setFlash(__('The exceptionalnlc has been saved.'));
128
				return $this->redirect(array('action' => 'index'));
129
			} else {
130
				$this->Session->setFlash(__('The exceptionalnlc could not be saved. Please, try again.'));
131
			}
132
		} else {
133
			$options = array('conditions' => array('Exceptionalnlc.' . $this->Exceptionalnlc->primaryKey => $id));
134
			$this->request->data = $this->Exceptionalnlc->find('first', $options);
135
		}
136
	}
137
 
138
/**
139
 * admin_delete method
140
 *
141
 * @throws NotFoundException
142
 * @param string $id
143
 * @return void
144
 */
145
 
146
	public function admin_delete($id = null) {		
147
		// $this->request->onlyAllow('post', 'delete');
148
		if ($this->remove($id,'FeaturedDeals')) {
17535 naman 149
			$this->Session->setFlash(__('The feature deal has been deleted.'));
14517 anikendra 150
		} else {
17535 naman 151
			$this->Session->setFlash(__('The feature deal could not be deleted. Please, try again.'));
14517 anikendra 152
		}
153
		return $this->redirect(array('action' => 'index'));
154
	}	
155
}