Subversion Repositories SmartDukaan

Rev

Rev 17838 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
17793 naman 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Exceptionalnlcs Controller
5
 *
6
 * @property Exceptionalnlc $Exceptionalnlc
7
 * @property PaginatorComponent $Paginator
8
 */
9
class ShippingsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
	public function beforeFilter() {
19
		parent::beforeFilter();
20
//		Configure::load('live');
21
		$this->apihost = Configure::read('pythonapihost');
22
		$this->mobileapihost = Configure::read('saholicapihost');
23
	}
24
 
25
 
26
	public function index(){
27
		$userId = $this->Auth->User('id');
28
		if ($this->request->is('post')) {
29
			$data = $this->request->data;
30
			// debug($data);
31
		}
32
		$this->layout = 'innerpages';
33
		$url = 'http://shop2020.in:8080/mobileapi/address?userId=41&isLoggedIn=true';
34
		// $url = $this->mobileapihost."address?userId=41&isLoggedIn=true";
35
		// echo $url;
36
		$response = $this->make_request($url,null);
37
		// debug($response);
38
 
39
		if(empty($response['addresses'])){
40
			$this->redirect(array('action' => 'add'));
41
		}
42
 
43
		$firstshowaddress = array();
44
		$findedaddress = array();
45
		$moreshowaddress = array();
46
		$current_address_id = -1;
47
		$defaultpin = -1;
48
		$defaultcookiepin = -1;
49
		foreach ($response['addresses'] as $key => $value) {
50
			// debug($value['']);
51
			if($value['id'] == intval($response['defaultAddress']) && $value['pin']== 201302){
52
				$defaultcookiepin = $key;
53
			}
54
			else if($value['pin']== 123456)
55
			{
56
				$current_address_id = $key;
57
				array_push($findedaddress,$key);
58
			}
59
			else if($value['id'] == intval($response['defaultAddress']))
60
			{
61
				$defaultpin = $key;
62
			}
63
			else{
64
				array_push($moreshowaddress,$key);	
65
			}
66
		}
67
 
68
		if($defaultcookiepin != -1){
69
			array_push($firstshowaddress,$defaultcookiepin);	
70
		}
71
 
72
		for($i= 0; $i<count($findedaddress);$i++)
73
		{
74
			array_push($firstshowaddress,$findedaddress[$i]);
75
		}
76
 
77
		if($defaultpin != -1){
78
			array_push($firstshowaddress,$defaultpin);	
79
		}
80
 
81
 
82
		for($i= 0; $i<count($moreshowaddress);$i++)
83
		{
84
			array_push($firstshowaddress,$moreshowaddress[$i]);
85
		}
86
 
87
		if($current_address_id == -1) 
88
		{
89
			foreach ($response['addresses'] as $key => $value) {
90
			// debug($value['']);
91
				if($value['id']== $response['defaultAddress'])
92
				{
93
					$current_address_id = $key;
94
					break;
95
				}
96
			}
97
		}
98
 
99
 
100
 
101
		debug($firstshowaddress);
102
		$this->set('address', $response);
103
		$this->set('current_address_id', $current_address_id);
104
		$this->set(compact('firstshowaddress'));
105
	}
106
 
107
	public function add() {
108
		$this->layout = 'innerpages';
109
		$pinval = 232104;
110
		setcookie('pin', $pinval, -1, '/');
111
		$nameval = "Supermans";
112
		setcookie('name', $nameval, -1, '/');
113
 
114
		if ($this->request->is('post')) {
115
			$data = $this->request->data;
116
			if($data['name'] == "")
117
			{
118
				$senddata['name'] = $_COOKIE['name'];	
119
			}
120
			else
121
			{
122
				$senddata['name'] = $data['name'];	
123
			}
124
 
125
			$senddata['line1'] = $data['line1'];
126
			$senddata['line2'] = "";
127
			$senddata['city'] = $data['city'];
128
			$senddata['state'] = $data['state'];
129
			if($data['pin'] == "")
130
			{
131
				$senddata['pin'] = $_COOKIE['pin'];	
132
			}
133
			else
134
			{
135
				$senddata['pin'] = $data['pin'];	
136
			}
137
			$senddata['phone'] = $data['phone'];
138
			$senddata['country'] = 'India';
139
			// debug($senddata);
140
			$url  = "http://shop2020.in:8080/mobileapi/address?userId=41&isLoggedIn=true&cartId=41&isPrivateDealUser=true";
141
			$response = $this->post_request($url,$senddata);
142
			// debug($response);
143
			$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
 
157
		}
158
 
159
		// debug($_COOKIE['pin']);
160
		$url = "http://dtr:8057/pincodeValidation/".$_COOKIE['pin'];
161
		$getstate =$this->make_request($url , null);
162
		$getstateval = "";
163
		if($getstate != "{}"){
164
			$getstateval =ucwords(strtolower($getstate['state']));
165
		}
166
 
167
 
168
		// debug($getstate);
169
		// debug($getstateval);
170
		// $getpin = ;
171
		$this->set(compact('getstateval'));
172
	}
173
	 public function change(){
174
	 	$this->layout = 'innerpages';
175
	 	if($this->request->is('post'))
176
	 	{
177
	 		echo "Hello";
178
	 	}
179
	 }
180
 
181
	 public function isServicable($pin){
182
	 	$this->autoRender = false;	
183
		$this->request->onlyAllow('ajax');
184
		// $url = "http://shop2020.in:8080/mobileapi/address!serviceable?pincode=".$pin;
185
		// $response = $this->make_request($url,null);
186
		if($pin == 110096)
187
		{$res = 'false';}
188
		else
189
			{$res = 'true';}
190
	 	return $res;
191
	 }
192
 
193
}