Subversion Repositories SmartDukaan

Rev

Rev 15077 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
14098 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Exceptionalnlcs Controller
5
 *
6
 * @property Exceptionalnlc $Exceptionalnlc
7
 * @property PaginatorComponent $Paginator
8
 */
9
class MasterDatasController 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
	}
23
 
24
	public function admin_index() {
14539 anikendra 25
		/*$page = $this->request->query('page');
14098 anikendra 26
		if(!isset($page)){
27
			$page = 1;
28
		}
29
		$limit = Configure::read('admindashboardlimit');
30
		$params = array(
31
			'fields' => array('_id','brand','source_product_name', 'available_price', 'thumbnail','category','category_id','in_stock','marketPlaceUrl','mrp','rank','source_id','source_product_name','url'),
32
			'conditions' => array('source_id' => array('$ne' => 0)),
33
			'order' => array('_id' => -1),
34
			'limit' => $limit,
35
			'page' => $page,
36
		);
37
		$masterdata = $this->MasterData->find('all', $params);
38
		$this->loadModel('Category');
39
		$categories = $this->Category->find('list');
40
		$storemapping = Configure::read('storemapping');
14539 anikendra 41
		$this->set(compact('masterdata','categories','page','storemapping'));*/
42
		$page = $this->request->query('page');
43
		if(!isset($page)){
44
			$page = 1;
45
		}
46
		$limit = Configure::read('admindashboardlimit');
47
		$offset = ($page - 1)*$limit;
48
		$search = '';
49
		$url = $this->apihost."Catalog/searchMaster/?search=$search&limit=$limit&offset=$offset";
50
		$response = $this->make_request($url,null);
51
		$storemapping = Configure::read('storemapping');
52
		$this->set('masterdata', $response);
53
		$this->set(compact('page','search','storemapping'));
14098 anikendra 54
	}
55
 
15039 manas 56
	public function admin_show($id=null){
57
		$limit = 10;
58
		$page = 1;
59
		$params = array(
60
			'fields' => array('_id','brand','source_product_name', 'available_price', 'thumbnail','category','category_id','in_stock','marketPlaceUrl','mrp','rank','source_id','source_product_name','url'),
61
			'conditions' => array('source_id' => array('$ne' => 0)),
62
			'order' => array('_id' => -1),
63
			'limit' => $limit,
64
			'page' => $page,
65
		);
66
		$masterdata = $this->MasterData->find('all', $params);
67
		$this->set(compact('masterdata'));
68
	}
14098 anikendra 69
	public function admin_edit($id = null) {
70
		$id = (integer) $id;
71
		if (!$id && empty($this->data)) {
72
			$this->flash(__('Invalid Post', true), array('action' => 'index'));
73
		}
74
		if (!empty($this->data)) {
75
			if ($this->MasterData->save($this->data)) {
76
				$this->flash(__('The data has been saved.', true), array('action' => 'index'));
77
			} else {
78
			}
79
		}
80
		if (empty($this->data)) {
81
			$this->data = $this->MasterData->read(null, $id);
82
			debug($this->data);
83
		}
84
	}
14509 anikendra 85
 
14600 anikendra 86
	public function admin_add() {
87
		if ($this->request->is('post')) {
88
			$this->log(print_r($this->request->data,1),'masterdatas');
89
			$url = $this->apihost."masterData/addOrUpdateMaster/?addNew=1";
90
			$data = $this->request->data['MasterData'];
91
			$url = $this->generateMultiUrl($url,$data);
92
			$data['identifier'] = (string)$data['identifier'];
93
			$data['secondaryIdentifier'] = (string)$data['secondaryIdentifier'];
94
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
95
			$response = $this->make_request($url,$jsonVar);
96
			if (key($response)) {
97
				$this->Session->setFlash(current($response));
98
				return $this->redirect(array('action' => 'search'));
99
			} else {
100
				$this->Session->setFlash(current($response));
101
			}	
102
		}
103
		$sources = Configure::read('storemapping');
104
		$sources[0] = 'Other';
105
		// $this->set('sources',$sources);
106
		// $this->set('source_ids',Configure::read('storemapping'));
107
		$this->set('categories',Configure::read('Categories'));
108
		$stock_statuses = array(0=>'OOS',1=>'In Stock');
109
		$statuses = array(2=>'EOL',1=>'Active',3=>'In Process',4=>'Exclusive');
110
		$shortage_status = array(0=>'No',1=>'Yes');
15250 anikendra 111
		$buyBoxFlag = array(1 => 'Yes', 0 => 'No');
112
		$this->set(compact('stock_statuses','statuses','sources','shortage_status','buyBoxFlag'));
14600 anikendra 113
	}
114
 
115
	public function admin_addtoexisting() {
116
		if ($this->request->is('post')) {
117
			$this->log(print_r($this->request->data,1),'masterdatas');
118
			$url = $this->apihost."masterData/addOrUpdateMaster/?addToExisting=1";
119
			$data = $this->request->data['MasterData'];
120
			$url = $this->generateMultiUrl($url,$data);
121
			$data['identifier'] = (string)$data['identifier'];
122
			$data['secondaryIdentifier'] = (string)$data['secondaryIdentifier'];
123
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
124
			$response = $this->make_request($url,$jsonVar);
125
			if (key($response)) {
126
				$this->Session->setFlash(current($response));
127
				return $this->redirect(array('action' => 'search'));
128
			} else {
129
				$this->Session->setFlash(current($response));
130
			}	
131
		}
132
		$sources = Configure::read('storemapping');
133
		$sources[0] = 'Other';
134
		// $this->set('sources',$sources);
135
		// $this->set('source_ids',Configure::read('storemapping'));
136
		$this->set('categories',Configure::read('Categories'));
137
		$stock_statuses = array(0=>'OOS',1=>'In Stock');
138
		$statuses = array(2=>'EOL',1=>'Active',3=>'In Process',4=>'Exclusive');
139
		$shortage_status = array(0=>'No',1=>'Yes');
15250 anikendra 140
		$buyBoxFlag = array(1 => 'Yes', 0 => 'No');
141
		$this->set(compact('stock_statuses','statuses','sources','shortage_status','buyBoxFlag'));
14600 anikendra 142
	}
143
 
144
	public function admin_update($id) {
145
		if ($this->request->is('post')) {
146
			$this->log(print_r($this->request->data,1),'masterdatas');
147
			$url = $this->apihost."masterData/addOrUpdateMaster/?update=1";			
148
			$data = $this->request->data['MasterData'];
149
			if(isset($data['multi']) && !empty($data['multi'])){
150
				$url .= '&multi=1';
151
				unset($data['multi']);
152
			}
153
			$url = $this->generateMultiUrl($url,$data);
154
			$data['identifier'] = (string)$data['identifier'];
155
			$data['secondaryIdentifier'] = (string)$data['secondaryIdentifier'];
156
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
157
			$response = $this->make_request($url,$jsonVar);
158
			if (key($response)) {
159
				$this->Session->setFlash(current($response));
160
				return $this->redirect(array('action' => 'search'));
161
			} else {
162
				$this->Session->setFlash(current($response));
163
			}	
164
		}
165
		$url = $this->apihost."masterData/getSkuById/$id";
166
		$temp = $this->make_request($url,null);
167
		$data = json_decode($temp[0],1);
168
		$sources = Configure::read('storemapping');
169
		$sources[0] = 'Other';
170
		// $this->set('sources',$sources);
171
		// $this->set('source_ids',Configure::read('storemapping'));
172
		$this->set('categories',Configure::read('Categories'));
173
		$stock_statuses = array(0=>'OOS',1=>'In Stock');
174
		$statuses = array(2=>'EOL',1=>'Active',3=>'In Process',4=>'Exclusive');
175
		$shortage_status = array(0=>'No',1=>'Yes');
15250 anikendra 176
		$buyBoxFlag = array(1 => 'Yes', 0 => 'No');
177
		$this->set(compact('stock_statuses','statuses','sources','shortage_status','data','buyBoxFlag'));
14600 anikendra 178
	}
179
 
14509 anikendra 180
	public function admin_search(){
181
		$page = $this->request->query('page');
182
		if(!isset($page)){
183
			$page = 1;
184
		}
185
		$limit = Configure::read('admindashboardlimit');
186
		$offset = ($page - 1)*$limit;
187
		$search = urlencode($this->request->query('search'));
188
		$url = $this->apihost."Catalog/searchMaster/?search=$search&limit=$limit&offset=$offset";
189
		$response = $this->make_request($url,null);
14517 anikendra 190
		$storemapping = Configure::read('storemapping');
14509 anikendra 191
		$this->set('masterdata', $response);
14517 anikendra 192
		$this->set(compact('page','search','storemapping'));
14509 anikendra 193
	}
15077 anikendra 194
 
195
	public function admin_autoupdates(){		
196
		$page = $this->request->query('page');
197
		if(!isset($page)){
198
			$page = 1;
199
		}
200
		$limit = Configure::read('admindashboardlimit');
201
		$offset = ($page - 1)*$limit;
202
		$search = urlencode($this->request->query('search'));
203
		if(!empty($search)){
204
			$type = $this->request->query('type');
205
			$url = $this->apihost."Catalog/searchProducts/?class=Notifications&$type=$search";
206
		}else{
207
			$url = $this->apihost."Catalog/notification/?limit=$limit&offset=$offset";
208
		}		
209
		$autoupdates = $this->make_request($url,null);
210
		$this->set(compact('page','autoupdates'));	
211
	}
212
 
213
	public function admin_scheduleupdate(){				
214
		if ($this->request->is('post')) {			
215
			$data = $this->request->data['MasterData'];
216
			$this->log(print_r($data,1),'scheduleupdates');
217
			$data['startDate'] = mktime($data['startDate']['hour'],$data['startDate']['min'],0,$data['startDate']['month'],$data['startDate']['day'],$data['startDate']['year'])*1000;
218
			$data['endDate'] = mktime($data['endDate']['hour'],$data['endDate']['min'],0,$data['endDate']['month'],$data['endDate']['day'],$data['endDate']['year'])*1000;
219
			$url = $this->apihost."Catalog/notification";			
220
			$url = $this->generateMultiUrl($url,$data);
221
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
222
			$response = $this->make_request($url,$jsonVar);
223
			if (key($response)) {
224
				$this->Session->setFlash(current($response));
225
				return $this->redirect(array('action' => 'autoupdates'));
226
			} else {
227
				$this->Session->setFlash(current($response));
228
			}	
229
		}
230
	}
231
 
232
	public function admin_editscheduledupdate($id,$skuBundleId,$model,$brand,$startDate,$endDate){				
233
		if ($this->request->is('post')) {			
234
			$data = $this->request->data['MasterData'];			
235
			$this->log(print_r($data,1),'scheduleupdates');
236
			$data['startDate'] = mktime($data['startDate']['hour'],$data['startDate']['min'],0,$data['startDate']['month'],$data['startDate']['day'],$data['startDate']['year'])*1000;
237
			$data['endDate'] = mktime($data['endDate']['hour'],$data['endDate']['min'],0,$data['endDate']['month'],$data['endDate']['day'],$data['endDate']['year'])*1000;
238
			// debug($data);die;
239
			$url = $this->apihost."Catalog/updateCollection";
240
			$data1 = $data2 = $data;
241
			$data1['class'] = 'Notifications';
242
			unset($data1['endDate']);
243
			$data2['class'] = 'Notifications';
244
			unset($data2['startDate']);
245
			$jsonVar = json_encode($data1, JSON_NUMERIC_CHECK );
246
			$response = $this->make_request($url,$jsonVar);
247
			$jsonVar = json_encode($data2, JSON_NUMERIC_CHECK );
248
			$response = $this->make_request($url,$jsonVar);
249
			if (key($response)) {
250
				// $this->Session->setFlash(current($response));
251
				return $this->redirect(array('action' => 'autoupdates'));
252
			} else {
253
				$this->Session->setFlash(current($response));
254
			}	
255
		}
256
		$this->set(compact('id','skuBundleId','brand','model','startDate','endDate'));
257
	}
258
 
259
	public function admin_deletescheduledupdate($id){
260
		if ($this->remove($id,'Notifications')) {
261
			$this->Session->setFlash(__('The sku scheme deal has been deleted.'));
262
		} else {
263
			$this->Session->setFlash(__('The sku scheme could not be deleted. Please, try again.'));
264
		}
265
		return $this->redirect(array('action' => 'autoupdates'));
266
	}
14098 anikendra 267
}