| Line 49... |
Line 49... |
| 49 |
/**
|
49 |
/**
|
| 50 |
* add method
|
50 |
* add method
|
| 51 |
*
|
51 |
*
|
| 52 |
* @return void
|
52 |
* @return void
|
| 53 |
*/
|
53 |
*/
|
| 54 |
public function add($userId=null,$storeProductId=null) {
|
54 |
public function add($userId=null,$storeProductId=null,$storeId=null) {
|
| 55 |
if(!empty($userId) && !empty($storeProductId)){
|
55 |
if(!empty($userId) && !empty($storeProductId)){
|
| - |
|
56 |
$url = $this->request->query('url');
|
| - |
|
57 |
$available_price = $this->request->query('price');
|
| 56 |
//Get StoreProduct Info
|
58 |
//Get StoreProduct Info
|
| 57 |
$this->loadModel('Store');
|
59 |
$this->loadModel('Store');
|
| 58 |
// $options = array('conditions'=>array('id'=>$storeProductId),'fields'=>array('source_id','available_price','url'),'recursive'=>-1);
|
60 |
// $options = array('conditions'=>array('id'=>$storeProductId),'fields'=>array('source_id','available_price','url'),'recursive'=>-1);
|
| 59 |
// $storeProduct = $this->StoreProduct->find('first',$options);
|
61 |
// $storeProduct = $this->StoreProduct->find('first',$options);
|
| 60 |
$cachekey = 'storeproduct-'.$storeProductId;
|
62 |
$cachekey = 'storeproduct-'.$storeProductId;
|
| - |
|
63 |
|
| - |
|
64 |
if($url=='undefined' || $available_price=='undefined' || $storeId=='undefined') {
|
| 61 |
$product = Cache::read($cachekey,'five');
|
65 |
$product = Cache::read($cachekey,'five');
|
| 62 |
if(empty($product)) {
|
66 |
if(empty($product)) {
|
| 63 |
$url = $this->apihost.'masterData/getSkuById/'.$storeProductId;
|
67 |
$url = $this->apihost.'masterData/getSkuById/'.$storeProductId;
|
| 64 |
$product = $this->make_request($url,null);
|
68 |
$product = $this->make_request($url,null);
|
| 65 |
Cache::write($cachekey,$product,'five');
|
69 |
Cache::write($cachekey,$product,'five');
|
| - |
|
70 |
}
|
| - |
|
71 |
$storeProduct = json_decode($product[0],1);
|
| - |
|
72 |
$url = $storeProduct['marketPlaceUrl'];
|
| - |
|
73 |
$storeId = $storeProduct['source_id'];
|
| - |
|
74 |
$available_price = $storeProduct['available_price'];
|
| 66 |
}
|
75 |
}
|
| 67 |
$storeProduct = json_decode($product[0],1);
|
- |
|
| 68 |
$cachekey = 'store-'.$storeProduct['source_id'];
|
76 |
$cachekey = 'store-'.$storeId;
|
| 69 |
// $store = Cache::read($cachekey,'month');
|
77 |
// $store = Cache::read($cachekey,'month');
|
| 70 |
if(empty($store)) {
|
78 |
if(empty($storeId)) {
|
| 71 |
$store = $this->Store->find('first',array('recursive'=>-1,'conditions'=>array('id'=>$storeProduct['source_id'])));
|
79 |
$store = $this->Store->find('first',array('recursive'=>-1,'conditions'=>array('id'=>$storeProduct['source_id'])));
|
| 72 |
Cache::write($cachekey,$store,'month');
|
80 |
Cache::write($cachekey,$store,'month');
|
| 73 |
}
|
81 |
}
|
| 74 |
$prefix = "SHA".$storeProduct['source_id'];
|
82 |
$prefix = "SHA".$storeId;
|
| 75 |
$tag = $prefix.time();
|
83 |
$tag = $prefix.time();
|
| 76 |
if($storeProduct['source_id'] == 2){
|
84 |
if($storeId == 2){
|
| 77 |
$url = str_replace('www','m',$storeProduct['marketPlaceUrl']);
|
85 |
$url = str_replace('www','m',$url);
|
| 78 |
} elseif($storeProduct['source_id'] == 3) {
|
86 |
} elseif($storeId == 3) {
|
| 79 |
$url_parts = parse_url($storeProduct['marketPlaceUrl']);
|
87 |
$url_parts = parse_url($url);
|
| 80 |
$url_parts['path'] = str_replace('viewAllSellers/','',$url_parts['path']);//quickfix for snapdeal
|
88 |
$url_parts['path'] = str_replace('viewAllSellers/','',$url_parts['path']);//quickfix for snapdeal
|
| 81 |
if(isset($url_parts['query'])) {
|
89 |
if(isset($url_parts['query'])) {
|
| 82 |
$url = "http://m.snapdeal.com".$url_parts['path'].'?'.$url_parts['query']."&utm_source=aff_prog&utm_campaign=afts&offer_id=17";
|
90 |
$url = "http://m.snapdeal.com".$url_parts['path'].'?'.$url_parts['query']."&utm_source=aff_prog&utm_campaign=afts&offer_id=17";
|
| 83 |
}else{
|
91 |
}else{
|
| 84 |
$url = "http://m.snapdeal.com".$url_parts['path'].'?utm_source=aff_prog&utm_campaign=afts&offer_id=17';
|
92 |
$url = "http://m.snapdeal.com".$url_parts['path'].'?utm_source=aff_prog&utm_campaign=afts&offer_id=17';
|
| 85 |
}
|
93 |
}
|
| 86 |
} elseif($storeProduct['source_id'] == 4){
|
94 |
} elseif($storeId == 4){
|
| 87 |
$next = "&next=".str_replace('www','m',$storeProduct['marketPlaceUrl']);
|
95 |
$next = "&next=".str_replace('www','m',$url);
|
| 88 |
$url = $this->getAutoLoginUrl($userId,$next);
|
96 |
$url = $this->getAutoLoginUrl($userId,$next);
|
| 89 |
$url .= '?utm_source=profitmandi';
|
97 |
$url .= '?utm_source=profitmandi';
|
| 90 |
}else{
|
98 |
}else{
|
| 91 |
$url = $storeProduct['marketPlaceUrl'];
|
99 |
$url = $storeProduct['marketPlaceUrl'];
|
| 92 |
}
|
100 |
}*/
|
| 93 |
if( strpos($url, '?') === false ) {
|
101 |
if( strpos($url, '?') === false ) {
|
| 94 |
$firstChar = '?';
|
102 |
$firstChar = '?';
|
| 95 |
} else {
|
103 |
} else {
|
| 96 |
$firstChar = '&';
|
104 |
$firstChar = '&';
|
| 97 |
}
|
105 |
}
|
| 98 |
$url .= $firstChar.$store['Store']['affid_param'].'='.$store['Store']['affiliate_id'];
|
106 |
$url .= $firstChar.$store['Store']['affid_param'].'='.$store['Store']['affiliate_id'];
|
| 99 |
if(!empty($store['Store']['sub_tag_param'])){
|
107 |
if(!empty($store['Store']['sub_tag_param'])){
|
| 100 |
$url .= '&'.$store['Store']['sub_tag_param'].'='.$tag;
|
108 |
$url .= '&'.$store['Store']['sub_tag_param'].'='.$tag;
|
| 101 |
}
|
109 |
}
|
| 102 |
$extras = array('store'=>$store['Store']['name']);
|
110 |
$extras = array('store'=>$store['Store']['name']);
|
| 103 |
$data = array('user_id'=>$userId,'store_product_id'=>$storeProductId,'price'=>$storeProduct['available_price'],'tag'=>$tag,'url'=>$url,'extras'=>json_encode($extras));
|
111 |
$data = array('user_id'=>$userId,'store_product_id'=>$storeProductId,'price'=>$available_price,'tag'=>$tag,'url'=>$url,'extras'=>json_encode($extras));
|
| 104 |
$this->Click->create();
|
112 |
$this->Click->create();
|
| 105 |
if ($this->Click->save($data)) {
|
113 |
if ($this->Click->save($data)) {
|
| 106 |
$result = array('success'=>true,'message'=>__('The click has been saved.'),'type'=>'redirect','url'=>$url);
|
114 |
$result = array('success'=>true,'message'=>__('The click has been saved.'),'type'=>'redirect','url'=>$url);
|
| 107 |
} else {
|
115 |
} else {
|
| 108 |
$result = array('success'=>false,'message'=>__('The click could not be saved. Please, try again.'));
|
116 |
$result = array('success'=>false,'message'=>__('The click could not be saved. Please, try again.'));
|