Subversion Repositories SmartDukaan

Rev

Rev 18165 | Rev 20389 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Stores Controller
5
 *
6
 * @property Store $Store
7
 * @property PaginatorComponent $Paginator
8
 */
9
class StoresController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
14455 anikendra 18
	public function beforeFilter() {
19
		parent::beforeFilter();
20
		$this->Auth->allow('redirectto');
21
	}
22
 
13532 anikendra 23
/**
24
 * index method
25
 *
26
 * @return void
27
 */
28
	public function index() {
29
		$this->Store->recursive = 0;
14455 anikendra 30
		$this->set('stores', $this->Paginator->paginate());		
13532 anikendra 31
	}
32
 
33
/**
34
 * view method
35
 *
36
 * @throws NotFoundException
37
 * @param string $id
38
 * @return void
39
 */
40
	public function view($id = null) {
41
		if (!$this->Store->exists($id)) {
42
			throw new NotFoundException(__('Invalid store'));
43
		}
44
		$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
45
		$this->set('store', $this->Store->find('first', $options));
46
	}
47
 
14455 anikendra 48
	public function redirectto(){
49
		$this->layout = 'innerpages';
50
		$userId = $this->request->query('user_id');
20100 naman 51
// 		if(isset($userId) && !empty($userId)){
52
// 			$this->loadModel('User');
53
// 			$dbuser = $this->User->findById($userId);
54
// 			$this->Auth->login($dbuser['User']);
55
// 		}
14455 anikendra 56
		$storeId = $this->request->query('store_id');
57
		$cachekey = 'store-'.$storeId;
16679 anikendra 58
		$store = Cache::read($cachekey,'month');
14455 anikendra 59
		if(empty($store)) {
14786 anikendra 60
			$store = $this->Store->find('first',array('recursive'=>-1,'conditions'=>array('id'=>$storeId)));
14455 anikendra 61
			Cache::write($cachekey,$store,'month');			
62
		}
63
		$prefix = "SHA".$storeId;
64
		$tag = $prefix.time();
65
		if($storeId == 2){				
14654 anikendra 66
			$url = "http://dl.flipkart.com/dl/";
14455 anikendra 67
		} elseif($storeId == 3) {
18165 amit.gupta 68
			//$url = "http://m.snapdeal.com/products/mobiles?utm_source=aff_prog&utm_campaign=afts&offer_id=17";			
69
			$url = "http://m.snapdeal.com/products/mobiles";			
14455 anikendra 70
		} elseif($storeId == 1){
14786 anikendra 71
			$url = "http://www.amazon.in/gp/goldbox";
15248 anikendra 72
		} elseif($storeId == 4) {
17656 amit.gupta 73
			$url = "http://m.saholic.com";			
15925 anikendra 74
		} elseif($storeId==5){
75
			$url = "http://clk.omgt5.com/?PID=10314&r=$url";
16397 anikendra 76
		} elseif($storeId==6){
77
			$url = "http://clk.omgt5.com/?PID=11365&r=$url";
17055 anikendra 78
		} elseif($storeId==7){
79
			$url = "http://clk.omgt5.com/?PID=9419&r=$url";
14455 anikendra 80
		}
81
		if( strpos($url, '?') === false ) {
82
			$firstChar = '?';
83
		} else {
84
			$firstChar = '&';
85
		}
18165 amit.gupta 86
		if($storeId!=3){
87
			$url .= $firstChar.$store['Store']['affid_param'].'='.$store['Store']['affiliate_id'];
88
			if(!empty($store['Store']['sub_tag_param'])){
89
				$url .= '&'.$store['Store']['sub_tag_param'].'='.$tag;
90
			}
14455 anikendra 91
		}
92
		$extras = array('store'=>$store['Store']['name']);
93
		$data = array('user_id'=>$userId,'store_product_id'=>0,'price'=>0,'tag'=>$tag,'url'=>$url,'extras'=>json_encode($extras));
94
		$this->loadModel('Click');
95
		$this->Click->create();
96
		if ($this->Click->save($data)) {
97
			$result = array('success'=>true,'message'=>__('The click has been saved.'),'type'=>'redirect','url'=>$url);
98
		} else {
99
			$result = array('success'=>false,'message'=>__('The click could not be saved. Please, try again.'));
100
		}
101
		$this->set(compact('store','url'));
102
	}
103
 
13532 anikendra 104
/**
105
 * add method
106
 *
107
 * @return void
108
 */
109
	public function add() {
110
		if ($this->request->is('post')) {
111
			$this->Store->create();
112
			if ($this->Store->save($this->request->data)) {
113
				$this->Session->setFlash(__('The store has been saved.'));
114
				return $this->redirect(array('action' => 'index'));
115
			} else {
116
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
117
			}
118
		}
119
		$affiliates = $this->Store->Affiliate->find('list');
120
		$this->set(compact('affiliates'));
121
	}
122
 
123
/**
124
 * edit method
125
 *
126
 * @throws NotFoundException
127
 * @param string $id
128
 * @return void
129
 */
130
	public function edit($id = null) {
131
		if (!$this->Store->exists($id)) {
132
			throw new NotFoundException(__('Invalid store'));
133
		}
134
		if ($this->request->is(array('post', 'put'))) {
135
			if ($this->Store->save($this->request->data)) {
136
				$this->Session->setFlash(__('The store has been saved.'));
137
				return $this->redirect(array('action' => 'index'));
138
			} else {
139
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
140
			}
141
		} else {
142
			$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
143
			$this->request->data = $this->Store->find('first', $options);
144
		}
145
		$affiliates = $this->Store->Affiliate->find('list');
146
		$this->set(compact('affiliates'));
147
	}
148
 
149
/**
150
 * delete method
151
 *
152
 * @throws NotFoundException
153
 * @param string $id
154
 * @return void
155
 */
156
	public function delete($id = null) {
157
		$this->Store->id = $id;
158
		if (!$this->Store->exists()) {
159
			throw new NotFoundException(__('Invalid store'));
160
		}
161
		$this->request->onlyAllow('post', 'delete');
162
		if ($this->Store->delete()) {
163
			$this->Session->setFlash(__('The store has been deleted.'));
164
		} else {
165
			$this->Session->setFlash(__('The store could not be deleted. Please, try again.'));
166
		}
167
		return $this->redirect(array('action' => 'index'));
168
	}
169
 
170
/**
171
 * admin_index method
172
 *
173
 * @return void
174
 */
175
	public function admin_index() {
176
		$this->Store->recursive = 0;
177
		$this->set('stores', $this->Paginator->paginate());
178
	}
179
 
180
/**
181
 * admin_view method
182
 *
183
 * @throws NotFoundException
184
 * @param string $id
185
 * @return void
186
 */
187
	public function admin_view($id = null) {
188
		if (!$this->Store->exists($id)) {
189
			throw new NotFoundException(__('Invalid store'));
190
		}
191
		$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
192
		$this->set('store', $this->Store->find('first', $options));
193
	}
194
 
195
/**
196
 * admin_add method
197
 *
198
 * @return void
199
 */
200
	public function admin_add() {
201
		if ($this->request->is('post')) {
202
			$this->Store->create();
203
			if ($this->Store->save($this->request->data)) {
204
				$this->Session->setFlash(__('The store has been saved.'));
205
				return $this->redirect(array('action' => 'index'));
206
			} else {
207
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
208
			}
209
		}
210
		$statuses = array('active'=>'Active','paused'=>'Paused','deleted'=>'Deleted');
13558 anikendra 211
		$cashback_statuses = array('active'=>'Active','inactive'=>'In-active');
212
		$this->set(compact('statuses','cashback_statuses'));
13532 anikendra 213
	}
214
 
215
/**
216
 * admin_edit method
217
 *
218
 * @throws NotFoundException
219
 * @param string $id
220
 * @return void
221
 */
222
	public function admin_edit($id = null) {
223
		if (!$this->Store->exists($id)) {
224
			throw new NotFoundException(__('Invalid store'));
225
		}
226
		if ($this->request->is(array('post', 'put'))) {
227
			if ($this->Store->save($this->request->data)) {
228
				$this->Session->setFlash(__('The store has been saved.'));
229
				return $this->redirect(array('action' => 'index'));
230
			} else {
231
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
232
			}
233
		} else {
234
			$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
235
			$this->request->data = $this->Store->find('first', $options);
236
		}
237
		$statuses = array('active'=>'Active','paused'=>'Paused','deleted'=>'Deleted');
13558 anikendra 238
		$cashback_statuses = array('active'=>'Active','inactive'=>'In-active');
239
		$this->set(compact('statuses','cashback_statuses'));
13532 anikendra 240
	}
241
 
242
/**
243
 * admin_delete method
244
 *
245
 * @throws NotFoundException
246
 * @param string $id
247
 * @return void
248
 */
249
	public function admin_delete($id = null) {
250
		$this->Store->id = $id;
251
		if (!$this->Store->exists()) {
252
			throw new NotFoundException(__('Invalid store'));
253
		}
254
		$this->request->onlyAllow('post', 'delete');
255
		if ($this->Store->delete()) {
256
			$this->Session->setFlash(__('The store has been deleted.'));
257
		} else {
258
			$this->Session->setFlash(__('The store could not be deleted. Please, try again.'));
259
		}
260
		return $this->redirect(array('action' => 'index'));
261
	}}