| Line 12... |
Line 12... |
| 12 |
* Components
|
12 |
* Components
|
| 13 |
*
|
13 |
*
|
| 14 |
* @var array
|
14 |
* @var array
|
| 15 |
*/
|
15 |
*/
|
| 16 |
public $components = array('Paginator');
|
16 |
public $components = array('Paginator');
|
| - |
|
17 |
public $apihost;
|
| 17 |
|
18 |
|
| 18 |
public function beforeFilter() {
|
19 |
public function beforeFilter() {
|
| 19 |
parent::beforeFilter();
|
20 |
parent::beforeFilter();
|
| 20 |
$this->Auth->allow('add');
|
21 |
// $this->Auth->allow('add');
|
| - |
|
22 |
$this->apihost = Configure::read('pythonapihost');
|
| 21 |
}
|
23 |
}
|
| 22 |
/**
|
24 |
/**
|
| 23 |
* index method
|
25 |
* index method
|
| 24 |
*
|
26 |
*
|
| 25 |
* @return void
|
27 |
* @return void
|
| Line 50... |
Line 52... |
| 50 |
* @return void
|
52 |
* @return void
|
| 51 |
*/
|
53 |
*/
|
| 52 |
public function add($userId=null,$storeProductId=null) {
|
54 |
public function add($userId=null,$storeProductId=null) {
|
| 53 |
if(!empty($userId) && !empty($storeProductId)){
|
55 |
if(!empty($userId) && !empty($storeProductId)){
|
| 54 |
//Get StoreProduct Info
|
56 |
//Get StoreProduct Info
|
| 55 |
$this->loadModel('StoreProduct');
|
57 |
$this->loadModel('Store');
|
| 56 |
$options = array('conditions'=>array('id'=>$storeProductId),'fields'=>array('store_id','available_price','url'),'recursive'=>-1);
|
58 |
// $options = array('conditions'=>array('id'=>$storeProductId),'fields'=>array('source_id','available_price','url'),'recursive'=>-1);
|
| 57 |
$storeProduct = $this->StoreProduct->find('first',$options);
|
59 |
// $storeProduct = $this->StoreProduct->find('first',$options);
|
| - |
|
60 |
$cachekey = 'storeproduct-'.$storeProductId;
|
| - |
|
61 |
$product = Cache::read($cachekey,'month');
|
| - |
|
62 |
if(empty($storeProduct)) {
|
| - |
|
63 |
$url = $this->apihost.'masterData/getSkuById/'.$storeProductId;
|
| - |
|
64 |
$product = $this->make_request($url,null);
|
| - |
|
65 |
Cache::write($cachekey,$product,'month');
|
| - |
|
66 |
}
|
| - |
|
67 |
$storeProduct = json_decode($product[0],1);
|
| 58 |
$store = $this->StoreProduct->Store->find('first',array('recursive'=>-1,'conditions'=>array('id'=>$storeProduct['StoreProduct']['store_id'])));
|
68 |
$store = $this->Store->find('first',array('recursive'=>-1,'conditions'=>array('id'=>$storeProduct['source_id'])));
|
| 59 |
$prefix = "SHA".$storeProduct['StoreProduct']['store_id'];
|
69 |
$prefix = "SHA".$storeProduct['source_id'];
|
| 60 |
$tag = $prefix.time();
|
70 |
$tag = $prefix.time();
|
| 61 |
if($storeProduct['StoreProduct']['store_id'] == 2){
|
71 |
if($storeProduct['source_id'] == 2){
|
| 62 |
$url_parts = parse_url($storeProduct['StoreProduct']['url']);
|
72 |
$url_parts = parse_url($storeProduct['marketPlaceUrl']);
|
| 63 |
$url = "http://dl.flipkart.com/dl".$url_parts['path'].'?'.$url_parts['query'];
|
73 |
$url = "http://dl.flipkart.com/dl".$url_parts['path'].'?'.$url_parts['query'];
|
| 64 |
} elseif($storeProduct['StoreProduct']['store_id'] == 3) {
|
74 |
} elseif($storeProduct['source_id'] == 3) {
|
| 65 |
$url = $storeProduct['StoreProduct']['url']."?utm_source=aff_prog&utm_campaign=afts&offer_id=17";
|
75 |
$url = $storeProduct['marketPlaceUrl']."?utm_source=aff_prog&utm_campaign=afts&offer_id=17";
|
| 66 |
}else{
|
76 |
}else{
|
| 67 |
$url = $storeProduct['StoreProduct']['url'];
|
77 |
$url = $storeProduct['marketPlaceUrl'];
|
| 68 |
}
|
78 |
}
|
| 69 |
if( strpos($url, '?') === false ) {
|
79 |
if( strpos($url, '?') === false ) {
|
| 70 |
$firstChar = '?';
|
80 |
$firstChar = '?';
|
| 71 |
} else {
|
81 |
} else {
|
| 72 |
$firstChar = '&';
|
82 |
$firstChar = '&';
|
| Line 74... |
Line 84... |
| 74 |
$url .= $firstChar.$store['Store']['affid_param'].'='.$store['Store']['affiliate_id'];
|
84 |
$url .= $firstChar.$store['Store']['affid_param'].'='.$store['Store']['affiliate_id'];
|
| 75 |
if(!empty($store['Store']['sub_tag_param'])){
|
85 |
if(!empty($store['Store']['sub_tag_param'])){
|
| 76 |
$url .= '&'.$store['Store']['sub_tag_param'].'='.$tag;
|
86 |
$url .= '&'.$store['Store']['sub_tag_param'].'='.$tag;
|
| 77 |
}
|
87 |
}
|
| 78 |
$extras = array('store'=>$store['Store']['name']);
|
88 |
$extras = array('store'=>$store['Store']['name']);
|
| 79 |
$data = array('user_id'=>$userId,'store_product_id'=>$storeProductId,'price'=>$storeProduct['StoreProduct']['available_price'],'tag'=>$tag,'url'=>$url,'extras'=>json_encode($extras));
|
89 |
$data = array('user_id'=>$userId,'store_product_id'=>$storeProductId,'price'=>$storeProduct['available_price'],'tag'=>$tag,'url'=>$url,'extras'=>json_encode($extras));
|
| 80 |
$this->Click->create();
|
90 |
$this->Click->create();
|
| 81 |
if ($this->Click->save($data)) {
|
91 |
if ($this->Click->save($data)) {
|
| 82 |
$result = array('success'=>true,'message'=>__('The click has been saved.'),'type'=>'redirect','url'=>$url);
|
92 |
$result = array('success'=>true,'message'=>__('The click has been saved.'),'type'=>'redirect','url'=>$url);
|
| 83 |
} else {
|
93 |
} else {
|
| 84 |
$result = array('success'=>false,'message'=>__('The click could not be saved. Please, try again.'));
|
94 |
$result = array('success'=>false,'message'=>__('The click could not be saved. Please, try again.'));
|