Subversion Repositories SmartDukaan

Rev

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