Subversion Repositories SmartDukaan

Rev

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

Rev 14224 Rev 14315
Line 151... Line 151...
151
	}
151
	}
152
 
152
 
153
	public function add() {
153
	public function add() {
154
		$this->log(print_r($this->request->data,1),'orders');
154
		$this->log(print_r($this->request->data,1),'orders');
155
		if ($this->request->is('post')) {
155
		if ($this->request->is('post')) {
156
			$this->Order->create();
-
 
157
			if(!empty($this->request->data['sub_tag'])){
156
			if(empty($this->request->data['id'])) {
158
				$this->request->data['status'] = 'mapped';
157
				$this->Order->create();
159
			}
158
			}
160
			if ($this->Order->save($this->request->data)) {
159
			if ($this->Order->save($this->request->data)) {
161
				//$this->loadModel('PythonApi');
160
				//$this->loadModel('PythonApi');	
-
 
161
				if(empty($this->request->data['id'])) {
-
 
162
					$id = $this->Order->getLastInsertID();
-
 
163
				}else{
-
 
164
					$id = $this->request->data['id'];
-
 
165
				}
162
				$order = $this->Order->find('first',array('conditions'=>array('id'=>$this->Order->getLastInsertID()),'recursive'=>-1));
166
				$order = $this->Order->find('first',array('conditions'=>array('id'=>$id),'recursive'=>-1));
163
				$response = $this->postOrders($order);
167
				$response = $this->postOrders($order);
164
				$this->log(print_r($response,1),'orders');
168
				$this->log(print_r($response,1),'orders');
165
				if(!empty($response) && $response['result']) {
169
				if(!empty($response) && $response['result']) {
-
 
170
					//if($response['result'] == 'HTML_REQUIRED' || $response['result'] == 'requireHtml') {
166
					if($response['result'] == 'HTML_REQUIRED') {
171
					if($response['htmlRequired'] == 1) {
167
						$this->loadModel('Rawhtml');
172
						$this->loadModel('Rawhtml');
168
						$data = array('order_id' => $order['Order']['id'],'url' => $response['url'], 'status' => 'new');
173
						$data = array('order_id' => $order['Order']['id'],'url' => $response['url'], 'status' => 'new');
169
						$this->Rawhtml->create();
174
						$this->Rawhtml->create();
170
						$this->Rawhtml->save($data); 
175
						$this->Rawhtml->save($data); 
171
						$result =array('success'=>true,'message'=>__('HTML_REQUIRED'),'url' => $response['url']);
176
						//$result =array('success'=>true,'message'=>__('requireHtml'),'url' => $response['url'],'orderId' => $response['orderId']);
-
 
177
						$result =  $response;
172
						$sql = "UPDATE orders SET status = 'deleted' WHERE id = ".$order['Order']['id'];
178
						$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
173
					} elseif($response['result'] == 'IGNORED') {
179
					}/* elseif($response['result'] == 'IGNORED') {
174
						$result =array('success'=>true,'message'=>__('IGNORED'));
180
						$result =array('success'=>true,'message'=>__('IGNORED'));
175
						$sql = "UPDATE orders SET status = 'deleted' WHERE id = ".$order['Order']['id'];
181
						$sql = "UPDATE orders SET status = 'deleted' WHERE id = ".$order['Order']['id'];
176
					} elseif($response['result'] == 'PARSE_ERROR') {
182
					} elseif($response['result'] == 'PARSE_ERROR') {
177
						$result =array('success'=>true,'message'=>__('PARSE_ERROR'));
183
						$result =array('success'=>true,'message'=>__('PARSE_ERROR'));
178
						$sql = "UPDATE orders SET status = 'deleted' WHERE id = ".$order['Order']['id'];
184
						$sql = "UPDATE orders SET status = 'deleted' WHERE id = ".$order['Order']['id'];
-
 
185
					} */
179
					} else {
186
					else {
180
						$result =array('success'=>true,'message'=>__('PROCESSED'));
187
						$result =array('success'=>true,'message'=> $response['result']);
181
						$sql = "UPDATE orders SET status = 'processed' WHERE id = ".$order['Order']['id'];
188
						$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
182
					}
189
					}
183
					$this->Order->query($sql);
190
					$this->Order->query($sql);
184
				}
191
				}
185
				//$result = array('success'=>true,'message'=>__('HTML_REQUIRED'),'url'=>'https://www.amazon.in/gp/css/summary/edit.html?orderID=404-7369214-6566739');
192
				//$result = array('success'=>true,'message'=>__('HTML_REQUIRED'),'url'=>'https://www.amazon.in/gp/css/summary/edit.html?orderID=404-7369214-6566739');
186
/*
193
/*
Line 195... Line 202...
195
						}
202
						}
196
					}
203
					}
197
				}
204
				}
198
*/
205
*/
199
			} else {
206
			} else {
-
 
207
				$this->log(print_r($this->Order->validationErrors,1),'orders');
200
				$result = array('success'=>false,'message'=>__('The order could not be saved. Please, try again.'));
208
				$result = array('success'=>false,'message'=>__('The order could not be saved. Please, try again.'));
201
			}
209
			}
202
			$this->response->type('json');
210
			$this->response->type('json');
203
			$this->layout = 'ajax';
211
			$this->layout = 'ajax';
204
			$this->set(array(
212
			$this->set(array(
205
			    'result' => $result,
213
			    'result' => $response,
206
			    // 'callback' => $callback,
214
			    // 'callback' => $callback,
207
			    '_serialize' => array('result')
215
			    '_serialize' => array('result')
208
			));
216
			));
209
			$this->render('/Elements/json');		
217
			$this->render('/Elements/json');		
210
		}			
218
		}