| 15761 |
manas |
1 |
<?php
|
|
|
2 |
App::uses('AppController', 'Controller');
|
|
|
3 |
/**
|
|
|
4 |
* UserAddresses Controller
|
|
|
5 |
*
|
|
|
6 |
* @property UserAddress $UserAddress
|
|
|
7 |
* @property PaginatorComponent $Paginator
|
|
|
8 |
*/
|
|
|
9 |
class UserAddressesController extends AppController {
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* Components
|
|
|
13 |
*
|
|
|
14 |
* @var array
|
|
|
15 |
*/
|
|
|
16 |
public $components = array('Paginator');
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* index method
|
|
|
20 |
*
|
|
|
21 |
* @return void
|
|
|
22 |
*/
|
|
|
23 |
public function index() {
|
|
|
24 |
$this->UserAddress->recursive = 0;
|
|
|
25 |
$this->set('userAddresses', $this->Paginator->paginate());
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* view method
|
|
|
30 |
*
|
|
|
31 |
* @throws NotFoundException
|
|
|
32 |
* @param string $id
|
|
|
33 |
* @return void
|
|
|
34 |
*/
|
|
|
35 |
public function view($id = null) {
|
|
|
36 |
if (!$this->UserAddress->exists($id)) {
|
|
|
37 |
throw new NotFoundException(__('Invalid user address'));
|
|
|
38 |
}
|
|
|
39 |
$options = array('conditions' => array('UserAddress.' . $this->UserAddress->primaryKey => $id));
|
|
|
40 |
$this->set('userAddress', $this->UserAddress->find('first', $options));
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* add method
|
|
|
45 |
*
|
|
|
46 |
* @return void
|
|
|
47 |
*/
|
|
|
48 |
public function add() {
|
|
|
49 |
if ($this->request->is('post')) {
|
|
|
50 |
$this->UserAddress->create();
|
|
|
51 |
if ($this->UserAddress->save($this->request->data)) {
|
|
|
52 |
$this->Session->setFlash(__('The user address has been saved.'));
|
|
|
53 |
return $this->redirect(array('action' => 'index'));
|
|
|
54 |
} else {
|
|
|
55 |
$this->Session->setFlash(__('The user address could not be saved. Please, try again.'));
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* edit method
|
|
|
62 |
*
|
|
|
63 |
* @throws NotFoundException
|
|
|
64 |
* @param string $id
|
|
|
65 |
* @return void
|
|
|
66 |
*/
|
|
|
67 |
public function edit($id = null) {
|
|
|
68 |
if (!$this->UserAddress->exists($id)) {
|
|
|
69 |
throw new NotFoundException(__('Invalid user address'));
|
|
|
70 |
}
|
|
|
71 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
72 |
if ($this->UserAddress->save($this->request->data)) {
|
|
|
73 |
$this->Session->setFlash(__('The user address has been saved.'));
|
|
|
74 |
return $this->redirect(array('action' => 'index'));
|
|
|
75 |
} else {
|
|
|
76 |
$this->Session->setFlash(__('The user address could not be saved. Please, try again.'));
|
|
|
77 |
}
|
|
|
78 |
} else {
|
|
|
79 |
$options = array('conditions' => array('UserAddress.' . $this->UserAddress->primaryKey => $id));
|
|
|
80 |
$this->request->data = $this->UserAddress->find('first', $options);
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
/**
|
|
|
85 |
* delete method
|
|
|
86 |
*
|
|
|
87 |
* @throws NotFoundException
|
|
|
88 |
* @param string $id
|
|
|
89 |
* @return void
|
|
|
90 |
*/
|
|
|
91 |
public function delete($id = null) {
|
|
|
92 |
$this->UserAddress->id = $id;
|
|
|
93 |
if (!$this->UserAddress->exists()) {
|
|
|
94 |
throw new NotFoundException(__('Invalid user address'));
|
|
|
95 |
}
|
|
|
96 |
$this->request->onlyAllow('post', 'delete');
|
|
|
97 |
if ($this->UserAddress->delete()) {
|
|
|
98 |
$this->Session->setFlash(__('The user address has been deleted.'));
|
|
|
99 |
} else {
|
|
|
100 |
$this->Session->setFlash(__('The user address could not be deleted. Please, try again.'));
|
|
|
101 |
}
|
|
|
102 |
return $this->redirect(array('action' => 'index'));
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
/**
|
|
|
106 |
* admin_index method
|
|
|
107 |
*
|
|
|
108 |
* @return void
|
|
|
109 |
*/
|
|
|
110 |
public function admin_index() {
|
|
|
111 |
$this->UserAddress->recursive = 0;
|
|
|
112 |
$this->set('userAddresses', $this->Paginator->paginate());
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
/**
|
|
|
116 |
* admin_view method
|
|
|
117 |
*
|
|
|
118 |
* @throws NotFoundException
|
|
|
119 |
* @param string $id
|
|
|
120 |
* @return void
|
|
|
121 |
*/
|
|
|
122 |
public function admin_view($id = null) {
|
|
|
123 |
if (!$this->UserAddress->exists($id)) {
|
|
|
124 |
throw new NotFoundException(__('Invalid user address'));
|
|
|
125 |
}
|
|
|
126 |
$options = array('conditions' => array('UserAddress.' . $this->UserAddress->primaryKey => $id));
|
|
|
127 |
$this->set('userAddress', $this->UserAddress->find('first', $options));
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
/**
|
|
|
131 |
* admin_add method
|
|
|
132 |
*
|
|
|
133 |
* @return void
|
|
|
134 |
*/
|
|
|
135 |
public function admin_add() {
|
|
|
136 |
if ($this->request->is('post')) {
|
|
|
137 |
$this->UserAddress->create();
|
|
|
138 |
if ($this->UserAddress->save($this->request->data)) {
|
|
|
139 |
$this->Session->setFlash(__('The user address has been saved.'));
|
|
|
140 |
return $this->redirect(array('action' => 'index'));
|
|
|
141 |
} else {
|
|
|
142 |
$this->Session->setFlash(__('The user address could not be saved. Please, try again.'));
|
|
|
143 |
}
|
|
|
144 |
}
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
/**
|
|
|
148 |
* admin_edit method
|
|
|
149 |
*
|
|
|
150 |
* @throws NotFoundException
|
|
|
151 |
* @param string $id
|
|
|
152 |
* @return void
|
|
|
153 |
*/
|
|
|
154 |
public function admin_edit($id = null) {
|
|
|
155 |
if (!$this->UserAddress->exists($id)) {
|
|
|
156 |
throw new NotFoundException(__('Invalid user address'));
|
|
|
157 |
}
|
|
|
158 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
159 |
if ($this->UserAddress->save($this->request->data)) {
|
|
|
160 |
$this->Session->setFlash(__('The user address has been saved.'));
|
|
|
161 |
return $this->redirect(array('action' => 'index'));
|
|
|
162 |
} else {
|
|
|
163 |
$this->Session->setFlash(__('The user address could not be saved. Please, try again.'));
|
|
|
164 |
}
|
|
|
165 |
} else {
|
|
|
166 |
$options = array('conditions' => array('UserAddress.' . $this->UserAddress->primaryKey => $id));
|
|
|
167 |
$this->request->data = $this->UserAddress->find('first', $options);
|
|
|
168 |
}
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
/**
|
|
|
172 |
* admin_delete method
|
|
|
173 |
*
|
|
|
174 |
* @throws NotFoundException
|
|
|
175 |
* @param string $id
|
|
|
176 |
* @return void
|
|
|
177 |
*/
|
|
|
178 |
public function admin_delete($id = null) {
|
|
|
179 |
$this->UserAddress->id = $id;
|
|
|
180 |
if (!$this->UserAddress->exists()) {
|
|
|
181 |
throw new NotFoundException(__('Invalid user address'));
|
|
|
182 |
}
|
|
|
183 |
$this->request->onlyAllow('post', 'delete');
|
|
|
184 |
if ($this->UserAddress->delete()) {
|
|
|
185 |
$this->Session->setFlash(__('The user address has been deleted.'));
|
|
|
186 |
} else {
|
|
|
187 |
$this->Session->setFlash(__('The user address could not be deleted. Please, try again.'));
|
|
|
188 |
}
|
|
|
189 |
return $this->redirect(array('action' => 'index'));
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
public function admin_by($userId = null) {
|
|
|
193 |
|
|
|
194 |
$postOfficeQuery="select pincode,state from postoffices group by pincode";
|
|
|
195 |
$postOfficeResult=$this->UserAddress->query($postOfficeQuery);
|
|
|
196 |
$postOffice=array();
|
|
|
197 |
foreach($postOfficeResult as $value){
|
|
|
198 |
$postOffice[$value['postoffices']['pincode']]=$value['postoffices']['state'];
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
$retailerAddress="SELECT r.title,r.address, r.city,r.state,r.pin from retaileraddresses r join retailerlinks rl on r.retailer_id=rl.retailer_id where rl.user_id=$userId";
|
|
|
202 |
$new_address=$this->UserAddress->query($retailerAddress);
|
|
|
203 |
|
|
|
204 |
$retailerAddress="SELECT title,address,city,state,pin from retailers r join retailerlinks rl on r.id=rl.retailer_id where rl.user_id=$userId";
|
|
|
205 |
$retailer_address=$this->UserAddress->query($retailerAddress);
|
|
|
206 |
|
| 17656 |
amit.gupta |
207 |
$retailerAddress="SELECT ua.store_name,ua.address,ua.city,ua.state,ua.pincode from user_addresses ua join users u on ua.user_id=u.id where ua.user_id=$userId";
|
| 15761 |
manas |
208 |
$user_update_address=$this->UserAddress->query($retailerAddress);
|
|
|
209 |
|
|
|
210 |
$retailerAddress="SELECT concat(' ', address_line_1,address_line_2) as address,city,state,pincode from users where id=$userId";
|
|
|
211 |
$user_address=$this->UserAddress->query($retailerAddress);
|
|
|
212 |
if($user_address[0]['users']['state']==null){
|
|
|
213 |
if($user_address[0]['users']['pincode']==null){
|
|
|
214 |
|
|
|
215 |
}else{
|
|
|
216 |
$user_address[0]['users']['state']=$postOffice[$user_address[0]['users']['pincode']];
|
|
|
217 |
}
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
if(empty($new_address)){
|
|
|
221 |
|
|
|
222 |
}else{
|
|
|
223 |
if(empty($new_address[0]['r']['state'])){
|
|
|
224 |
$new_address[0]['r']['state']=$postOffice[$new_address[0]['r']['pin']];
|
|
|
225 |
}
|
|
|
226 |
}
|
|
|
227 |
if(empty($retailer_address)){
|
|
|
228 |
|
|
|
229 |
}else{
|
|
|
230 |
if(empty($retailer_address[0]['r']['state'])){
|
|
|
231 |
$retailer_address[0]['r']['state']=$postOffice[$retailer_address[0]['r']['pin']];
|
|
|
232 |
}
|
|
|
233 |
}
|
|
|
234 |
if(empty($user_update_address)){
|
|
|
235 |
|
|
|
236 |
}else{
|
|
|
237 |
if(empty($user_update_address[0]['ua']['state'])){
|
|
|
238 |
$user_update_address[0]['ua']['state']=$postOffice[$user_update_address[0]['ua']['pincode']];
|
|
|
239 |
}
|
|
|
240 |
}
|
|
|
241 |
$this->set('newaddress', $new_address);
|
|
|
242 |
$this->set('retaileraddress', $retailer_address);
|
|
|
243 |
$this->set('userupdateaddress', $user_update_address);
|
|
|
244 |
$this->set('useraddress', $user_address);
|
|
|
245 |
}
|
|
|
246 |
}
|