Subversion Repositories SmartDukaan

Rev

Rev 15085 | Rev 15380 | 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');
51
		if(isset($userId) && !empty($userId)){
52
			$this->loadModel('User');
53
			$dbuser = $this->User->findById($userId);
54
			$this->Auth->login($dbuser['User']);
55
		}
56
		$storeId = $this->request->query('store_id');
57
		$cachekey = 'store-'.$storeId;
15085 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) {
14838 anikendra 68
			$url = "http://m.snapdeal.com/products/mobiles?utm_source=aff_prog&utm_campaign=afts&offer_id=17";			
14455 anikendra 69
		} elseif($storeId == 1){
14786 anikendra 70
			$url = "http://www.amazon.in/gp/goldbox";
15248 anikendra 71
		} elseif($storeId == 4) {
72
			$this->checkToken();			
14455 anikendra 73
		}
74
		if( strpos($url, '?') === false ) {
75
			$firstChar = '?';
76
		} else {
77
			$firstChar = '&';
78
		}
79
		$url .= $firstChar.$store['Store']['affid_param'].'='.$store['Store']['affiliate_id'];
80
		if(!empty($store['Store']['sub_tag_param'])){
81
			$url .= '&'.$store['Store']['sub_tag_param'].'='.$tag;
82
		}
83
		$extras = array('store'=>$store['Store']['name']);
84
		$data = array('user_id'=>$userId,'store_product_id'=>0,'price'=>0,'tag'=>$tag,'url'=>$url,'extras'=>json_encode($extras));
85
		$this->loadModel('Click');
86
		$this->Click->create();
87
		if ($this->Click->save($data)) {
88
			$result = array('success'=>true,'message'=>__('The click has been saved.'),'type'=>'redirect','url'=>$url);
89
		} else {
90
			$result = array('success'=>false,'message'=>__('The click could not be saved. Please, try again.'));
91
		}
92
		$this->set(compact('store','url'));
93
	}
94
 
13532 anikendra 95
/**
96
 * add method
97
 *
98
 * @return void
99
 */
100
	public function add() {
101
		if ($this->request->is('post')) {
102
			$this->Store->create();
103
			if ($this->Store->save($this->request->data)) {
104
				$this->Session->setFlash(__('The store has been saved.'));
105
				return $this->redirect(array('action' => 'index'));
106
			} else {
107
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
108
			}
109
		}
110
		$affiliates = $this->Store->Affiliate->find('list');
111
		$this->set(compact('affiliates'));
112
	}
113
 
114
/**
115
 * edit method
116
 *
117
 * @throws NotFoundException
118
 * @param string $id
119
 * @return void
120
 */
121
	public function edit($id = null) {
122
		if (!$this->Store->exists($id)) {
123
			throw new NotFoundException(__('Invalid store'));
124
		}
125
		if ($this->request->is(array('post', 'put'))) {
126
			if ($this->Store->save($this->request->data)) {
127
				$this->Session->setFlash(__('The store has been saved.'));
128
				return $this->redirect(array('action' => 'index'));
129
			} else {
130
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
131
			}
132
		} else {
133
			$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
134
			$this->request->data = $this->Store->find('first', $options);
135
		}
136
		$affiliates = $this->Store->Affiliate->find('list');
137
		$this->set(compact('affiliates'));
138
	}
139
 
140
/**
141
 * delete method
142
 *
143
 * @throws NotFoundException
144
 * @param string $id
145
 * @return void
146
 */
147
	public function delete($id = null) {
148
		$this->Store->id = $id;
149
		if (!$this->Store->exists()) {
150
			throw new NotFoundException(__('Invalid store'));
151
		}
152
		$this->request->onlyAllow('post', 'delete');
153
		if ($this->Store->delete()) {
154
			$this->Session->setFlash(__('The store has been deleted.'));
155
		} else {
156
			$this->Session->setFlash(__('The store could not be deleted. Please, try again.'));
157
		}
158
		return $this->redirect(array('action' => 'index'));
159
	}
160
 
161
/**
162
 * admin_index method
163
 *
164
 * @return void
165
 */
166
	public function admin_index() {
167
		$this->Store->recursive = 0;
168
		$this->set('stores', $this->Paginator->paginate());
169
	}
170
 
171
/**
172
 * admin_view method
173
 *
174
 * @throws NotFoundException
175
 * @param string $id
176
 * @return void
177
 */
178
	public function admin_view($id = null) {
179
		if (!$this->Store->exists($id)) {
180
			throw new NotFoundException(__('Invalid store'));
181
		}
182
		$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
183
		$this->set('store', $this->Store->find('first', $options));
184
	}
185
 
186
/**
187
 * admin_add method
188
 *
189
 * @return void
190
 */
191
	public function admin_add() {
192
		if ($this->request->is('post')) {
193
			$this->Store->create();
194
			if ($this->Store->save($this->request->data)) {
195
				$this->Session->setFlash(__('The store has been saved.'));
196
				return $this->redirect(array('action' => 'index'));
197
			} else {
198
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
199
			}
200
		}
201
		$statuses = array('active'=>'Active','paused'=>'Paused','deleted'=>'Deleted');
13558 anikendra 202
		$cashback_statuses = array('active'=>'Active','inactive'=>'In-active');
203
		$this->set(compact('statuses','cashback_statuses'));
13532 anikendra 204
	}
205
 
206
/**
207
 * admin_edit method
208
 *
209
 * @throws NotFoundException
210
 * @param string $id
211
 * @return void
212
 */
213
	public function admin_edit($id = null) {
214
		if (!$this->Store->exists($id)) {
215
			throw new NotFoundException(__('Invalid store'));
216
		}
217
		if ($this->request->is(array('post', 'put'))) {
218
			if ($this->Store->save($this->request->data)) {
219
				$this->Session->setFlash(__('The store has been saved.'));
220
				return $this->redirect(array('action' => 'index'));
221
			} else {
222
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
223
			}
224
		} else {
225
			$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
226
			$this->request->data = $this->Store->find('first', $options);
227
		}
228
		$statuses = array('active'=>'Active','paused'=>'Paused','deleted'=>'Deleted');
13558 anikendra 229
		$cashback_statuses = array('active'=>'Active','inactive'=>'In-active');
230
		$this->set(compact('statuses','cashback_statuses'));
13532 anikendra 231
	}
232
 
233
/**
234
 * admin_delete method
235
 *
236
 * @throws NotFoundException
237
 * @param string $id
238
 * @return void
239
 */
240
	public function admin_delete($id = null) {
241
		$this->Store->id = $id;
242
		if (!$this->Store->exists()) {
243
			throw new NotFoundException(__('Invalid store'));
244
		}
245
		$this->request->onlyAllow('post', 'delete');
246
		if ($this->Store->delete()) {
247
			$this->Session->setFlash(__('The store has been deleted.'));
248
		} else {
249
			$this->Session->setFlash(__('The store could not be deleted. Please, try again.'));
250
		}
251
		return $this->redirect(array('action' => 'index'));
252
	}}