Subversion Repositories SmartDukaan

Rev

Rev 14561 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13646 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Exceptionalskudiscounts Controller
5
 *
6
 * @property Exceptionalskudiscount $Exceptionalskudiscount
7
 * @property PaginatorComponent $Paginator
8
 */
9
class ExceptionalskudiscountsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
	public $apihost;
19
 
20
	public function beforeFilter() {
21
		parent::beforeFilter();
13946 anikendra 22
		//Configure::load('live');
13646 anikendra 23
		$this->apihost = Configure::read('pythonapihost');
24
	}
25
/**
26
 * admin_index method
27
 *
28
 * @return void
29
 */
30
	public function admin_index() {
14098 anikendra 31
		$page = $this->request->query('page');
32
		if(!isset($page)){
33
			$page = 1;
34
		}
35
		$limit = Configure::read('admindashboardlimit');
36
		$offset = ($page - 1)*$limit;
37
		$url = $this->apihost."discountInfo/getAllExceptionalSkuDiscount/?limit=$limit&offset=$offset";
13646 anikendra 38
		$response = $this->make_request($url,null);
39
		$this->set('exceptionalskudiscounts', $response);
14098 anikendra 40
		$this->set('page',$page);
13646 anikendra 41
	}
42
 
43
/**
44
 * admin_view method
45
 *
46
 * @throws NotFoundException
47
 * @param string $id
48
 * @return void
49
 */
14517 anikendra 50
	public function admin_search() {
51
		$type = $this->request->query('type');
52
		$search = $this->request->query('search');				
53
		$url = $this->apihost."Catalog/searchProducts/?class=SkuDiscountInfo&$type=$search";
54
		$response = $this->make_request($url,null);
55
		$this->set('exceptionalskudiscounts', $response);
56
		$this->set('page',1);
57
		$this->render('admin_index');
13646 anikendra 58
	}
59
 
60
/**
61
 * admin_add method
62
 *
63
 * @return void
64
 */
65
	public function admin_add() {
66
		if ($this->request->is('post')) {
14561 anikendra 67
			$data = $this->request->data['Exceptionalskudiscount'];
68
			$url = $this->apihost."discountInfo/addExceptionalSkuDiscount";			
69
			$url = $this->generateMultiUrl($url,$data);
70
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
13646 anikendra 71
			$response = $this->make_request($url,$jsonVar);
72
			if (key($response)) {
73
				$this->Session->setFlash(current($response));
74
				return $this->redirect(array('action' => 'index'));
75
			} else {
76
				$this->Session->setFlash(current($response));
77
			}	
78
		}
79
	}
80
 
81
/**
82
 * admin_edit method
83
 *
84
 * @throws NotFoundException
85
 * @param string $id
86
 * @return void
87
 */
88
	public function admin_edit($id = null) {
89
		if (!$this->Exceptionalskudiscount->exists($id)) {
90
			throw new NotFoundException(__('Invalid exceptionalskudiscount'));
91
		}
92
		if ($this->request->is(array('post', 'put'))) {
93
			if ($this->Exceptionalskudiscount->save($this->request->data)) {
94
				$this->Session->setFlash(__('The exceptionalskudiscount has been saved.'));
95
				return $this->redirect(array('action' => 'index'));
96
			} else {
97
				$this->Session->setFlash(__('The exceptionalskudiscount could not be saved. Please, try again.'));
98
			}
99
		} else {
100
			$options = array('conditions' => array('Exceptionalskudiscount.' . $this->Exceptionalskudiscount->primaryKey => $id));
101
			$this->request->data = $this->Exceptionalskudiscount->find('first', $options);
102
		}
103
	}
104
 
105
/**
106
 * admin_delete method
107
 *
108
 * @throws NotFoundException
109
 * @param string $id
110
 * @return void
111
 */
14517 anikendra 112
	public function admin_delete($id = null) {		
15848 anikendra 113
		$response = $this->remove($id,'SkuDiscountInfo');
114
		if ($response) {
115
			$this->Session->setFlash(current($response));
13646 anikendra 116
		} else {
15848 anikendra 117
			$this->Session->setFlash(current($response));
13646 anikendra 118
		}
119
		return $this->redirect(array('action' => 'index'));
14517 anikendra 120
	}
121
}