Subversion Repositories SmartDukaan

Rev

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

Rev 13532 Rev 13558
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('add');
-
 
21
	}
18
/**
22
/**
19
 * index method
23
 * index method
20
 *
24
 *
21
 * @return void
25
 * @return void
22
 */
26
 */
Line 43... Line 47...
43
/**
47
/**
44
 * add method
48
 * add method
45
 *
49
 *
46
 * @return void
50
 * @return void
47
 */
51
 */
48
	public function add() {
52
	public function add($userId=null,$storeProductId=null) {
-
 
53
		if(!empty($userId) && !empty($storeProductId)){
-
 
54
			//Get StoreProduct Info
49
		if ($this->request->is('post')) {
55
			$this->loadModel('StoreProduct');
-
 
56
			$options = array('conditions'=>array('id'=>$storeProductId),'fields'=>array('store_id','available_price','url'),'recursive'=>-1);
-
 
57
			$storeProduct = $this->StoreProduct->find('first',$options);
-
 
58
			$store = $this->StoreProduct->Store->find('first',array('recursive'=>-1,'conditions'=>array('id'=>$storeProduct['StoreProduct']['store_id'])));
-
 
59
			$prefix = "DTR".$storeProduct['StoreProduct']['store_id'];
-
 
60
			$tag = uniqid($prefix);
-
 
61
			if($storeProduct['StoreProduct']['store_id'] == 2){
-
 
62
				$url = str_replace('http://www', 'http://dl', $storeProduct['StoreProduct']['url']);
-
 
63
			}else{
-
 
64
				$url = $storeProduct['StoreProduct']['url'];
-
 
65
			}
-
 
66
			if( strpos($url, '?') === false ) {
-
 
67
				$firstChar = '?';
-
 
68
			} else {
-
 
69
				$firstChar = '=';
-
 
70
			}
-
 
71
			$url .= $firstChar.$store['Store']['affid_param'].'='.$store['Store']['affiliate_id'];
-
 
72
			if(!empty($store['Store']['sub_tag_param'])){
-
 
73
				$url .= '&'.$store['Store']['sub_tag_param'].'='.$tag;
-
 
74
			}
-
 
75
			$extras = array('store'=>$store['Store']['name']);
-
 
76
			$data = array('user_id'=>$userId,'store_product_id'=>$storeProductId,'price'=>$storeProduct['StoreProduct']['available_price'],'tag'=>$tag,'url'=>$url,'extras'=>json_encode($extras));
50
			$this->Click->create();
77
			$this->Click->create();
51
			if ($this->Click->save($this->request->data)) {
78
			if ($this->Click->save($data)) {
52
				$this->Session->setFlash(__('The click has been saved.'));
79
				$result = array('success'=>true,'message'=>__('The click has been saved.'),'type'=>'redirect','url'=>$url);
53
				return $this->redirect(array('action' => 'index'));
-
 
54
			} else {
80
			} else {
55
				$this->Session->setFlash(__('The click could not be saved. Please, try again.'));
81
				$result = array('success'=>false,'message'=>__('The click could not be saved. Please, try again.'));
56
			}
82
			}
-
 
83
			$this->response->type('json');
-
 
84
			$this->layout = 'ajax';
-
 
85
			$callback = $this->request->query('callback');
-
 
86
			$this->set(array(
-
 
87
			    'result' => $result,
-
 
88
			    'callback' => $callback,
-
 
89
			    '_serialize' => array('result')
-
 
90
			));
-
 
91
			$this->render('/Elements/jsonp');
57
		}
92
		}
58
		$users = $this->Click->User->find('list');
-
 
59
		$storeProducts = $this->Click->StoreProduct->find('list');
-
 
60
		$this->set(compact('users', 'storeProducts'));
-
 
61
	}
93
	}
62
 
94
 
63
/**
95
/**
64
 * edit method
96
 * edit method
65
 *
97
 *