Subversion Repositories SmartDukaan

Rev

Rev 14539 | Rev 15039 | 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
 
56
	public function admin_edit($id = null) {
57
		$id = (integer) $id;
58
		if (!$id && empty($this->data)) {
59
			$this->flash(__('Invalid Post', true), array('action' => 'index'));
60
		}
61
		if (!empty($this->data)) {
62
			if ($this->MasterData->save($this->data)) {
63
				$this->flash(__('The data has been saved.', true), array('action' => 'index'));
64
			} else {
65
			}
66
		}
67
		if (empty($this->data)) {
68
			$this->data = $this->MasterData->read(null, $id);
69
			debug($this->data);
70
		}
71
	}
14509 anikendra 72
 
14600 anikendra 73
	public function admin_add() {
74
		if ($this->request->is('post')) {
75
			$this->log(print_r($this->request->data,1),'masterdatas');
76
			$url = $this->apihost."masterData/addOrUpdateMaster/?addNew=1";
77
			$data = $this->request->data['MasterData'];
78
			$url = $this->generateMultiUrl($url,$data);
79
			$data['identifier'] = (string)$data['identifier'];
80
			$data['secondaryIdentifier'] = (string)$data['secondaryIdentifier'];
81
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
82
			$response = $this->make_request($url,$jsonVar);
83
			if (key($response)) {
84
				$this->Session->setFlash(current($response));
85
				return $this->redirect(array('action' => 'search'));
86
			} else {
87
				$this->Session->setFlash(current($response));
88
			}	
89
		}
90
		$sources = Configure::read('storemapping');
91
		$sources[0] = 'Other';
92
		// $this->set('sources',$sources);
93
		// $this->set('source_ids',Configure::read('storemapping'));
94
		$this->set('categories',Configure::read('Categories'));
95
		$stock_statuses = array(0=>'OOS',1=>'In Stock');
96
		$statuses = array(2=>'EOL',1=>'Active',3=>'In Process',4=>'Exclusive');
97
		$shortage_status = array(0=>'No',1=>'Yes');
98
		$this->set(compact('stock_statuses','statuses','sources','shortage_status'));
99
	}
100
 
101
	public function admin_addtoexisting() {
102
		if ($this->request->is('post')) {
103
			$this->log(print_r($this->request->data,1),'masterdatas');
104
			$url = $this->apihost."masterData/addOrUpdateMaster/?addToExisting=1";
105
			$data = $this->request->data['MasterData'];
106
			$url = $this->generateMultiUrl($url,$data);
107
			$data['identifier'] = (string)$data['identifier'];
108
			$data['secondaryIdentifier'] = (string)$data['secondaryIdentifier'];
109
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
110
			$response = $this->make_request($url,$jsonVar);
111
			if (key($response)) {
112
				$this->Session->setFlash(current($response));
113
				return $this->redirect(array('action' => 'search'));
114
			} else {
115
				$this->Session->setFlash(current($response));
116
			}	
117
		}
118
		$sources = Configure::read('storemapping');
119
		$sources[0] = 'Other';
120
		// $this->set('sources',$sources);
121
		// $this->set('source_ids',Configure::read('storemapping'));
122
		$this->set('categories',Configure::read('Categories'));
123
		$stock_statuses = array(0=>'OOS',1=>'In Stock');
124
		$statuses = array(2=>'EOL',1=>'Active',3=>'In Process',4=>'Exclusive');
125
		$shortage_status = array(0=>'No',1=>'Yes');
126
		$this->set(compact('stock_statuses','statuses','sources','shortage_status'));
127
	}
128
 
129
	public function admin_update($id) {
130
		if ($this->request->is('post')) {
131
			$this->log(print_r($this->request->data,1),'masterdatas');
132
			$url = $this->apihost."masterData/addOrUpdateMaster/?update=1";			
133
			$data = $this->request->data['MasterData'];
134
			if(isset($data['multi']) && !empty($data['multi'])){
135
				$url .= '&multi=1';
136
				unset($data['multi']);
137
			}
138
			$url = $this->generateMultiUrl($url,$data);
139
			$data['identifier'] = (string)$data['identifier'];
140
			$data['secondaryIdentifier'] = (string)$data['secondaryIdentifier'];
141
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
142
			$response = $this->make_request($url,$jsonVar);
143
			if (key($response)) {
144
				$this->Session->setFlash(current($response));
145
				return $this->redirect(array('action' => 'search'));
146
			} else {
147
				$this->Session->setFlash(current($response));
148
			}	
149
		}
150
		$url = $this->apihost."masterData/getSkuById/$id";
151
		$temp = $this->make_request($url,null);
152
		$data = json_decode($temp[0],1);
153
		$sources = Configure::read('storemapping');
154
		$sources[0] = 'Other';
155
		// $this->set('sources',$sources);
156
		// $this->set('source_ids',Configure::read('storemapping'));
157
		$this->set('categories',Configure::read('Categories'));
158
		$stock_statuses = array(0=>'OOS',1=>'In Stock');
159
		$statuses = array(2=>'EOL',1=>'Active',3=>'In Process',4=>'Exclusive');
160
		$shortage_status = array(0=>'No',1=>'Yes');
161
		$this->set(compact('stock_statuses','statuses','sources','shortage_status','data'));
162
	}
163
 
14509 anikendra 164
	public function admin_search(){
165
		$page = $this->request->query('page');
166
		if(!isset($page)){
167
			$page = 1;
168
		}
169
		$limit = Configure::read('admindashboardlimit');
170
		$offset = ($page - 1)*$limit;
171
		$search = urlencode($this->request->query('search'));
172
		$url = $this->apihost."Catalog/searchMaster/?search=$search&limit=$limit&offset=$offset";
173
		$response = $this->make_request($url,null);
14517 anikendra 174
		$storemapping = Configure::read('storemapping');
14509 anikendra 175
		$this->set('masterdata', $response);
14517 anikendra 176
		$this->set(compact('page','search','storemapping'));
14509 anikendra 177
	}
14098 anikendra 178
}