Subversion Repositories SmartDukaan

Rev

Rev 14600 | 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');
111
		$this->set(compact('stock_statuses','statuses','sources','shortage_status'));
112
	}
113
 
114
	public function admin_addtoexisting() {
115
		if ($this->request->is('post')) {
116
			$this->log(print_r($this->request->data,1),'masterdatas');
117
			$url = $this->apihost."masterData/addOrUpdateMaster/?addToExisting=1";
118
			$data = $this->request->data['MasterData'];
119
			$url = $this->generateMultiUrl($url,$data);
120
			$data['identifier'] = (string)$data['identifier'];
121
			$data['secondaryIdentifier'] = (string)$data['secondaryIdentifier'];
122
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
123
			$response = $this->make_request($url,$jsonVar);
124
			if (key($response)) {
125
				$this->Session->setFlash(current($response));
126
				return $this->redirect(array('action' => 'search'));
127
			} else {
128
				$this->Session->setFlash(current($response));
129
			}	
130
		}
131
		$sources = Configure::read('storemapping');
132
		$sources[0] = 'Other';
133
		// $this->set('sources',$sources);
134
		// $this->set('source_ids',Configure::read('storemapping'));
135
		$this->set('categories',Configure::read('Categories'));
136
		$stock_statuses = array(0=>'OOS',1=>'In Stock');
137
		$statuses = array(2=>'EOL',1=>'Active',3=>'In Process',4=>'Exclusive');
138
		$shortage_status = array(0=>'No',1=>'Yes');
139
		$this->set(compact('stock_statuses','statuses','sources','shortage_status'));
140
	}
141
 
142
	public function admin_update($id) {
143
		if ($this->request->is('post')) {
144
			$this->log(print_r($this->request->data,1),'masterdatas');
145
			$url = $this->apihost."masterData/addOrUpdateMaster/?update=1";			
146
			$data = $this->request->data['MasterData'];
147
			if(isset($data['multi']) && !empty($data['multi'])){
148
				$url .= '&multi=1';
149
				unset($data['multi']);
150
			}
151
			$url = $this->generateMultiUrl($url,$data);
152
			$data['identifier'] = (string)$data['identifier'];
153
			$data['secondaryIdentifier'] = (string)$data['secondaryIdentifier'];
154
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
155
			$response = $this->make_request($url,$jsonVar);
156
			if (key($response)) {
157
				$this->Session->setFlash(current($response));
158
				return $this->redirect(array('action' => 'search'));
159
			} else {
160
				$this->Session->setFlash(current($response));
161
			}	
162
		}
163
		$url = $this->apihost."masterData/getSkuById/$id";
164
		$temp = $this->make_request($url,null);
165
		$data = json_decode($temp[0],1);
166
		$sources = Configure::read('storemapping');
167
		$sources[0] = 'Other';
168
		// $this->set('sources',$sources);
169
		// $this->set('source_ids',Configure::read('storemapping'));
170
		$this->set('categories',Configure::read('Categories'));
171
		$stock_statuses = array(0=>'OOS',1=>'In Stock');
172
		$statuses = array(2=>'EOL',1=>'Active',3=>'In Process',4=>'Exclusive');
173
		$shortage_status = array(0=>'No',1=>'Yes');
174
		$this->set(compact('stock_statuses','statuses','sources','shortage_status','data'));
175
	}
176
 
14509 anikendra 177
	public function admin_search(){
178
		$page = $this->request->query('page');
179
		if(!isset($page)){
180
			$page = 1;
181
		}
182
		$limit = Configure::read('admindashboardlimit');
183
		$offset = ($page - 1)*$limit;
184
		$search = urlencode($this->request->query('search'));
185
		$url = $this->apihost."Catalog/searchMaster/?search=$search&limit=$limit&offset=$offset";
186
		$response = $this->make_request($url,null);
14517 anikendra 187
		$storemapping = Configure::read('storemapping');
14509 anikendra 188
		$this->set('masterdata', $response);
14517 anikendra 189
		$this->set(compact('page','search','storemapping'));
14509 anikendra 190
	}
14098 anikendra 191
}