Subversion Repositories SmartDukaan

Rev

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

Rev 15085 Rev 15188
Line 18... Line 18...
18
 
18
 
19
	public function beforeFilter() {
19
	public function beforeFilter() {
20
		parent::beforeFilter();
20
		parent::beforeFilter();
21
		$this->Auth->allow('redirecttosaholic');
21
		$this->Auth->allow('redirecttosaholic');
22
		$this->apihost = Configure::read('pythonapihost');
22
		$this->apihost = Configure::read('pythonapihost');
-
 
23
		$this->livepriceurl = Configure::read('livepriceurl');
23
	}
24
	}
24
/**
25
/**
25
 * index method
26
 * index method
26
 *
27
 *
27
 * @return void
28
 * @return void
Line 115... Line 116...
115
				$url .= '&'.$store['Store']['sub_tag_param'].'='.$tag;
116
				$url .= '&'.$store['Store']['sub_tag_param'].'='.$tag;
116
			}
117
			}
117
			$extras = array('store'=>$store['Store']['name']);
118
			$extras = array('store'=>$store['Store']['name']);
118
			$data = array('user_id'=>$userId,'store_product_id'=>$storeProductId,'price'=>$available_price,'tag'=>$tag,'url'=>$url,'extras'=>json_encode($extras));
119
			$data = array('user_id'=>$userId,'store_product_id'=>$storeProductId,'price'=>$available_price,'tag'=>$tag,'url'=>$url,'extras'=>json_encode($extras));
119
			$this->Click->create();
120
			$this->Click->create();
-
 
121
			$curl = $this->livepriceurl."!latestPriceById?id=$storeProductId&source_id=$storeId&url=".base64_encode($url);
-
 
122
			$response = $this->make_request($curl,null);
-
 
123
			$this->log("live price response ".print_r($response,1),'api');
120
			if ($this->Click->save($data)) {
124
			if ($this->Click->save($data)) {
-
 
125
				if($response['result']){
-
 
126
					$result = array('success'=>true,'message'=> $response['message'],'type'=>'redirect','url'=>$url,'showmessage'=>1);
-
 
127
				}else{
121
				$result = array('success'=>true,'message'=>__('The click has been saved.'),'type'=>'redirect','url'=>$url);
128
					$result = array('success'=>true,'message'=> __('The click has been saved.'),'type'=>'redirect','url'=>$url,'showmessage'=>0);
-
 
129
				}				
122
			} else {
130
			} else {
123
				$result = array('success'=>false,'message'=>__('The click could not be saved. Please, try again.'));
131
				$result = array('success'=>false,'message'=>__('The click could not be saved. Please, try again.'));
124
			}
132
			}
125
			$this->response->type('json');
133
			$this->response->type('json');
126
			$this->layout = 'ajax';
134
			$this->layout = 'ajax';
Line 128... Line 136...
128
			$this->set(array(
136
			$this->set(array(
129
			    'result' => $result,
137
			    'result' => $result,
130
			    'callback' => $callback,
138
			    'callback' => $callback,
131
			    '_serialize' => array('result')
139
			    '_serialize' => array('result')
132
			));
140
			));
133
			$url = $this->apihost.'Catalog/fetchLivePrices/?id='.$storeProductId;
141
			// $url = $this->apihost.'Catalog/fetchLivePrices/?id='.$storeProductId;			
134
			$this->make_request($url,null);
-
 
135
			$this->render('/Elements/jsonp');
142
			$this->render('/Elements/jsonp');
136
		}
143
		}
137
	}
144
	}
138
 
145
 
139
	public function redirecttosaholic() {
146
	public function redirecttosaholic() {