| 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 |
*/
|
| 13558 |
anikendra |
54 |
public function add($userId=null,$storeProductId=null) {
|
|
|
55 |
if(!empty($userId) && !empty($storeProductId)){
|
|
|
56 |
//Get StoreProduct Info
|
| 13808 |
anikendra |
57 |
$this->loadModel('Store');
|
|
|
58 |
// $options = array('conditions'=>array('id'=>$storeProductId),'fields'=>array('source_id','available_price','url'),'recursive'=>-1);
|
|
|
59 |
// $storeProduct = $this->StoreProduct->find('first',$options);
|
|
|
60 |
$cachekey = 'storeproduct-'.$storeProductId;
|
| 14139 |
anikendra |
61 |
$product = Cache::read($cachekey,'five');
|
| 13863 |
anikendra |
62 |
if(empty($product)) {
|
| 13808 |
anikendra |
63 |
$url = $this->apihost.'masterData/getSkuById/'.$storeProductId;
|
|
|
64 |
$product = $this->make_request($url,null);
|
| 14139 |
anikendra |
65 |
Cache::write($cachekey,$product,'five');
|
| 13808 |
anikendra |
66 |
}
|
|
|
67 |
$storeProduct = json_decode($product[0],1);
|
| 13903 |
anikendra |
68 |
$cachekey = 'store-'.$storeProduct['source_id'];
|
| 14316 |
anikendra |
69 |
// $store = Cache::read($cachekey,'month');
|
| 13903 |
anikendra |
70 |
if(empty($store)) {
|
|
|
71 |
$store = $this->Store->find('first',array('recursive'=>-1,'conditions'=>array('id'=>$storeProduct['source_id'])));
|
|
|
72 |
Cache::write($cachekey,$store,'month');
|
|
|
73 |
}
|
| 13808 |
anikendra |
74 |
$prefix = "SHA".$storeProduct['source_id'];
|
| 13599 |
anikendra |
75 |
$tag = $prefix.time();
|
| 14163 |
anikendra |
76 |
if($storeProduct['source_id'] == 2){
|
| 14139 |
anikendra |
77 |
$url = str_replace('www','m',$storeProduct['marketPlaceUrl']);
|
| 13808 |
anikendra |
78 |
} elseif($storeProduct['source_id'] == 3) {
|
| 13863 |
anikendra |
79 |
$url_parts = parse_url($storeProduct['marketPlaceUrl']);
|
| 13903 |
anikendra |
80 |
$url_parts['path'] = str_replace('viewAllSellers/','',$url_parts['path']);//quickfix for snapdeal
|
| 13901 |
anikendra |
81 |
if(isset($url_parts['query'])) {
|
| 13903 |
anikendra |
82 |
$url = "http://m.snapdeal.com".$url_parts['path'].'?'.$url_parts['query']."&utm_source=aff_prog&utm_campaign=afts&offer_id=17";
|
| 13901 |
anikendra |
83 |
}else{
|
| 13903 |
anikendra |
84 |
$url = "http://m.snapdeal.com".$url_parts['path'].'?utm_source=aff_prog&utm_campaign=afts&offer_id=17';
|
| 13901 |
anikendra |
85 |
}
|
| 14150 |
anikendra |
86 |
} elseif($storeProduct['source_id'] == 4){
|
| 14163 |
anikendra |
87 |
$next = "&next=".str_replace('www','m',$storeProduct['marketPlaceUrl']);
|
| 14150 |
anikendra |
88 |
$url = $this->getAutoLoginUrl($userId,$next);
|
| 14316 |
anikendra |
89 |
$url .= '?utm_source=profitmandi';
|
| 13558 |
anikendra |
90 |
}else{
|
| 13808 |
anikendra |
91 |
$url = $storeProduct['marketPlaceUrl'];
|
| 13558 |
anikendra |
92 |
}
|
|
|
93 |
if( strpos($url, '?') === false ) {
|
|
|
94 |
$firstChar = '?';
|
|
|
95 |
} else {
|
| 13561 |
anikendra |
96 |
$firstChar = '&';
|
| 13558 |
anikendra |
97 |
}
|
|
|
98 |
$url .= $firstChar.$store['Store']['affid_param'].'='.$store['Store']['affiliate_id'];
|
|
|
99 |
if(!empty($store['Store']['sub_tag_param'])){
|
|
|
100 |
$url .= '&'.$store['Store']['sub_tag_param'].'='.$tag;
|
|
|
101 |
}
|
|
|
102 |
$extras = array('store'=>$store['Store']['name']);
|
| 13808 |
anikendra |
103 |
$data = array('user_id'=>$userId,'store_product_id'=>$storeProductId,'price'=>$storeProduct['available_price'],'tag'=>$tag,'url'=>$url,'extras'=>json_encode($extras));
|
| 13532 |
anikendra |
104 |
$this->Click->create();
|
| 13558 |
anikendra |
105 |
if ($this->Click->save($data)) {
|
|
|
106 |
$result = array('success'=>true,'message'=>__('The click has been saved.'),'type'=>'redirect','url'=>$url);
|
| 13532 |
anikendra |
107 |
} else {
|
| 13558 |
anikendra |
108 |
$result = array('success'=>false,'message'=>__('The click could not be saved. Please, try again.'));
|
| 13532 |
anikendra |
109 |
}
|
| 13558 |
anikendra |
110 |
$this->response->type('json');
|
|
|
111 |
$this->layout = 'ajax';
|
|
|
112 |
$callback = $this->request->query('callback');
|
|
|
113 |
$this->set(array(
|
|
|
114 |
'result' => $result,
|
|
|
115 |
'callback' => $callback,
|
|
|
116 |
'_serialize' => array('result')
|
|
|
117 |
));
|
| 13903 |
anikendra |
118 |
$url = $this->apihost.'Catalog/fetchLivePrices/?id='.$storeProductId;
|
|
|
119 |
$this->make_request($url,null);
|
| 13558 |
anikendra |
120 |
$this->render('/Elements/jsonp');
|
| 13532 |
anikendra |
121 |
}
|
|
|
122 |
}
|
|
|
123 |
|
| 14302 |
anikendra |
124 |
public function redirecttosaholic() {
|
|
|
125 |
$userId = $this->request->query('user_id');
|
|
|
126 |
if(isset($userId) && !empty($userId)){
|
|
|
127 |
$next = "&next=/private-deals/1";
|
|
|
128 |
$redirectUrl = $this->getAutoLoginUrl($userId,$next);
|
|
|
129 |
header('location:'.$redirectUrl);
|
|
|
130 |
exit();
|
|
|
131 |
}
|
|
|
132 |
}
|
|
|
133 |
|
| 13532 |
anikendra |
134 |
/**
|
|
|
135 |
* edit method
|
|
|
136 |
*
|
|
|
137 |
* @throws NotFoundException
|
|
|
138 |
* @param string $id
|
|
|
139 |
* @return void
|
|
|
140 |
*/
|
|
|
141 |
public function edit($id = null) {
|
|
|
142 |
if (!$this->Click->exists($id)) {
|
|
|
143 |
throw new NotFoundException(__('Invalid click'));
|
|
|
144 |
}
|
|
|
145 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
146 |
if ($this->Click->save($this->request->data)) {
|
|
|
147 |
$this->Session->setFlash(__('The click has been saved.'));
|
|
|
148 |
return $this->redirect(array('action' => 'index'));
|
|
|
149 |
} else {
|
|
|
150 |
$this->Session->setFlash(__('The click could not be saved. Please, try again.'));
|
|
|
151 |
}
|
|
|
152 |
} else {
|
|
|
153 |
$options = array('conditions' => array('Click.' . $this->Click->primaryKey => $id));
|
|
|
154 |
$this->request->data = $this->Click->find('first', $options);
|
|
|
155 |
}
|
|
|
156 |
$users = $this->Click->User->find('list');
|
|
|
157 |
$storeProducts = $this->Click->StoreProduct->find('list');
|
|
|
158 |
$this->set(compact('users', 'storeProducts'));
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
/**
|
|
|
162 |
* delete method
|
|
|
163 |
*
|
|
|
164 |
* @throws NotFoundException
|
|
|
165 |
* @param string $id
|
|
|
166 |
* @return void
|
|
|
167 |
*/
|
|
|
168 |
public function delete($id = null) {
|
|
|
169 |
$this->Click->id = $id;
|
|
|
170 |
if (!$this->Click->exists()) {
|
|
|
171 |
throw new NotFoundException(__('Invalid click'));
|
|
|
172 |
}
|
|
|
173 |
$this->request->onlyAllow('post', 'delete');
|
|
|
174 |
if ($this->Click->delete()) {
|
|
|
175 |
$this->Session->setFlash(__('The click has been deleted.'));
|
|
|
176 |
} else {
|
|
|
177 |
$this->Session->setFlash(__('The click could not be deleted. Please, try again.'));
|
|
|
178 |
}
|
|
|
179 |
return $this->redirect(array('action' => 'index'));
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
/**
|
|
|
183 |
* admin_index method
|
|
|
184 |
*
|
|
|
185 |
* @return void
|
|
|
186 |
*/
|
|
|
187 |
public function admin_index() {
|
|
|
188 |
$this->Click->recursive = 0;
|
|
|
189 |
$this->set('clicks', $this->Paginator->paginate());
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
/**
|
|
|
193 |
* admin_view method
|
|
|
194 |
*
|
|
|
195 |
* @throws NotFoundException
|
|
|
196 |
* @param string $id
|
|
|
197 |
* @return void
|
|
|
198 |
*/
|
|
|
199 |
public function admin_view($id = null) {
|
|
|
200 |
if (!$this->Click->exists($id)) {
|
|
|
201 |
throw new NotFoundException(__('Invalid click'));
|
|
|
202 |
}
|
|
|
203 |
$options = array('conditions' => array('Click.' . $this->Click->primaryKey => $id));
|
|
|
204 |
$this->set('click', $this->Click->find('first', $options));
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
/**
|
|
|
208 |
* admin_add method
|
|
|
209 |
*
|
|
|
210 |
* @return void
|
|
|
211 |
*/
|
|
|
212 |
public function admin_add() {
|
|
|
213 |
if ($this->request->is('post')) {
|
|
|
214 |
$this->Click->create();
|
|
|
215 |
if ($this->Click->save($this->request->data)) {
|
|
|
216 |
$this->Session->setFlash(__('The click has been saved.'));
|
|
|
217 |
return $this->redirect(array('action' => 'index'));
|
|
|
218 |
} else {
|
|
|
219 |
$this->Session->setFlash(__('The click could not be saved. Please, try again.'));
|
|
|
220 |
}
|
|
|
221 |
}
|
|
|
222 |
$users = $this->Click->User->find('list');
|
|
|
223 |
$storeProducts = $this->Click->StoreProduct->find('list');
|
|
|
224 |
$this->set(compact('users', 'storeProducts'));
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
/**
|
|
|
228 |
* admin_edit method
|
|
|
229 |
*
|
|
|
230 |
* @throws NotFoundException
|
|
|
231 |
* @param string $id
|
|
|
232 |
* @return void
|
|
|
233 |
*/
|
|
|
234 |
public function admin_edit($id = null) {
|
|
|
235 |
if (!$this->Click->exists($id)) {
|
|
|
236 |
throw new NotFoundException(__('Invalid click'));
|
|
|
237 |
}
|
|
|
238 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
239 |
if ($this->Click->save($this->request->data)) {
|
|
|
240 |
$this->Session->setFlash(__('The click has been saved.'));
|
|
|
241 |
return $this->redirect(array('action' => 'index'));
|
|
|
242 |
} else {
|
|
|
243 |
$this->Session->setFlash(__('The click could not be saved. Please, try again.'));
|
|
|
244 |
}
|
|
|
245 |
} else {
|
|
|
246 |
$options = array('conditions' => array('Click.' . $this->Click->primaryKey => $id));
|
|
|
247 |
$this->request->data = $this->Click->find('first', $options);
|
|
|
248 |
}
|
|
|
249 |
$users = $this->Click->User->find('list');
|
|
|
250 |
$storeProducts = $this->Click->StoreProduct->find('list');
|
|
|
251 |
$this->set(compact('users', 'storeProducts'));
|
|
|
252 |
}
|
|
|
253 |
|
|
|
254 |
/**
|
|
|
255 |
* admin_delete method
|
|
|
256 |
*
|
|
|
257 |
* @throws NotFoundException
|
|
|
258 |
* @param string $id
|
|
|
259 |
* @return void
|
|
|
260 |
*/
|
|
|
261 |
public function admin_delete($id = null) {
|
|
|
262 |
$this->Click->id = $id;
|
|
|
263 |
if (!$this->Click->exists()) {
|
|
|
264 |
throw new NotFoundException(__('Invalid click'));
|
|
|
265 |
}
|
|
|
266 |
$this->request->onlyAllow('post', 'delete');
|
|
|
267 |
if ($this->Click->delete()) {
|
|
|
268 |
$this->Session->setFlash(__('The click has been deleted.'));
|
|
|
269 |
} else {
|
|
|
270 |
$this->Session->setFlash(__('The click could not be deleted. Please, try again.'));
|
|
|
271 |
}
|
|
|
272 |
return $this->redirect(array('action' => 'index'));
|
| 14302 |
anikendra |
273 |
}
|
|
|
274 |
}
|