Subversion Repositories SmartDukaan

Rev

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

Rev 13762 Rev 13814
Line 83... Line 83...
83
/**
83
/**
84
 * add method
84
 * add method
85
 *
85
 *
86
 * @return void
86
 * @return void
87
 */
87
 */
-
 
88
 
-
 
89
	public function postOrders($order=null) {
-
 
90
		Configure::load('live');
-
 
91
		$apihost = Configure::read('pythonapihost');
-
 
92
		$url = $apihost."storeorder";
-
 
93
		if(!empty($order)) {
-
 
94
			$params = array('sourceId'=>$order['Order']['store_id'],'orderId'=>$order['Order']['id'],'subTagId'=>$order['Order']['sub_tag'],'userId'=>$order['Order']['user_id'],'rawHtml'=>$order['Order']['rawhtml'],'orderSuccessUrl'=>$order['Order']['order_url']);
-
 
95
			$jsonVar = json_encode($params);
-
 
96
			return $this->make_request($url,$jsonVar);
-
 
97
		}else{
-
 
98
			$result = array('success'=>false,'message'=>'Empty order array');
-
 
99
			return $result;
-
 
100
		}
-
 
101
	}
-
 
102
 
88
	public function add() {
103
	public function add() {
89
		$this->log(print_r($this->request->data,1),'orders');
104
		$this->log(print_r($this->request->data,1),'orders');
90
		if ($this->request->is('post')) {
105
		if ($this->request->is('post')) {
91
			$this->Order->create();
106
			$this->Order->create();
92
			if(!empty($this->request->data['sub_tag'])){
107
			if(!empty($this->request->data['sub_tag'])){
93
				$this->request->data['status'] = 'mapped';
108
				$this->request->data['status'] = 'mapped';
94
			}
109
			}
95
			if ($this->Order->save($this->request->data)) {
110
			if ($this->Order->save($this->request->data)) {
-
 
111
				//$this->loadModel('PythonApi');
-
 
112
				$order = $this->Order->find('first',array('conditions'=>array('id'=>$this->Order->getLastInsertID()),'recursive'=>-1));
-
 
113
				$response = $this->postOrders($order);
-
 
114
				$this->log(print_r($response,1),'orders');
-
 
115
				if(!empty($response) && $response['result']) {
-
 
116
					if($response['result'] == 'HTML_REQUIRED') {
-
 
117
						$this->loadModel('Rawhtml');
-
 
118
						$data = array('order_id' => $order['Order']['id'],'url' => $response['url'], 'status' => 'new');
-
 
119
						$this->Rawhtml->create();
-
 
120
						$this->Rawhtml->save($data); 
-
 
121
						$result =array('success'=>true,'message'=>__('HTML_REQUIRED'),'url' => $response['url']);
-
 
122
						$sql = "UPDATE orders SET status = 'deleted' WHERE id = ".$order['Order']['id'];
-
 
123
					} elseif($response['result'] == 'IGNORED') {
-
 
124
						$result =array('success'=>true,'message'=>__('IGNORED'));
-
 
125
						$sql = "UPDATE orders SET status = 'deleted' WHERE id = ".$order['Order']['id'];
-
 
126
					} elseif($response['result'] == 'PARSE_ERROR') {
96
				$result =array('success'=>true,'message'=>__('The order has been saved.'));
127
						$result =array('success'=>true,'message'=>__('PARSE_ERROR'));
-
 
128
						$sql = "UPDATE orders SET status = 'deleted' WHERE id = ".$order['Order']['id'];
-
 
129
					} else {
-
 
130
						$result =array('success'=>true,'message'=>__('PROCESSED'));
-
 
131
						$sql = "UPDATE orders SET status = 'processed' WHERE id = ".$order['Order']['id'];
-
 
132
					}
-
 
133
					$this->Order->query($sql);
-
 
134
				}
-
 
135
				//$result = array('success'=>true,'message'=>__('HTML_REQUIRED'),'url'=>'https://www.amazon.in/gp/css/summary/edit.html?orderID=404-7369214-6566739');
97
/*
136
/*
98
				$options = array('conditions'=>array('status'=>'mapped'),'recursive'=>-1);
137
				$options = array('conditions'=>array('status'=>'mapped'),'recursive'=>-1);
99
				$order = $this->Order->find('first',$options);
138
				$order = $this->Order->find('first',$options);
100
				if(!empty($orders)) {
139
				if(!empty($orders)) {
101
					foreach($orders AS $order) {
140
					foreach($orders AS $order) {