Subversion Repositories SmartDukaan

Rev

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