Rev 14539 | Rev 15039 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?phpApp::uses('AppController', 'Controller');/*** Exceptionalnlcs Controller** @property Exceptionalnlc $Exceptionalnlc* @property PaginatorComponent $Paginator*/class MasterDatasController extends AppController {/*** Components** @var array*/public $components = array('Paginator');public function beforeFilter() {parent::beforeFilter();// Configure::load('live');$this->apihost = Configure::read('pythonapihost');}public function admin_index() {/*$page = $this->request->query('page');if(!isset($page)){$page = 1;}$limit = Configure::read('admindashboardlimit');$params = array('fields' => array('_id','brand','source_product_name', 'available_price', 'thumbnail','category','category_id','in_stock','marketPlaceUrl','mrp','rank','source_id','source_product_name','url'),'conditions' => array('source_id' => array('$ne' => 0)),'order' => array('_id' => -1),'limit' => $limit,'page' => $page,);$masterdata = $this->MasterData->find('all', $params);$this->loadModel('Category');$categories = $this->Category->find('list');$storemapping = Configure::read('storemapping');$this->set(compact('masterdata','categories','page','storemapping'));*/$page = $this->request->query('page');if(!isset($page)){$page = 1;}$limit = Configure::read('admindashboardlimit');$offset = ($page - 1)*$limit;$search = '';$url = $this->apihost."Catalog/searchMaster/?search=$search&limit=$limit&offset=$offset";$response = $this->make_request($url,null);$storemapping = Configure::read('storemapping');$this->set('masterdata', $response);$this->set(compact('page','search','storemapping'));}public function admin_edit($id = null) {$id = (integer) $id;if (!$id && empty($this->data)) {$this->flash(__('Invalid Post', true), array('action' => 'index'));}if (!empty($this->data)) {if ($this->MasterData->save($this->data)) {$this->flash(__('The data has been saved.', true), array('action' => 'index'));} else {}}if (empty($this->data)) {$this->data = $this->MasterData->read(null, $id);debug($this->data);}}public function admin_add() {if ($this->request->is('post')) {$this->log(print_r($this->request->data,1),'masterdatas');$url = $this->apihost."masterData/addOrUpdateMaster/?addNew=1";$data = $this->request->data['MasterData'];$url = $this->generateMultiUrl($url,$data);$data['identifier'] = (string)$data['identifier'];$data['secondaryIdentifier'] = (string)$data['secondaryIdentifier'];$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );$response = $this->make_request($url,$jsonVar);if (key($response)) {$this->Session->setFlash(current($response));return $this->redirect(array('action' => 'search'));} else {$this->Session->setFlash(current($response));}}$sources = Configure::read('storemapping');$sources[0] = 'Other';// $this->set('sources',$sources);// $this->set('source_ids',Configure::read('storemapping'));$this->set('categories',Configure::read('Categories'));$stock_statuses = array(0=>'OOS',1=>'In Stock');$statuses = array(2=>'EOL',1=>'Active',3=>'In Process',4=>'Exclusive');$shortage_status = array(0=>'No',1=>'Yes');$this->set(compact('stock_statuses','statuses','sources','shortage_status'));}public function admin_addtoexisting() {if ($this->request->is('post')) {$this->log(print_r($this->request->data,1),'masterdatas');$url = $this->apihost."masterData/addOrUpdateMaster/?addToExisting=1";$data = $this->request->data['MasterData'];$url = $this->generateMultiUrl($url,$data);$data['identifier'] = (string)$data['identifier'];$data['secondaryIdentifier'] = (string)$data['secondaryIdentifier'];$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );$response = $this->make_request($url,$jsonVar);if (key($response)) {$this->Session->setFlash(current($response));return $this->redirect(array('action' => 'search'));} else {$this->Session->setFlash(current($response));}}$sources = Configure::read('storemapping');$sources[0] = 'Other';// $this->set('sources',$sources);// $this->set('source_ids',Configure::read('storemapping'));$this->set('categories',Configure::read('Categories'));$stock_statuses = array(0=>'OOS',1=>'In Stock');$statuses = array(2=>'EOL',1=>'Active',3=>'In Process',4=>'Exclusive');$shortage_status = array(0=>'No',1=>'Yes');$this->set(compact('stock_statuses','statuses','sources','shortage_status'));}public function admin_update($id) {if ($this->request->is('post')) {$this->log(print_r($this->request->data,1),'masterdatas');$url = $this->apihost."masterData/addOrUpdateMaster/?update=1";$data = $this->request->data['MasterData'];if(isset($data['multi']) && !empty($data['multi'])){$url .= '&multi=1';unset($data['multi']);}$url = $this->generateMultiUrl($url,$data);$data['identifier'] = (string)$data['identifier'];$data['secondaryIdentifier'] = (string)$data['secondaryIdentifier'];$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );$response = $this->make_request($url,$jsonVar);if (key($response)) {$this->Session->setFlash(current($response));return $this->redirect(array('action' => 'search'));} else {$this->Session->setFlash(current($response));}}$url = $this->apihost."masterData/getSkuById/$id";$temp = $this->make_request($url,null);$data = json_decode($temp[0],1);$sources = Configure::read('storemapping');$sources[0] = 'Other';// $this->set('sources',$sources);// $this->set('source_ids',Configure::read('storemapping'));$this->set('categories',Configure::read('Categories'));$stock_statuses = array(0=>'OOS',1=>'In Stock');$statuses = array(2=>'EOL',1=>'Active',3=>'In Process',4=>'Exclusive');$shortage_status = array(0=>'No',1=>'Yes');$this->set(compact('stock_statuses','statuses','sources','shortage_status','data'));}public function admin_search(){$page = $this->request->query('page');if(!isset($page)){$page = 1;}$limit = Configure::read('admindashboardlimit');$offset = ($page - 1)*$limit;$search = urlencode($this->request->query('search'));$url = $this->apihost."Catalog/searchMaster/?search=$search&limit=$limit&offset=$offset";$response = $this->make_request($url,null);$storemapping = Configure::read('storemapping');$this->set('masterdata', $response);$this->set(compact('page','search','storemapping'));}}