Subversion Repositories SmartDukaan

Rev

Rev 18207 | Rev 18223 | 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
 * Categories Controller
5
 *
6
 * @property Category $Category
7
 * @property PaginatorComponent $Paginator
8
 */
9
class CategoriesController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
13794 anikendra 17
	public $apihost;
18
	public $limit;
13532 anikendra 19
 
13596 anikendra 20
	public function beforeFilter() {
21
		parent::beforeFilter();
22
		$this->Auth->allow('deals');
13794 anikendra 23
		$this->apihost = Configure::read('pythonapihost');
24
		$this->limit = Configure::read('dealsperpage');
13596 anikendra 25
	}
26
 
13532 anikendra 27
/**
28
 * index method
29
 *
30
 * @return void
31
 */
32
	public function index() {
33
		// $this->Category->recursive = 0;
34
		// $this->set('categories', $this->Paginator->paginate());
13541 anikendra 35
		$userId = $this->request->query('user_id');
36
		$this->loadModel('UserCategory');
13689 anikendra 37
		$options = array('conditions' => array('user_id'=>$userId),'order'=>array('rank','asc'),'recursive'=>-1);
13541 anikendra 38
		$userCategories = $this->UserCategory->find('all',$options);		
13532 anikendra 39
		$this->response->type('json');
40
		$this->layout = 'ajax';
13541 anikendra 41
		$conditions = array(array('Category.parent_id !='=>0));
42
		if(!empty($userCategories)){
43
			foreach ($userCategories as $key => $value) {
44
				$categoryIds[] = $value['UserCategory']['category_id'];
45
			}
46
			array_push($conditions,array('Category.id'=>$categoryIds));
47
		}
48
		$this->Category->recursive = -1;		
13532 anikendra 49
		$categories = $this->Paginator->paginate(null,$conditions);
50
		$callback = $this->request->query('callback');
51
		$result = array('categories' => $categories);
52
		$this->set(array(
53
		    'result' => $result,
54
		    'callback' => $callback,
55
		    '_serialize' => array('result')
56
		));
57
		$this->render('/Elements/jsonp');
58
	}
59
 
13567 anikendra 60
	public function deals(){
13591 anikendra 61
		$userId = $this->request->query('user_id');
17962 manish.sha 62
		$error = $this->request->query('error');
13591 anikendra 63
		if(isset($userId) && !empty($userId)){
13597 anikendra 64
			$this->loadModel('User');
65
			$dbuser = $this->User->findById($userId);
66
			$this->Auth->login($dbuser['User']);	
13591 anikendra 67
		}
13583 anikendra 68
		$likedDeals = $disLikedDeals = array();
13794 anikendra 69
		// $this->loadModel('Api');
70
		// $apideals = $this->Api->getCategoryDeals($this->Auth->User('id'),1);
71
		// $categorydeals = $apideals['products'];
72
		$page = $this->request->query('page');
73
		if(!isset($page)){
74
			$page = 1;
75
		}
76
		$offset = ($page - 1) * $this->limit;
77
		$url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId=0&limit='.$this->limit.'&offset='.$offset;
17683 naman 78
		//debug($url);
13794 anikendra 79
		$deals = $this->make_request($url,null);		
13583 anikendra 80
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));		
81
		if(!empty($myactions)) {
82
			foreach ($myactions['actions'] as $key => $value) {
83
				if($value['UserAction']['action'] == 'like'){
84
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
85
				}else{
86
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
87
				}
88
			}
89
		}
17962 manish.sha 90
 
91
		$errorstr = '';
92
 
93
		if(isset($error)){
94
			$errorstr = 'Oops!! Some Error Occured. <br> Please try after Some Time';
95
		}
13567 anikendra 96
		$rows = sizeof($categorydeals);
97
		if($rows>=1){
98
			$this->set('deals',$categorydeals);
13583 anikendra 99
			$this->set('likedDeals',$likedDeals);
100
			$this->set('disLikedDeals',$disLikedDeals);
17962 manish.sha 101
			$this->set('errorstr',$errorstr);
13567 anikendra 102
			$this->render('categorydeals');
103
		}else{
104
			foreach ($categorydeals as $key => $dealarr) {
105
				foreach ($dealarr as $key => $deal) {
106
					$deals[] = $deal[0];
107
				}				
108
			}
17962 manish.sha 109
			$this->set(compact('deals','likedDeals','disLikedDeals','errorstr'));
13567 anikendra 110
		}		
111
	}
112
/*
113
	*
13532 anikendra 114
 * view method
115
 *
116
 * @throws NotFoundException
117
 * @param string $id
118
 * @return void
119
 */
120
	public function view($id = null) {
18206 amit.gupta 121
		$searchableSubCategories = array('20'=>'Tempered Glasses', '19^27'=>'Mobile Covers');
14930 anikendra 122
		$userId = $this->request->query('user_id');
17683 naman 123
 
15378 anikendra 124
		if(isset($userId) && !empty($userId)) {
14930 anikendra 125
			$this->loadModel('User');
126
			$dbuser = $this->User->findById($userId);
127
			$this->Auth->login($dbuser['User']);
16549 anikendra 128
		}				
13583 anikendra 129
		$page = $this->request->query('page');
18063 naman 130
		$searchfor = $this->request->query('searchFor');
131
		// echo "page=>",$page;
17810 manish.sha 132
		$error = $this->request->query('error');
13583 anikendra 133
		if(!isset($page)){
134
			$page = 1;
16549 anikendra 135
		}
136
 
13808 anikendra 137
		$sort = $this->request->query('sort');
138
		$direction = $this->request->query('direction');
18207 amit.gupta 139
		//$filter = $this->request->query('filter');
15044 anikendra 140
		// $brands = $this->request->query('brands');
16549 anikendra 141
		if($id != 2) {
142
			//Fetch deals
143
			$likedDeals = $disLikedDeals = array();
17174 naman 144
			$brandschosen = $_COOKIE['brandschosen'];
17683 naman 145
			$subcategorieschosen = $_COOKIE['subcategorieschosen'];			
17759 naman 146
 
147
			// echo "Cookie val", $_COOKIE['old_id'];
148
			// echo "id val", $id;
17683 naman 149
 
18063 naman 150
			if(!empty($searchfor) || $searchfor != null)
151
			{
152
				unset($brandschosen);
153
				setcookie('brandschosen', null, -1, '/');
154
				unset($subcategorieschosen);
155
				setcookie('subcategorieschosen', null, -1, '/');
156
			}
17759 naman 157
 
18004 naman 158
			if((isset($_COOKIE['old_cid'])) && ($_COOKIE['old_cid'] != $id)) {
17683 naman 159
 
160
 
17174 naman 161
				unset($brandschosen);
17683 naman 162
				// setcookie('brandschosen', 1, time()-1, '/');
163
				// unset($_COOKIE['brandschosen']);
164
    			setcookie('brandschosen', null, -1, '/');
165
				unset($subcategorieschosen);
166
				setcookie('subcategorieschosen', 1, time()-1, '/');
167
 
168
			}		
169
 
18004 naman 170
			if((isset($_COOKIE['brandschosen'])) && ($_COOKIE['old_cid'] != $id)) {
17683 naman 171
 
172
				unset($brandschosen);
173
				// setcookie('brandschosen', 1, time()-10, '/');
174
				// unset($_COOKIE['brandschosen']);
175
    			setcookie('brandschosen', null, -1, '/');
176
				unset($subcategorieschosen);
177
				setcookie('subcategorieschosen', 1, time()-1, '/');
178
 
16549 anikendra 179
			}
17683 naman 180
 
18004 naman 181
			setcookie('old_cid', $id, -1, '/');
17683 naman 182
 
183
 
184
				if(!empty($brandschosen) && !empty($subcategorieschosen)){
185
					$filter = 'brand|subcategory';
186
				}			
187
				else if(!empty($brandschosen) && empty($subcategorieschosen)){
188
					$filter = 'brand';
189
				}
190
				if(!empty($subcategorieschosen) && empty($brandschosen)){
191
					$filter = 'subcategory';
192
				}
193
 
16549 anikendra 194
			$brands = str_replace(',', '^', $brandschosen);
17683 naman 195
			$subcategories = str_replace(',', '^', $subcategorieschosen);
196
			$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands,$subcategories);
16549 anikendra 197
			// $url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId='.$id;
198
			$response = $this->make_request($url,null);
199
			$deals = array();
17683 naman 200
 
201
			$response_count =1;
202
			if($response == '')
203
			{
204
				$response_count = 0;
205
			}
206
			// debug($response_count);
16549 anikendra 207
			if(!empty($response)){
208
				foreach ($response as $key => $value) {
209
					if(!empty($value)){
210
						$deals[] = $value;
211
					}
16098 anikendra 212
				}
213
			}
17683 naman 214
			#print_r($deals);
16549 anikendra 215
			$this->loadModel('Api');
216
			$myactions = $this->Api->getMyActions($this->Auth->User('id'));
217
			if(!empty($myactions)) {
218
				foreach ($myactions['actions'] as $key => $value) {
219
					if($value['UserAction']['action'] == 'like'){
220
						$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
221
					}else{
222
						$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
223
					}
13583 anikendra 224
				}
225
			}
16549 anikendra 226
			$this->loadModel('NotificationRule');
227
			$notification = $this->NotificationRule->getNotification($this->Auth->User('id'));	
228
		    $filterstr = '';
229
			if(isset($filter) && !empty($filter)){
17759 naman 230
 
17683 naman 231
			    $filterstr = '&filter='.$filter.'&brands='.$brands.'&subcategories='.$subcategories;
17695 naman 232
		  	} 
233
 
17759 naman 234
 
17695 naman 235
		  	$get_url = "'".$_SERVER['REQUEST_URI']."'";
236
		  	$urlArray = explode('=',$_SERVER['REQUEST_URI']);
237
		  	$last = $urlArray[sizeof($urlArray)-1];
238
 
17759 naman 239
		  	// <Code for url used after scrolling...>
17695 naman 240
		  	if(!isset($filter) && empty($filter)){
241
		  		if (strpos($get_url,'filter=brand&brands') !== false)
242
		  		{
243
		  			$filterstr= "&filter=brand&brands=".$last;
244
		  		}
245
		  		if (strpos($get_url,'filter=subcategory&subcategories') !== false)
246
		  		{
247
		  			$filterstr= "&filter=subcategory&subcategories=".$last;
248
		  		}
249
 
17759 naman 250
		  	}
251
 
252
 
253
			if(!empty($subcategorieschosen) && isset($subcategorieschosen) && empty($brandschosen) && !isset($brandschosen)){	
254
					$filterstr= "&filter=subcategory&subcategories=".$subcategorieschosen;				
255
			}
17810 manish.sha 256
 
257
			$errorstr = '';
258
 
259
			if(isset($error)){
260
				$errorstr = 'Oops!! Some Error Occured. <br> Please try after Some Time';
261
			}
17759 naman 262
 
18063 naman 263
 
264
			$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;			
18115 amit.gupta 265
			$this->set(compact('response_count','deals','id','likedDeals','disLikedDeals','page','sort','direction','notification','filter','brands','filterstr','brandschosen','subcategories','subcategorieschosen','errorstr','nexturl','searchfor', 'searchableSubCategories'));
16549 anikendra 266
		}else{
16583 anikendra 267
			//Check for apk support of sharing
268
			$sharable = 0;
269
			if(isset($_COOKIE['shareApps']) && !empty($_COOKIE['shareApps'])) {
270
				$sharable = 1;
17183 anikendra 271
			}			
16704 anikendra 272
			$url = $this->apihost."appOffers/1";
273
			$appOffers = $this->make_request($url,null);
274
			$this->set(compact('page','id','sharable','appOffers'));
16549 anikendra 275
			$this->render('viewapps');
13583 anikendra 276
		}
13532 anikendra 277
	}
278
 
16549 anikendra 279
	public function getapps($id=null){
280
		$this->layout = 'ajax';
281
		$page = $this->request->query('page');
282
		if(!isset($page)){
283
			$page = 1;
284
		}
285
		$this->loadModel('AppOffer');
286
		$this->AppOffer->recursive = -1;
287
		$options = array('conditions'=>array('offer_active'=>1,'show'=>1),'limit' => Configure::read('searchresultsperpage'),'page'=>$page);
288
		$this->Paginator->settings = $options;
289
		try{
290
			$appOffers = $this->Paginator->paginate('AppOffer');
291
		} catch (NotFoundException $e) {
292
	        //get current page
293
	        $page = $this->request->params['named']['page'];
294
	     	$appOffers = array();   
295
		}
296
		debug($appOffers);		
297
		if(!empty($appOffers)){
298
			$this->set(compact('page','id','appOffers'));
299
			$this->render('/Elements/appoffers');
300
		}else{
301
			$this->render('/Elements/nooffers');
302
		}		
303
	}
304
 
13579 anikendra 305
	public function getdeals($id = null) {
17695 naman 306
 
13808 anikendra 307
		$this->log('getdeal id '.$id,'api');
13583 anikendra 308
		$likedDeals = $disLikedDeals = array();
13579 anikendra 309
		$this->layout = 'ajax';
310
		$page = $this->request->query('page');
311
		if(!isset($page)){
312
			$page = 1;
313
		}
13808 anikendra 314
		$sort = $this->request->query('sort');
315
		$direction = $this->request->query('direction');
15044 anikendra 316
		// $filter = $this->request->query('filter');
317
		// $brands = $this->request->query('brands');
17759 naman 318
		$brandschosen = $_COOKIE['brandschosen'];	 
319
		$subcategorieschosen = $_COOKIE['subcategorieschosen']; 	
320
 
321
		// Replace with the below content
322
		// if(!empty($brandschosen)){
323
		// 	$filter = 'brand';
324
		// }
325
 
326
		//I have replaced the above content
327
		if(!empty($brandschosen) && !empty($subcategorieschosen)){
328
			$filter = 'brand|subcategory';
329
		}			
330
		else if(!empty($brandschosen) && empty($subcategorieschosen)){
15044 anikendra 331
			$filter = 'brand';
332
		}
17759 naman 333
		if(!empty($subcategorieschosen) && empty($brandschosen)){
334
			$filter = 'subcategory';
335
		}
336
		//Replaced end
337
 
15044 anikendra 338
		$brands = str_replace(',', '^', $brandschosen);
17759 naman 339
		$subcategories = str_replace(',', '^', $subcategorieschosen);
340
		$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands,$subcategories);
16098 anikendra 341
		$response = $this->make_request($url,null);
342
		$deals = array();
343
		if(!empty($response)){
344
			foreach ($response as $key => $value) {
345
				if(!empty($value)){
346
					$deals[] = $value;
347
				}
348
			}
349
		}
13794 anikendra 350
		// if (!$this->Category->exists($id)) {
351
			// throw new NotFoundException(__('Invalid category'));
352
		// }
13579 anikendra 353
		$this->loadModel('Api');
13794 anikendra 354
		// $apideals = $this->Api->getDealsByCategory($this->Auth->User('id'),$id,$page);
355
		// $deals = $apideals['products'];
13583 anikendra 356
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
357
		if(!empty($myactions)) {
358
			foreach ($myactions['actions'] as $key => $value) {
359
				if($value['UserAction']['action'] == 'like'){
360
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
361
				}else{
362
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
363
				}
364
			}
365
		}
15026 anikendra 366
		$filterstr = '';
17695 naman 367
 
368
		$get_url = "'".$_SERVER['REQUEST_URI']."'";
369
		$urlArray = explode('=',$_SERVER['REQUEST_URI']);
370
		$last = $urlArray[sizeof($urlArray)-1];
371
 
372
		if(!isset($filter) && empty($filter)){
373
			if (strpos($get_url,'filter=brand&brands') !== false)
374
			{
375
				$filterstr= "&filter=brand&brands=".$last;
376
			}
377
			if (strpos($get_url,'filter=subcategory&subcategories') !== false)
378
			{
379
				$filterstr= "&filter=subcategory&subcategories=".$last;
380
			}
381
 
382
		} 	  	
383
 
15026 anikendra 384
		if(isset($filter) && !empty($filter)){
17759 naman 385
		    // $filterstr = '&filter='.$filter.'&brands='.$brands;
386
		    $filterstr = '&filter='.$filter.'&brands='.$brands.'&subcategories='.$subcategories;
15026 anikendra 387
	  	} 
17759 naman 388
 
389
	  	if(!empty($subcategorieschosen) && isset($subcategorieschosen)&& empty($brandschosen) && !isset($brandschosen)){
390
 
391
	  			$filterstr= "&filter=subcategory&subcategories=".$subcategorieschosen;
392
	  	}
393
 
18063 naman 394
	  	$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;
17759 naman 395
 
18063 naman 396
		$this->set(compact('nexturl','deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','filterstr'));
16098 anikendra 397
		if(!empty($deals) && !empty($deals[0])){
15026 anikendra 398
			$this->render('/Elements/deals');
399
		}else{
400
			$this->render('/Elements/nodeals');
401
		}
17695 naman 402
 
403
 
404
 
13579 anikendra 405
	}
18063 naman 406
 
18212 naman 407
	public function dealdetail($item_id = null){
408
		$this->layout = "innerpages";
409
		$deal = array();
410
		$dealinfo = json_decode('{"entity":{"id":1015088,"url":"mobile-phones/lava-iris-atom-2-1015088","keySpecs":["Dual-SIM, 4.5-inch display, Android KitKat","1.3GHz quad core processor, 512MB RAM","5MP rear and VGA front camera"],"detailedSpecs":[{"title":"Look n Feel","specs":[{"name":"Weight","values":["130 g"]},{"name":"Size","values":["134 x 66 x 9.15 mm"]},{"name":"Form factor","values":["Candybar"]},{"name":"Keyboard","values":["Touchscreen QWERTY keyboard, Touchscreen T9 keyboard"]},{"name":"Hard keys","values":["Power button, Volume keys"]},{"name":"Color","values":["White, Black"]}]},{"title":"Display","specs":[{"name":"Type","values":["TFT LCD"]},{"name":"Screen size","values":["4.5 inch"]},{"name":"Touchscreen type","values":["Capacitive touchscreen"]},{"name":"Resolution","values":["854 x 480 px"]},{"name":"Number of colors","values":["16 M"]},{"name":"Sensors","values":["Accelerometer sensor"]}]},{"title":"Camera","specs":[{"name":"Back camera","values":["5 megapixels"]},{"name":"Flash","values":["LED"]},{"name":"Image formats","values":["JPEG"]},{"name":"Front camera","values":["VGA"]},{"name":"Additional camera features","values":["Panaroma capture, HDR, Digital zoom, Video recording"]}]},{"title":"Hardware","specs":[{"name":"Processor","values":["1.3 GHz Quad core"]}]},{"title":"Memory","specs":[{"name":"Built-in","values":["8 GB"]},{"name":"RAM","values":["512 MB"]},{"name":"Expansion type","values":["MicroSD card"]},{"name":"Expansion capacity","values":["32 GB"]}]},{"title":"Connectivity","specs":[{"name":"GPRS","values":["Yes"]},{"name":"EDGE","values":["Yes"]},{"name":"3G","values":["Yes"]},{"name":"Wi-Fi","values":["Wi-Fi 802.11 b/g/n"]},{"name":"Bluetooth","values":["v2.0"]},{"name":"USB","values":["MicroUSB v2.0"]},{"name":"GPS type","values":["Integrated GPS, A-GPS"]}]},{"title":"Communication","specs":[{"name":"Multiple SIM","values":["Dual-SIM"]},{"name":"2G network","values":["Dualband (GSM 900/1800)"]},{"name":"3G network","values":["WCDMA 2100"]},{"name":"Communication facilities","values":["SMS, Email, Instant messaging"]}]},{"title":"Software","specs":[{"name":"OS","values":["Android v4.4 (KitKat)"]},{"name":"OS upgradeable","values":["Android  v5.1 (Lollipop)"]}]},{"title":"Battery","specs":[{"name":"Capacity","values":["Talk time 2G - 16 hours,Talk time 3G - 6 hours","Standby time 2G - 6 days"]},{"name":"Battery type","values":["Li-Ion 1750 mAh battery"]},{"name":"Charger connector pin","values":["MicroUSB"]}]},{"title":"Music","specs":[{"name":"Music formats","values":["MP3"]},{"name":"Earphone","values":["3.5mm headset"]},{"name":"FM radio","values":["Yes"]}]},{"title":"Video","specs":[{"name":"File formats","values":["MP4"]},{"name":"Video recording","values":["Yes"]}]},{"title":"Miscellaneous","specs":[{"name":"Organizer","values":["Calculator, Alarm, Clock, Calendar"]},{"name":"Other features","values":["oogle Play, Google Search, Gmail, Hangout, Opera Mini, Torch, Clean Master, Note, Auto call recording, Smart gesture control"]}]}],"warranty":"1 year manufacturer\u0027s warranty","pinCode":"110001","logisticsInfo":{"business_days":1,"cod_delivery_estimate":"Mon 11-Jan-16","is_cod_available_for_location":true,"delivery_estimate":"Tomorrow, Sat 09-Jan-16","on_time_guarantee":true},"name":"Lava Iris Atom 2","categoryName":"Mobile Phone","categoryUrl":"mobile-phone/10006","breadCrumb":"\u003ca href\u003d\u0027/\u0027\u003eHome\u003c/a\u003e\u0026nbsp;\u0026gt;\u0026nbsp;\u003ca href\u003d\u0027/mobile-phone/10006\u0027\u003eMobile Phone\u003c/a\u003e\u0026nbsp;\u0026gt;\u0026nbsp;\u003ca href\u003d\u0027/lava\u0027\u003eLava\u003c/a\u003e\u0026nbsp;\u003ca\u003eIris Atom 2\u003c/a\u003e","exclusiveAffiliateInfo":[],"dtrAffiliateJSON":{"map":{"products":{"myArrayList":[{"map":{"source_product_name":"Lava Iris Atom 2 (White)","gross_price":0,"codAvailable":1,"available_price":3949.0,"marketPlaceUrl":"http://www.amazon.in/gp/offer-listing/B013SS1Z3Q","_id":25655,"source_id":1,"offer":"","coupon":""}},{"map":{"source_product_name":"Lava Iris Atom 2 (Black)","gross_price":0,"codAvailable":1,"available_price":4049.0,"marketPlaceUrl":"http://www.amazon.in/gp/offer-listing/B013SS1HMU","_id":25656,"source_id":1,"offer":"","coupon":""}},{"map":{"source_product_name":"Lava Iris Atom 2 8 GB(White)","gross_price":4189.0,"codAvailable":0,"available_price":3980,"marketPlaceUrl":"https://paytm.com/shop/p/lava-iris-atom-2-8-gb-white-MOBLAVA-IRIS-ATSURP492176AE8F567","_id":26991,"source_id":6,"offer":"","coupon":"SAVE5"}},{"map":{"source_product_name":"Lava Iris Atom 2(White, 8 GB)","gross_price":0,"codAvailable":1,"available_price":4049,"marketPlaceUrl":"http://www.flipkart.com/lava-iris-atom-2/p/itmea7n9uaebk2wg?pid\u003dMOBEA7N9CFEUQAGF","_id":26205,"source_id":2,"offer":"","coupon":""}},{"map":{"source_product_name":"Lava Iris Atom 2(Black, 8 GB)","gross_price":0,"codAvailable":1,"available_price":3900,"marketPlaceUrl":"http://www.flipkart.com/lava-iris-atom-2/p/itmea7n9uaebk2wg?pid\u003dMOBEA7N9UZVFS9WJ","_id":26206,"source_id":2,"offer":"","coupon":""}},{"map":{"source_product_name":"Lava Iris Atom 2 8gb White","gross_price":0,"codAvailable":1,"available_price":4049.0,"marketPlaceUrl":"http://www.snapdeal.com/product/lava-iris-atom-2-8gb/625585008444","_id":26203,"source_id":3,"offer":"","coupon":""}},{"map":{"source_product_name":"Lava Iris Atom 2 8gb Black","gross_price":0,"codAvailable":1,"available_price":4049.0,"marketPlaceUrl":"http://www.snapdeal.com/product/lava-iris-atom-2-8gb/641089836520","_id":26204,"source_id":3,"offer":"","coupon":""}},{"map":{"source_product_name":"Lava Iris Atom 2 (Black)","gross_price":4049,"codAvailable":0,"available_price":3847,"marketPlaceUrl":"https://paytm.com/shop/p/lava-iris-atom-2-black-MOBLAVA-IRIS-ATTHE-340303C4506A8","_id":28212,"source_id":6,"offer":"","coupon":"SAVE5"}}]}}},"defaultImageUrl":"http://static2.saholic.com/images/media/1015088/lava-iris-atom-2-default-1442230687000.jpg","iconImageUrl":"http://static2.saholic.com/images/media/1015088/lava-iris-atom-2-icon-1442230687000.jpg","thumbnailImageUrl":"http://static2.saholic.com/images/media/1015088/lava-iris-atom-2-thumbnail-1442230687000.jpg","images":[{"title":"Image 1","url":"http://static2.saholic.com/images/media/1015088/lava-iris-atom-2-default-1442230644000.jpg"},{"title":"Image 2","url":"http://static2.saholic.com/images/media/1015088/lava-iris-atom-2-2-1442230653000.jpg"},{"title":"Image 3","url":"http://static2.saholic.com/images/media/1015088/lava-iris-atom-2-3-1442230662000.jpg"},{"title":"Image 4","url":"http://static2.saholic.com/images/media/1015088/lava-iris-atom-2-4-1442230668000.jpg"}],"videos":[],"packageContents":["Handset","Battery","Charger","Headset","Data cable","User guide "],"items":[{"sellingPrice":4049.0,"id":20889,"color":"White","minEmi":250.0,"buttonText":"BUY NOW","showSellingPrice":true,"comingSoon":false,"dealPojo":{"itemId":20889,"dealTextOption":1,"dealText":"","isCod":true,"dealPrice":3949.0,"dealFreebieOption":1,"freebieItemId":0}},{"sellingPrice":4049.0,"id":20963,"color":"Black","minEmi":250.0,"buttonText":"NOTIFY ME","showSellingPrice":true,"comingSoon":false,"dealPojo":{"itemId":20963,"dealTextOption":1,"dealText":"","isCod":true,"dealPrice":3949.0,"dealFreebieOption":1,"freebieItemId":0}}],"title":"Lava Iris Atom 2 Price in India | Specifications, Features and Reviews","metaDescription":"Buy Lava Iris Atom 2 at 4049.0. All mobile phones are 100% Original and carry full Manufacturers Warranty since we procure directly from the Brand. Free Next Day Delivery."}}',true);
411
		$deal = json_decode('{"coupon": "", "marketPlaceUrl": "http://www.saholic.com/mobile-accessories/imported-thread-usb-cable-(10-retail-packs)-1015160", "buyBoxFlag": 1, "showMrp": 0.0, "rank": 0, "brand_id": 420, "ppq": 14, "videoLink": "", "priceUpdatedOn": 1452163605232, "sourceCategoryId": "", "category": "Accs", "cash_back": 0.0, "subCategory": "Cable", "updatedOn": 1452163605232, "tagline": "<p>One meter length</p>\r\n", "stock_status": "In Stock", "shippingCost": 0.0, "cash_back_type": 1, "gross_price": 0, "cashback": "", "filterLink": "/category/6?searchFor=Cable&filter=subcategory&subcategories=8", "persPoints": 6199.0, "source_product_name": "Imported Thread USB Cable (10 PCS)", "product_name": "Imported Thread USB Cable (10 PCS)", "status": 4, "showVideo": 0.0, "identifier": "1015160", "offer": "", "brand": "Imported", "availabilityInfo": [{"minBuyQuantity": 1, "color": "", "quantityStep": 1, "sellingPriceType": "Private deal price", "maxQuantity": 20, "item_id": 20970, "sellingPrice": 140.0, "availability": 105, "bulkPricing": [{"price": 450.0, "quantity": 4}, {"price": 250.0, "quantity": 2}]}], "source_url": "", "ignorePricing": 0, "in_stock": 1, "sourceProductId": "", "source_id": 4, "skuBundleId": 4566, "available_price": 140, "dp": 899, "is_shortage": 0, "subCategoryId": 8, "category_id": 6, "snapdealSpecialItem": 0, "showDp": 0, "url": "", "codAvailable": 1, "mrp": 0, "maxPrice": 0, "thumbnail": "http://static2.saholic.com/images/media/1015160/imported-thread-usb-cable-(10-pcs)-default-1449817265000.jpg", "source": "saholic", "secondaryIdentifier": "", "filterText": "More Cable", "_id": 27183, "model_name": "Thread USB Cable", "addedOn": 1447936529901, "quantity": 10}',true);
412
 
413
		$this->set(compact('deal','dealinfo'));
414
	}
415
 
18063 naman 416
	public function getdealsforsearchterm($searchterm,$page = null){
417
		$likedDeals = $disLikedDeals = array();
418
		$this->layout = 'ajax';
419
		$page = $this->request->query('page');
420
		$subcategorieschosen = $_COOKIE['subcategorieschosen']; 
421
		if(!isset($page)){
422
			$page = 1;
423
			$offset = 0;
424
			$limit=10;
425
		}
426
		else{
427
			$offset = ($page*20) - 30;
428
			$limit = 20;
429
		}
430
		$sort = $this->request->query('sort');
431
		$direction = $this->request->query('direction');
432
 
18115 amit.gupta 433
		$url = $this->apihost."searchSubCategory/?offset=".$offset."&limit=".$limit."&searchTerm=".urlencode($searchterm)."&subCategoryId=".$subcategorieschosen;
18063 naman 434
		$response = $this->make_request($url,null);
435
		$deals = array();
436
		if(!empty($response)){
437
			foreach ($response as $key => $value) {
438
				if(!empty($value)){
439
					$deals[] = $value;
440
				}
441
			}
442
		}
18115 amit.gupta 443
 
18063 naman 444
		$this->loadModel('Api');
18115 amit.gupta 445
 
18063 naman 446
		$myactions = $this->Api->getMyActions($this->Auth->User('id'));
447
		if(!empty($myactions)) {
448
			foreach ($myactions['actions'] as $key => $value) {
449
				if($value['UserAction']['action'] == 'like'){
450
					$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
451
				}else{
452
					$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];
453
				}
454
			}
455
		}
456
 
457
		$nexturl = "/categories/getdealsforsearchterm/".urlencode($searchterm)."/?page=".($page+1);
458
 
459
		$this->set(compact('deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','nexturl'));
460
		if(!empty($deals) && !empty($deals[0])){
461
			$this->render('/Elements/deals');
462
		}else{
463
			$this->render('/Elements/nodeals');
464
		}
465
 
466
 
467
	}
13532 anikendra 468
/**
469
 * add method
470
 *
471
 * @return void
472
 */
473
	public function add() {
474
		if ($this->request->is('post')) {
475
			$this->Category->create();
476
			if ($this->Category->save($this->request->data)) {
477
				$this->Session->setFlash(__('The category has been saved.'));
478
				return $this->redirect(array('action' => 'index'));
479
			} else {
480
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
481
			}
482
		}
483
	}
484
 
485
/**
486
 * edit method
487
 *
488
 * @throws NotFoundException
489
 * @param string $id
490
 * @return void
491
 */
492
	public function edit($id = null) {
493
		if (!$this->Category->exists($id)) {
494
			throw new NotFoundException(__('Invalid category'));
495
		}
496
		if ($this->request->is(array('post', 'put'))) {
497
			if ($this->Category->save($this->request->data)) {
498
				$this->Session->setFlash(__('The category has been saved.'));
499
				return $this->redirect(array('action' => 'index'));
500
			} else {
501
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
502
			}
503
		} else {
504
			$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
505
			$this->request->data = $this->Category->find('first', $options);
506
		}
507
	}
508
 
509
/**
510
 * delete method
511
 *
512
 * @throws NotFoundException
513
 * @param string $id
514
 * @return void
515
 */
516
	public function delete($id = null) {
517
		$this->Category->id = $id;
518
		if (!$this->Category->exists()) {
519
			throw new NotFoundException(__('Invalid category'));
520
		}
521
		$this->request->onlyAllow('post', 'delete');
522
		if ($this->Category->delete()) {
523
			$this->Session->setFlash(__('The category has been deleted.'));
524
		} else {
525
			$this->Session->setFlash(__('The category could not be deleted. Please, try again.'));
526
		}
527
		return $this->redirect(array('action' => 'index'));
528
	}
529
 
530
/**
531
 * admin_index method
532
 *
533
 * @return void
534
 */
535
	public function admin_index() {
536
		$this->Category->recursive = 0;
537
		$this->set('categories', $this->Paginator->paginate());
538
	}
539
 
540
/**
541
 * admin_view method
542
 *
543
 * @throws NotFoundException
544
 * @param string $id
545
 * @return void
546
 */
547
	public function admin_view($id = null) {
548
		if (!$this->Category->exists($id)) {
549
			throw new NotFoundException(__('Invalid category'));
550
		}
551
		$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
552
		$this->set('category', $this->Category->find('first', $options));
553
	}
554
 
555
/**
556
 * admin_add method
557
 *
558
 * @return void
559
 */
560
	public function admin_add() {
561
		if ($this->request->is('post')) {
562
			// print_r($this->request->data);die;
563
			$this->Category->create();
564
			if ($this->Category->save($this->request->data)) {
565
				$this->Session->setFlash(__('The category has been saved.'));
566
				return $this->redirect(array('action' => 'index'));
567
			} else {
568
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
569
			}
570
		}
571
		$this->set('parent_id',$this->Category->find('list'));
572
	}
573
 
574
/**
575
 * admin_edit method
576
 *
577
 * @throws NotFoundException
578
 * @param string $id
579
 * @return void
580
 */
581
	public function admin_edit($id = null) {
582
		if (!$this->Category->exists($id)) {
583
			throw new NotFoundException(__('Invalid category'));
584
		}
585
		if ($this->request->is(array('post', 'put'))) {
586
			if ($this->Category->save($this->request->data)) {
587
				$this->Session->setFlash(__('The category has been saved.'));
588
				return $this->redirect(array('action' => 'index'));
589
			} else {
590
				$this->Session->setFlash(__('The category could not be saved. Please, try again.'));
591
			}
592
		} else {
593
			$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));
594
			$this->request->data = $this->Category->find('first', $options);
595
		}
596
	}
597
 
598
/**
599
 * admin_delete method
600
 *
601
 * @throws NotFoundException
602
 * @param string $id
603
 * @return void
604
 */
605
	public function admin_delete($id = null) {
606
		$this->Category->id = $id;
607
		if (!$this->Category->exists()) {
608
			throw new NotFoundException(__('Invalid category'));
609
		}
610
		$this->request->onlyAllow('post', 'delete');
611
		if ($this->Category->delete()) {
612
			$this->Session->setFlash(__('The category has been deleted.'));
613
		} else {
614
			$this->Session->setFlash(__('The category could not be deleted. Please, try again.'));
615
		}
616
		return $this->redirect(array('action' => 'index'));
617
	}}