Subversion Repositories SmartDukaan

Rev

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

Rev 17793 Rev 17838
Line 15... Line 15...
15
 */
15
 */
16
	public $components = array('Paginator');
16
	public $components = array('Paginator');
17
 
17
 
18
	public function beforeFilter() {
18
	public function beforeFilter() {
19
		parent::beforeFilter();
19
		parent::beforeFilter();
20
//		Configure::load('live');
-
 
21
		$this->apihost = Configure::read('pythonapihost');
20
		$this->apihost = Configure::read('pythonapihost');
22
		$this->mobileapihost = Configure::read('saholicapihost');
21
		$this->mobileapihost = Configure::read('saholicapihost');
-
 
22
		$this->Auth->allow('isServicable');
23
	}
23
	}
24
	
24
	
25
 
25
 
26
	public function index(){
26
	public function index(){
27
		$userId = $this->Auth->User('id');
27
		$userId = $this->Auth->User('id');
-
 
28
		$dataGiven = json_decode($this->request->data['cart_details']);
28
		if ($this->request->is('post')) {
29
		if ($this->request->is('post')) {
29
			$data = $this->request->data;
30
			$data = $this->request->data;
30
			// debug($data);
-
 
31
		}
31
		}
-
 
32
		$totalPayable = intval($dataGiven->totalCartValue) + intval($dataGiven->shippingCharges);
32
		$this->layout = 'innerpages';
33
		$this->layout = 'innerpages';
33
		$url = 'http://shop2020.in:8080/mobileapi/address?userId=41&isLoggedIn=true';
34
		$suserId = base64_decode($_COOKIE['s_id']);
34
		// $url = $this->mobileapihost."address?userId=41&isLoggedIn=true";
35
		$url = Configure::read('saholicapihost').'address?isLoggedIn=true&privateDealUser=true&userId='.$suserId;
35
		// echo $url;
-
 
36
		$response = $this->make_request($url,null);
36
		$response = $this->make_request($url,null);
37
		// debug($response);
37
		//debug($response);
38
		
-
 
39
		if(empty($response['addresses'])){
38
		if(empty($response['addresses'])){
40
			$this->redirect(array('action' => 'add'));
39
			$this->redirect(array('action' => 'add'));
41
		}
40
		}
42
 
41
 
43
		$firstshowaddress = array();
42
		$firstshowaddress = array();
-
 
43
		
-
 
44
		$pincode = base64_decode($_COOKIE['s_pincode']);
-
 
45
		$defaultaddressid = $response['defaultAddress'];
-
 
46
		if(!empty($defaultaddressid)){
-
 
47
			$defaultaddressid = intval($defaultaddressid);
-
 
48
		}else{
-
 
49
			$defaultaddressid = -1;
-
 
50
		}
-
 
51
		
44
		$findedaddress = array();
52
		$defaultAddress = array();
45
		$moreshowaddress = array();
53
		$similarAddress = array();
46
		$current_address_id = -1;
54
		$otherAddress = array();
47
		$defaultpin = -1;
55
		$defaultPinAddress = array();
48
		$defaultcookiepin = -1;
56
		$defaultAddressFound = false;
-
 
57
		
49
		foreach ($response['addresses'] as $key => $value) {
58
		foreach ($response['addresses'] as $key => $value) {
50
			// debug($value['']);
-
 
51
			if($value['id'] == intval($response['defaultAddress']) && $value['pin']== 201302){
59
			if($defaultaddressid>-1 && $value['id']==$defaultaddressid && $value['pin']== $pincode){
-
 
60
				array_push($defaultAddress, $value);
52
				$defaultcookiepin = $key;
61
				$defaultAddressFound = true;
53
			}
62
			}
54
			else if($value['pin']== 123456)
63
			else if($value['pin']== $pincode){
55
			{
-
 
56
				$current_address_id = $key;
-
 
57
				array_push($findedaddress,$key);
64
				array_push($similarAddress, $value);
58
			}
65
			}
59
			else if($value['id'] == intval($response['defaultAddress']))
66
			else if($value['id'] == $defaultaddressid)
60
			{
67
			{
61
				$defaultpin = $key;
68
				array_push($defaultPinAddress, $value);
62
			}
69
			}	
63
			else{
70
			else{
64
				array_push($moreshowaddress,$key);	
71
				array_push($otherAddress, $value);
65
			}
72
			}
66
		}
73
		}
67
 
-
 
68
		if($defaultcookiepin != -1){
-
 
69
			array_push($firstshowaddress,$defaultcookiepin);	
-
 
70
		}
-
 
71
		
-
 
72
		for($i= 0; $i<count($findedaddress);$i++)
74
		for($i= 0; $i<count($defaultAddress);$i++)
73
		{
75
		{
74
			array_push($firstshowaddress,$findedaddress[$i]);
76
			array_push($firstshowaddress,$defaultAddress[$i]);
75
		}
77
		}
-
 
78
		for($i= 0; $i<count($similarAddress);$i++)
76
 
79
		{
77
		if($defaultpin != -1){
-
 
78
			array_push($firstshowaddress,$defaultpin);	
80
			array_push($firstshowaddress,$similarAddress[$i]);
79
		}
81
		}
80
		
-
 
81
 
-
 
82
		for($i= 0; $i<count($moreshowaddress);$i++)
82
		for($i= 0; $i<count($defaultPinAddress);$i++)
83
		{
83
		{
84
			array_push($firstshowaddress,$moreshowaddress[$i]);
84
			array_push($firstshowaddress,$defaultPinAddress[$i]);
85
		}
85
		}
86
 
-
 
87
		if($current_address_id == -1) 
86
		for($i= 0; $i<count($otherAddress);$i++)
88
		{
87
		{
89
			foreach ($response['addresses'] as $key => $value) {
-
 
90
			// debug($value['']);
-
 
91
				if($value['id']== $response['defaultAddress'])
88
			array_push($firstshowaddress,$otherAddress[$i]);
92
				{
-
 
93
					$current_address_id = $key;
-
 
94
					break;
-
 
95
				}
-
 
96
			}
-
 
97
		}
89
		}
98
 
-
 
99
		
90
		
100
 
-
 
101
		debug($firstshowaddress);
-
 
102
		$this->set('address', $response);
-
 
103
		$this->set('current_address_id', $current_address_id);
91
		$this->set(compact('firstshowaddress','defaultAddressFound', 'defaultaddressid', 'totalPayable'));
104
		$this->set(compact('firstshowaddress'));
-
 
105
	}
92
	}
106
 
93
 
107
	public function add() {
94
	public function add() {
108
		$this->layout = 'innerpages';
95
		$this->layout = 'innerpages';
109
		$pinval = 232104;
96
		$pinval = 232104;
Line 137... Line 124...
137
			$senddata['phone'] = $data['phone'];
124
			$senddata['phone'] = $data['phone'];
138
			$senddata['country'] = 'India';
125
			$senddata['country'] = 'India';
139
			// debug($senddata);
126
			// debug($senddata);
140
			$url  = "http://shop2020.in:8080/mobileapi/address?userId=41&isLoggedIn=true&cartId=41&isPrivateDealUser=true";
127
			$url  = "http://shop2020.in:8080/mobileapi/address?userId=41&isLoggedIn=true&cartId=41&isPrivateDealUser=true";
141
			$response = $this->post_request($url,$senddata);
128
			$response = $this->post_request($url,$senddata);
142
			// debug($response);
-
 
143
			$this->redirect(array('action' => 'index'));
129
			$this->redirect(array('action' => 'index'));
144
			// $data = $this->request->data['Objects'];
-
 
145
			// $data['template_id'] = 1;
-
 
146
			// // debug(json_encode($data,JSON_NUMERIC_CHECK));
-
 
147
			// $url = $this->apihost."addDealObject";
-
 
148
			// $response = $this->make_request($url,json_encode($data,JSON_NUMERIC_CHECK));
-
 
149
			// // debug($response);
-
 
150
			// if (key($response)) {
-
 
151
			// 	$this->Session->setFlash(current($response));
-
 
152
			// 	return $this->redirect(array('action' => 'index'));
-
 
153
			// } else {
-
 
154
			// 	$this->Session->setFlash(current($response));
-
 
155
			// }
-
 
156
			
130
			
157
		}
131
		}
158
		
132
		
159
		// debug($_COOKIE['pin']);
133
		// debug($_COOKIE['pin']);
160
		$url = "http://dtr:8057/pincodeValidation/".$_COOKIE['pin'];
134
		$url = "http://dtr:8057/pincodeValidation/".$_COOKIE['pin'];
161
		$getstate =$this->make_request($url , null);
135
		$getstate =$this->make_request($url , null);
162
		$getstateval = "";
136
		$getstateval = "";
163
		if($getstate != "{}"){
137
		if($getstate != "{}"){
164
			$getstateval =ucwords(strtolower($getstate['state']));
138
			$getstateval =ucwords(strtolower($getstate['state']));
165
		}
139
		}
166
 
-
 
167
		
-
 
168
		// debug($getstate);
-
 
169
		// debug($getstateval);
-
 
170
		// $getpin = ;
-
 
171
		$this->set(compact('getstateval'));
140
		$this->set(compact('getstateval'));
172
	}
141
	}
173
	 public function change(){
142
	 public function change(){
174
	 	$this->layout = 'innerpages';
143
	 	$this->layout = 'innerpages';
175
	 	if($this->request->is('post'))
144
	 	if($this->request->is('post'))
Line 181... Line 150...
181
	 public function isServicable($pin){
150
	 public function isServicable($pin){
182
	 	$this->autoRender = false;	
151
	 	$this->autoRender = false;	
183
		$this->request->onlyAllow('ajax');
152
		$this->request->onlyAllow('ajax');
184
		// $url = "http://shop2020.in:8080/mobileapi/address!serviceable?pincode=".$pin;
153
		// $url = "http://shop2020.in:8080/mobileapi/address!serviceable?pincode=".$pin;
185
		// $response = $this->make_request($url,null);
154
		// $response = $this->make_request($url,null);
186
		if($pin == 110096)
155
		if($pin == 110019)
187
		{$res = 'false';}
156
		{$res = 'false';}
188
		else
157
		else
189
			{$res = 'true';}
158
			{$res = 'true';}
190
	 	return $res;
159
	 	return $res;
191
	 }
160
	 }