| 13532 |
anikendra |
1 |
<?php
|
|
|
2 |
App::uses('AppController', 'Controller');
|
|
|
3 |
/**
|
|
|
4 |
* Clicks Controller
|
|
|
5 |
*
|
|
|
6 |
* @property Click $Click
|
|
|
7 |
* @property PaginatorComponent $Paginator
|
|
|
8 |
*/
|
|
|
9 |
class ClicksController extends AppController {
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* Components
|
|
|
13 |
*
|
|
|
14 |
* @var array
|
|
|
15 |
*/
|
|
|
16 |
public $components = array('Paginator');
|
| 13808 |
anikendra |
17 |
public $apihost;
|
| 13532 |
anikendra |
18 |
|
| 13558 |
anikendra |
19 |
public function beforeFilter() {
|
|
|
20 |
parent::beforeFilter();
|
| 14302 |
anikendra |
21 |
$this->Auth->allow('redirecttosaholic');
|
| 13808 |
anikendra |
22 |
$this->apihost = Configure::read('pythonapihost');
|
| 13558 |
anikendra |
23 |
}
|
| 13532 |
anikendra |
24 |
/**
|
|
|
25 |
* index method
|
|
|
26 |
*
|
|
|
27 |
* @return void
|
|
|
28 |
*/
|
|
|
29 |
public function index() {
|
|
|
30 |
$this->Click->recursive = 0;
|
|
|
31 |
$this->set('clicks', $this->Paginator->paginate());
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* view method
|
|
|
36 |
*
|
|
|
37 |
* @throws NotFoundException
|
|
|
38 |
* @param string $id
|
|
|
39 |
* @return void
|
|
|
40 |
*/
|
|
|
41 |
public function view($id = null) {
|
|
|
42 |
if (!$this->Click->exists($id)) {
|
|
|
43 |
throw new NotFoundException(__('Invalid click'));
|
|
|
44 |
}
|
|
|
45 |
$options = array('conditions' => array('Click.' . $this->Click->primaryKey => $id));
|
|
|
46 |
$this->set('click', $this->Click->find('first', $options));
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* add method
|
|
|
51 |
*
|
|
|
52 |
* @return void
|
|
|
53 |
*/
|
| 14345 |
anikendra |
54 |
public function add($userId=null,$storeProductId=null,$storeId=null) {
|
| 14387 |
anikendra |
55 |
session_write_close();
|
| 13558 |
anikendra |
56 |
if(!empty($userId) && !empty($storeProductId)){
|
| 14345 |
anikendra |
57 |
$url = $this->request->query('url');
|
|
|
58 |
$available_price = $this->request->query('price');
|
| 13558 |
anikendra |
59 |
//Get StoreProduct Info
|
| 13808 |
anikendra |
60 |
$this->loadModel('Store');
|
|
|
61 |
// $options = array('conditions'=>array('id'=>$storeProductId),'fields'=>array('source_id','available_price','url'),'recursive'=>-1);
|
|
|
62 |
// $storeProduct = $this->StoreProduct->find('first',$options);
|
|
|
63 |
$cachekey = 'storeproduct-'.$storeProductId;
|
| 14345 |
anikendra |
64 |
|
|
|
65 |
if($url=='undefined' || $available_price=='undefined' || $storeId=='undefined') {
|
|
|
66 |
$product = Cache::read($cachekey,'five');
|
|
|
67 |
if(empty($product)) {
|
|
|
68 |
$url = $this->apihost.'masterData/getSkuById/'.$storeProductId;
|
|
|
69 |
$product = $this->make_request($url,null);
|
|
|
70 |
Cache::write($cachekey,$product,'five');
|
|
|
71 |
}
|
|
|
72 |
$storeProduct = json_decode($product[0],1);
|
|
|
73 |
$url = $storeProduct['marketPlaceUrl'];
|
|
|
74 |
$storeId = $storeProduct['source_id'];
|
|
|
75 |
$available_price = $storeProduct['available_price'];
|
| 13808 |
anikendra |
76 |
}
|
| 14345 |
anikendra |
77 |
$cachekey = 'store-'.$storeId;
|
| 14346 |
anikendra |
78 |
$store = Cache::read($cachekey,'month');
|
|
|
79 |
if(empty($store)) {
|
| 13903 |
anikendra |
80 |
$store = $this->Store->find('first',array('recursive'=>-1,'conditions'=>array('id'=>$storeProduct['source_id'])));
|
|
|
81 |
Cache::write($cachekey,$store,'month');
|
|
|
82 |
}
|
| 14345 |
anikendra |
83 |
$prefix = "SHA".$storeId;
|
| 13599 |
anikendra |
84 |
$tag = $prefix.time();
|
| 14345 |
anikendra |
85 |
if($storeId == 2){
|
| 14654 |
anikendra |
86 |
// $url = str_replace('www','m',$url);
|
|
|
87 |
$url = str_replace('www.','',$url);
|
|
|
88 |
$url = str_replace('http://','',$url);
|
|
|
89 |
$url = str_replace('flipkart.com','http://dl.flipkart.com/dl',$url);
|
| 14345 |
anikendra |
90 |
} elseif($storeId == 3) {
|
|
|
91 |
$url_parts = parse_url($url);
|
| 13903 |
anikendra |
92 |
$url_parts['path'] = str_replace('viewAllSellers/','',$url_parts['path']);//quickfix for snapdeal
|
| 13901 |
anikendra |
93 |
if(isset($url_parts['query'])) {
|
| 13903 |
anikendra |
94 |
$url = "http://m.snapdeal.com".$url_parts['path'].'?'.$url_parts['query']."&utm_source=aff_prog&utm_campaign=afts&offer_id=17";
|
| 13901 |
anikendra |
95 |
}else{
|
| 13903 |
anikendra |
96 |
$url = "http://m.snapdeal.com".$url_parts['path'].'?utm_source=aff_prog&utm_campaign=afts&offer_id=17';
|
| 13901 |
anikendra |
97 |
}
|
| 14345 |
anikendra |
98 |
} elseif($storeId == 4){
|
| 14574 |
anikendra |
99 |
$urlparts = parse_url($url);
|
|
|
100 |
$url = $urlparts['path'];
|
|
|
101 |
if(!empty($urlparts['query'])){
|
|
|
102 |
$url .= '?'.$urlparts['query'];
|
|
|
103 |
}
|
|
|
104 |
$url = $this->getAutoLoginUrl($userId,$url);
|
| 14346 |
anikendra |
105 |
}/*else{
|
| 13808 |
anikendra |
106 |
$url = $storeProduct['marketPlaceUrl'];
|
| 14345 |
anikendra |
107 |
}*/
|
| 13558 |
anikendra |
108 |
if( strpos($url, '?') === false ) {
|
|
|
109 |
$firstChar = '?';
|
|
|
110 |
} else {
|
| 13561 |
anikendra |
111 |
$firstChar = '&';
|
| 13558 |
anikendra |
112 |
}
|
|
|
113 |
$url .= $firstChar.$store['Store']['affid_param'].'='.$store['Store']['affiliate_id'];
|
|
|
114 |
if(!empty($store['Store']['sub_tag_param'])){
|
|
|
115 |
$url .= '&'.$store['Store']['sub_tag_param'].'='.$tag;
|
|
|
116 |
}
|
|
|
117 |
$extras = array('store'=>$store['Store']['name']);
|
| 14345 |
anikendra |
118 |
$data = array('user_id'=>$userId,'store_product_id'=>$storeProductId,'price'=>$available_price,'tag'=>$tag,'url'=>$url,'extras'=>json_encode($extras));
|
| 13532 |
anikendra |
119 |
$this->Click->create();
|
| 13558 |
anikendra |
120 |
if ($this->Click->save($data)) {
|
|
|
121 |
$result = array('success'=>true,'message'=>__('The click has been saved.'),'type'=>'redirect','url'=>$url);
|
| 13532 |
anikendra |
122 |
} else {
|
| 13558 |
anikendra |
123 |
$result = array('success'=>false,'message'=>__('The click could not be saved. Please, try again.'));
|
| 13532 |
anikendra |
124 |
}
|
| 13558 |
anikendra |
125 |
$this->response->type('json');
|
|
|
126 |
$this->layout = 'ajax';
|
|
|
127 |
$callback = $this->request->query('callback');
|
|
|
128 |
$this->set(array(
|
|
|
129 |
'result' => $result,
|
|
|
130 |
'callback' => $callback,
|
|
|
131 |
'_serialize' => array('result')
|
|
|
132 |
));
|
| 13903 |
anikendra |
133 |
$url = $this->apihost.'Catalog/fetchLivePrices/?id='.$storeProductId;
|
|
|
134 |
$this->make_request($url,null);
|
| 13558 |
anikendra |
135 |
$this->render('/Elements/jsonp');
|
| 13532 |
anikendra |
136 |
}
|
|
|
137 |
}
|
|
|
138 |
|
| 14302 |
anikendra |
139 |
public function redirecttosaholic() {
|
|
|
140 |
$userId = $this->request->query('user_id');
|
|
|
141 |
if(isset($userId) && !empty($userId)){
|
|
|
142 |
$next = "&next=/private-deals/1";
|
|
|
143 |
$redirectUrl = $this->getAutoLoginUrl($userId,$next);
|
|
|
144 |
header('location:'.$redirectUrl);
|
|
|
145 |
exit();
|
|
|
146 |
}
|
|
|
147 |
}
|
|
|
148 |
|
| 13532 |
anikendra |
149 |
/**
|
|
|
150 |
* edit method
|
|
|
151 |
*
|
|
|
152 |
* @throws NotFoundException
|
|
|
153 |
* @param string $id
|
|
|
154 |
* @return void
|
|
|
155 |
*/
|
|
|
156 |
public function edit($id = null) {
|
|
|
157 |
if (!$this->Click->exists($id)) {
|
|
|
158 |
throw new NotFoundException(__('Invalid click'));
|
|
|
159 |
}
|
|
|
160 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
161 |
if ($this->Click->save($this->request->data)) {
|
|
|
162 |
$this->Session->setFlash(__('The click has been saved.'));
|
|
|
163 |
return $this->redirect(array('action' => 'index'));
|
|
|
164 |
} else {
|
|
|
165 |
$this->Session->setFlash(__('The click could not be saved. Please, try again.'));
|
|
|
166 |
}
|
|
|
167 |
} else {
|
|
|
168 |
$options = array('conditions' => array('Click.' . $this->Click->primaryKey => $id));
|
|
|
169 |
$this->request->data = $this->Click->find('first', $options);
|
|
|
170 |
}
|
|
|
171 |
$users = $this->Click->User->find('list');
|
|
|
172 |
$storeProducts = $this->Click->StoreProduct->find('list');
|
|
|
173 |
$this->set(compact('users', 'storeProducts'));
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
/**
|
|
|
177 |
* delete method
|
|
|
178 |
*
|
|
|
179 |
* @throws NotFoundException
|
|
|
180 |
* @param string $id
|
|
|
181 |
* @return void
|
|
|
182 |
*/
|
|
|
183 |
public function delete($id = null) {
|
|
|
184 |
$this->Click->id = $id;
|
|
|
185 |
if (!$this->Click->exists()) {
|
|
|
186 |
throw new NotFoundException(__('Invalid click'));
|
|
|
187 |
}
|
|
|
188 |
$this->request->onlyAllow('post', 'delete');
|
|
|
189 |
if ($this->Click->delete()) {
|
|
|
190 |
$this->Session->setFlash(__('The click has been deleted.'));
|
|
|
191 |
} else {
|
|
|
192 |
$this->Session->setFlash(__('The click could not be deleted. Please, try again.'));
|
|
|
193 |
}
|
|
|
194 |
return $this->redirect(array('action' => 'index'));
|
|
|
195 |
}
|
|
|
196 |
|
| 14734 |
anikendra |
197 |
public function admin_by($userId = null) {
|
|
|
198 |
$this->Click->recursive = 0;
|
|
|
199 |
$q = $this->request->query('q');
|
|
|
200 |
if(isset($q) && !empty($q)){
|
|
|
201 |
$options = array('conditions' => array('Click.user_id' => $userId, 'Click.url LIKE'=>'%'.$q.'%'),'order'=>array('id'=>'desc'),'limit' => 100);
|
|
|
202 |
$this->set(compact('q'));
|
|
|
203 |
} else {
|
|
|
204 |
$options = array('conditions' => array('Click.user_id' => $userId),'order'=>array('id'=>'desc'),'limit' => 100);
|
|
|
205 |
}
|
|
|
206 |
$this->Paginator->settings = $options;
|
|
|
207 |
$clicks = $this->Paginator->paginate();
|
|
|
208 |
$this->set(compact('clicks'));
|
|
|
209 |
}
|
|
|
210 |
|
| 13532 |
anikendra |
211 |
/**
|
|
|
212 |
* admin_index method
|
|
|
213 |
*
|
|
|
214 |
* @return void
|
|
|
215 |
*/
|
|
|
216 |
public function admin_index() {
|
|
|
217 |
$this->Click->recursive = 0;
|
| 14734 |
anikendra |
218 |
$q = $this->request->query('q');
|
|
|
219 |
if(isset($q) && !empty($q)){
|
|
|
220 |
$this->Paginator->settings = array('conditions' => array('Click.url LIKE'=>'%'.$q.'%'),'order' => array('id'=>'desc'));
|
|
|
221 |
$this->set(compact('q'));
|
|
|
222 |
} else {
|
|
|
223 |
$this->Paginator->settings = array('order' => array('id'=>'desc'));
|
|
|
224 |
}
|
| 13532 |
anikendra |
225 |
$this->set('clicks', $this->Paginator->paginate());
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
/**
|
|
|
229 |
* admin_view method
|
|
|
230 |
*
|
|
|
231 |
* @throws NotFoundException
|
|
|
232 |
* @param string $id
|
|
|
233 |
* @return void
|
|
|
234 |
*/
|
|
|
235 |
public function admin_view($id = null) {
|
|
|
236 |
if (!$this->Click->exists($id)) {
|
|
|
237 |
throw new NotFoundException(__('Invalid click'));
|
|
|
238 |
}
|
|
|
239 |
$options = array('conditions' => array('Click.' . $this->Click->primaryKey => $id));
|
|
|
240 |
$this->set('click', $this->Click->find('first', $options));
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
/**
|
|
|
244 |
* admin_add method
|
|
|
245 |
*
|
|
|
246 |
* @return void
|
|
|
247 |
*/
|
|
|
248 |
public function admin_add() {
|
|
|
249 |
if ($this->request->is('post')) {
|
|
|
250 |
$this->Click->create();
|
|
|
251 |
if ($this->Click->save($this->request->data)) {
|
|
|
252 |
$this->Session->setFlash(__('The click has been saved.'));
|
|
|
253 |
return $this->redirect(array('action' => 'index'));
|
|
|
254 |
} else {
|
|
|
255 |
$this->Session->setFlash(__('The click could not be saved. Please, try again.'));
|
|
|
256 |
}
|
|
|
257 |
}
|
|
|
258 |
$users = $this->Click->User->find('list');
|
|
|
259 |
$storeProducts = $this->Click->StoreProduct->find('list');
|
|
|
260 |
$this->set(compact('users', 'storeProducts'));
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
/**
|
|
|
264 |
* admin_edit method
|
|
|
265 |
*
|
|
|
266 |
* @throws NotFoundException
|
|
|
267 |
* @param string $id
|
|
|
268 |
* @return void
|
|
|
269 |
*/
|
|
|
270 |
public function admin_edit($id = null) {
|
|
|
271 |
if (!$this->Click->exists($id)) {
|
|
|
272 |
throw new NotFoundException(__('Invalid click'));
|
|
|
273 |
}
|
|
|
274 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
275 |
if ($this->Click->save($this->request->data)) {
|
|
|
276 |
$this->Session->setFlash(__('The click has been saved.'));
|
|
|
277 |
return $this->redirect(array('action' => 'index'));
|
|
|
278 |
} else {
|
|
|
279 |
$this->Session->setFlash(__('The click could not be saved. Please, try again.'));
|
|
|
280 |
}
|
|
|
281 |
} else {
|
|
|
282 |
$options = array('conditions' => array('Click.' . $this->Click->primaryKey => $id));
|
|
|
283 |
$this->request->data = $this->Click->find('first', $options);
|
|
|
284 |
}
|
|
|
285 |
$users = $this->Click->User->find('list');
|
|
|
286 |
$storeProducts = $this->Click->StoreProduct->find('list');
|
|
|
287 |
$this->set(compact('users', 'storeProducts'));
|
|
|
288 |
}
|
|
|
289 |
|
|
|
290 |
/**
|
|
|
291 |
* admin_delete method
|
|
|
292 |
*
|
|
|
293 |
* @throws NotFoundException
|
|
|
294 |
* @param string $id
|
|
|
295 |
* @return void
|
|
|
296 |
*/
|
|
|
297 |
public function admin_delete($id = null) {
|
|
|
298 |
$this->Click->id = $id;
|
|
|
299 |
if (!$this->Click->exists()) {
|
|
|
300 |
throw new NotFoundException(__('Invalid click'));
|
|
|
301 |
}
|
|
|
302 |
$this->request->onlyAllow('post', 'delete');
|
|
|
303 |
if ($this->Click->delete()) {
|
|
|
304 |
$this->Session->setFlash(__('The click has been deleted.'));
|
|
|
305 |
} else {
|
|
|
306 |
$this->Session->setFlash(__('The click could not be deleted. Please, try again.'));
|
|
|
307 |
}
|
|
|
308 |
return $this->redirect(array('action' => 'index'));
|
| 14302 |
anikendra |
309 |
}
|
|
|
310 |
}
|