Subversion Repositories SmartDukaan

Rev

Rev 13946 | Rev 14517 | Go to most recent revision | 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
 */
50
	public function admin_view($id = null) {
51
		if (!$this->Exceptionalskudiscount->exists($id)) {
52
			throw new NotFoundException(__('Invalid exceptionalskudiscount'));
53
		}
54
		$options = array('conditions' => array('Exceptionalskudiscount.' . $this->Exceptionalskudiscount->primaryKey => $id));
55
		$this->set('exceptionalskudiscount', $this->Exceptionalskudiscount->find('first', $options));
56
	}
57
 
58
/**
59
 * admin_add method
60
 *
61
 * @return void
62
 */
63
	public function admin_add() {
64
		if ($this->request->is('post')) {
65
			$url = $this->apihost."discountInfo/addExceptionalSkuDiscount";
66
			$jsonVar = json_encode($this->request->data['Exceptionalskudiscount'], JSON_NUMERIC_CHECK );
67
			$response = $this->make_request($url,$jsonVar);
68
			if (key($response)) {
69
				$this->Session->setFlash(current($response));
70
				return $this->redirect(array('action' => 'index'));
71
			} else {
72
				$this->Session->setFlash(current($response));
73
			}	
74
		}
75
	}
76
 
77
/**
78
 * admin_edit method
79
 *
80
 * @throws NotFoundException
81
 * @param string $id
82
 * @return void
83
 */
84
	public function admin_edit($id = null) {
85
		if (!$this->Exceptionalskudiscount->exists($id)) {
86
			throw new NotFoundException(__('Invalid exceptionalskudiscount'));
87
		}
88
		if ($this->request->is(array('post', 'put'))) {
89
			if ($this->Exceptionalskudiscount->save($this->request->data)) {
90
				$this->Session->setFlash(__('The exceptionalskudiscount has been saved.'));
91
				return $this->redirect(array('action' => 'index'));
92
			} else {
93
				$this->Session->setFlash(__('The exceptionalskudiscount could not be saved. Please, try again.'));
94
			}
95
		} else {
96
			$options = array('conditions' => array('Exceptionalskudiscount.' . $this->Exceptionalskudiscount->primaryKey => $id));
97
			$this->request->data = $this->Exceptionalskudiscount->find('first', $options);
98
		}
99
	}
100
 
101
/**
102
 * admin_delete method
103
 *
104
 * @throws NotFoundException
105
 * @param string $id
106
 * @return void
107
 */
108
	public function admin_delete($id = null) {
109
		$this->Exceptionalskudiscount->id = $id;
110
		if (!$this->Exceptionalskudiscount->exists()) {
111
			throw new NotFoundException(__('Invalid exceptionalskudiscount'));
112
		}
113
		$this->request->onlyAllow('post', 'delete');
114
		if ($this->Exceptionalskudiscount->delete()) {
115
			$this->Session->setFlash(__('The exceptionalskudiscount has been deleted.'));
116
		} else {
117
			$this->Session->setFlash(__('The exceptionalskudiscount could not be deleted. Please, try again.'));
118
		}
119
		return $this->redirect(array('action' => 'index'));
120
	}}