Subversion Repositories SmartDukaan

Rev

Rev 14441 | Rev 14509 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 14441 Rev 14445
Line 303... Line 303...
303
				$this->set(compact('users'));
303
				$this->set(compact('users'));
304
			}
304
			}
305
		}
305
		}
306
	}
306
	}
307
 
307
 
308
	public function generateAffiliateUrl($url,$user_id){
308
	public function generateAffiliateUrl($url,$user_id,$store){
309
		//Get StoreProduct Info
309
		//Get StoreProduct Info		
310
		$this->loadModel('Store');
-
 
311
		$store = $this->Store->getByUrl($url);	
-
 
312
		$storeId = $store['Store']['id'];
310
		$storeId = $store['Store']['id'];
313
		$prefix = "SHA".$storeId;
311
		$prefix = "SHA".$storeId;
314
		$tag = $prefix.time();
312
		$tag = $prefix.time();
315
		if($storeId == 2){				
313
		if($storeId == 2){				
316
			$url = str_replace('www','m',$url);
314
			$url = str_replace('www','m',$url);
Line 321... Line 319...
321
				$url = "http://m.snapdeal.com".$url_parts['path'].'?'.$url_parts['query']."&utm_source=aff_prog&utm_campaign=afts&offer_id=17";
319
				$url = "http://m.snapdeal.com".$url_parts['path'].'?'.$url_parts['query']."&utm_source=aff_prog&utm_campaign=afts&offer_id=17";
322
			}else{
320
			}else{
323
				$url = "http://m.snapdeal.com".$url_parts['path'].'?utm_source=aff_prog&utm_campaign=afts&offer_id=17';
321
				$url = "http://m.snapdeal.com".$url_parts['path'].'?utm_source=aff_prog&utm_campaign=afts&offer_id=17';
324
			}
322
			}
325
		} elseif($storeId == 4){
323
		} elseif($storeId == 4){
326
			$next = "&next=".str_replace('www','m',$url);	
324
			$next = str_replace('www','m',$url);	
327
			$url = $this->getAutoLoginUrl($userId,$next);
325
			$url = $this->getAutoLoginUrl($userId,$next);
328
			$url .= '?utm_source=profitmandi';
326
			$url .= '?utm_source=profitmandi';
329
		}
327
		}
330
		if( strpos($url, '?') === false ) {
328
		if( strpos($url, '?') === false ) {
331
			$firstChar = '?';
329
			$firstChar = '?';
Line 348... Line 346...
348
		if ($this->request->is('post')) {
346
		if ($this->request->is('post')) {
349
			if(empty($this->request->data['userIds'])){
347
			if(empty($this->request->data['userIds'])){
350
				$this->Session->setFlash(__('Please choose a few users'));
348
				$this->Session->setFlash(__('Please choose a few users'));
351
				$this->redirect(array('action' => 'admin_pushnotifications'));
349
				$this->redirect(array('action' => 'admin_pushnotifications'));
352
			}else{
350
			}else{
-
 
351
				$message = $this->request->data['User'];
-
 
352
				if($message['type'] == 'url' && !empty($message['url'])) {
-
 
353
					$url = $message['url'];
-
 
354
					$this->loadModel('Store');
-
 
355
					$store = $this->Store->getByUrl($url);					
-
 
356
				}				
353
				$this->loadModel('GcmUser');
357
				$this->loadModel('GcmUser');
354
				foreach ($this->request->data['userIds'] as $key => $value) {					
358
				foreach ($this->request->data['userIds'] as $key => $value) {					
355
					$options = array('conditions'=>array('user_id'=>$value),'fields'=>array('gcm_regid'),'order'=>array('id'=>'desc'));
359
					$options = array('conditions'=>array('user_id'=>$value),'fields'=>array('gcm_regid'),'order'=>array('id'=>'desc'));
356
					$gcmUser = $this->GcmUser->find('first',$options);
360
					$gcmUser = $this->GcmUser->find('first',$options);
357
					$regIds = array($gcmUser['GcmUser']['gcm_regid']);
361
					$regIds = array($gcmUser['GcmUser']['gcm_regid']);
358
					// $message = array('message'=>$this->request->data['User']['message']);
362
					// $message = array('message'=>$this->request->data['User']['message']);					
359
					$message = $this->request->data['User'];
-
 
360
					if($message['type'] == 'url'){
363
					if($message['type'] == 'url' && !empty($message['url'])) {
361
						$message['url'] = $this->generateAffiliateUrl($message['url'],$value);
364
						$message['url'] = $this->generateAffiliateUrl($url,$value,$store);
362
					}					
365
					}					
363
					$this->send_push_notification($regIds,$message,$value);
366
					$this->send_push_notification($regIds,$message,$value);
364
				}
367
				}
365
			}
368
			}
366
		}
369
		}