Subversion Repositories SmartDukaan

Rev

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

Rev 13558 Rev 14455
Line 13... Line 13...
13
 *
13
 *
14
 * @var array
14
 * @var array
15
 */
15
 */
16
	public $components = array('Paginator');
16
	public $components = array('Paginator');
17
 
17
 
-
 
18
	public function beforeFilter() {
-
 
19
		parent::beforeFilter();
-
 
20
		$this->Auth->allow('redirectto');
-
 
21
	}
-
 
22
 
18
/**
23
/**
19
 * index method
24
 * index method
20
 *
25
 *
21
 * @return void
26
 * @return void
22
 */
27
 */
23
	public function index() {
28
	public function index() {
24
		$this->Store->recursive = 0;
29
		$this->Store->recursive = 0;
25
		$this->set('stores', $this->Paginator->paginate());
30
		$this->set('stores', $this->Paginator->paginate());		
26
	}
31
	}
27
 
32
 
28
/**
33
/**
29
 * view method
34
 * view method
30
 *
35
 *
Line 38... Line 43...
38
		}
43
		}
39
		$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
44
		$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
40
		$this->set('store', $this->Store->find('first', $options));
45
		$this->set('store', $this->Store->find('first', $options));
41
	}
46
	}
42
 
47
 
-
 
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;
-
 
58
		$store = Cache::read($cachekey,'month');
-
 
59
		if(empty($store)) {
-
 
60
			$store = $this->Store->find('first',array('recursive'=>-1,'conditions'=>array('id'=>$storeProduct['source_id'])));
-
 
61
			Cache::write($cachekey,$store,'month');			
-
 
62
		}
-
 
63
		$prefix = "SHA".$storeId;
-
 
64
		$tag = $prefix.time();
-
 
65
		if($storeId == 2){				
-
 
66
			$url = "http://m.flipkart.com/";
-
 
67
		} elseif($storeId == 3) {
-
 
68
			$url = "http://m.snapdeal.com/?utm_source=aff_prog&utm_campaign=afts&offer_id=17";			
-
 
69
		} elseif($storeId == 1){
-
 
70
			$url = "http://amazon.in";
-
 
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
 
43
/**
93
/**
44
 * add method
94
 * add method
45
 *
95
 *
46
 * @return void
96
 * @return void
47
 */
97
 */