Subversion Repositories SmartDukaan

Rev

Rev 13946 | Go to most recent revision | Details | 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();
22
		Configure::load('live');
23
		$this->apihost = Configure::read('pythonapihost');
24
	}
25
/**
26
 * admin_index method
27
 *
28
 * @return void
29
 */
30
	public function admin_index() {
31
		$url = $this->apihost."discountInfo/getAllExceptionalSkuDiscount";
32
		$response = $this->make_request($url,null);
33
		$this->set('exceptionalskudiscounts', $response);
34
	}
35
 
36
/**
37
 * admin_view method
38
 *
39
 * @throws NotFoundException
40
 * @param string $id
41
 * @return void
42
 */
43
	public function admin_view($id = null) {
44
		if (!$this->Exceptionalskudiscount->exists($id)) {
45
			throw new NotFoundException(__('Invalid exceptionalskudiscount'));
46
		}
47
		$options = array('conditions' => array('Exceptionalskudiscount.' . $this->Exceptionalskudiscount->primaryKey => $id));
48
		$this->set('exceptionalskudiscount', $this->Exceptionalskudiscount->find('first', $options));
49
	}
50
 
51
/**
52
 * admin_add method
53
 *
54
 * @return void
55
 */
56
	public function admin_add() {
57
		if ($this->request->is('post')) {
58
			$url = $this->apihost."discountInfo/addExceptionalSkuDiscount";
59
			$jsonVar = json_encode($this->request->data['Exceptionalskudiscount'], JSON_NUMERIC_CHECK );
60
			$response = $this->make_request($url,$jsonVar);
61
			if (key($response)) {
62
				$this->Session->setFlash(current($response));
63
				return $this->redirect(array('action' => 'index'));
64
			} else {
65
				$this->Session->setFlash(current($response));
66
			}	
67
		}
68
	}
69
 
70
/**
71
 * admin_edit method
72
 *
73
 * @throws NotFoundException
74
 * @param string $id
75
 * @return void
76
 */
77
	public function admin_edit($id = null) {
78
		if (!$this->Exceptionalskudiscount->exists($id)) {
79
			throw new NotFoundException(__('Invalid exceptionalskudiscount'));
80
		}
81
		if ($this->request->is(array('post', 'put'))) {
82
			if ($this->Exceptionalskudiscount->save($this->request->data)) {
83
				$this->Session->setFlash(__('The exceptionalskudiscount has been saved.'));
84
				return $this->redirect(array('action' => 'index'));
85
			} else {
86
				$this->Session->setFlash(__('The exceptionalskudiscount could not be saved. Please, try again.'));
87
			}
88
		} else {
89
			$options = array('conditions' => array('Exceptionalskudiscount.' . $this->Exceptionalskudiscount->primaryKey => $id));
90
			$this->request->data = $this->Exceptionalskudiscount->find('first', $options);
91
		}
92
	}
93
 
94
/**
95
 * admin_delete method
96
 *
97
 * @throws NotFoundException
98
 * @param string $id
99
 * @return void
100
 */
101
	public function admin_delete($id = null) {
102
		$this->Exceptionalskudiscount->id = $id;
103
		if (!$this->Exceptionalskudiscount->exists()) {
104
			throw new NotFoundException(__('Invalid exceptionalskudiscount'));
105
		}
106
		$this->request->onlyAllow('post', 'delete');
107
		if ($this->Exceptionalskudiscount->delete()) {
108
			$this->Session->setFlash(__('The exceptionalskudiscount has been deleted.'));
109
		} else {
110
			$this->Session->setFlash(__('The exceptionalskudiscount could not be deleted. Please, try again.'));
111
		}
112
		return $this->redirect(array('action' => 'index'));
113
	}}