Subversion Repositories SmartDukaan

Rev

Rev 13646 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
13637 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Skuschemes Controller
5
 *
6
 * @property Skuscheme $Skuscheme
7
 * @property PaginatorComponent $Paginator
8
 */
9
class SkuschemesController 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/getAllSkuSchemeDetails";
32
		$response = $this->make_request($url,null);
33
		$this->set('skuschemes',$response);
34
		// $this->Skuscheme->recursive = 0;
35
		// $this->set('skuschemes', $this->Paginator->paginate());
36
	}
37
 
38
/**
39
 * admin_view method
40
 *
41
 * @throws NotFoundException
42
 * @param string $id
43
 * @return void
44
 */
45
	public function admin_view($id = null) {
46
		if (!$this->Skuscheme->exists($id)) {
47
			throw new NotFoundException(__('Invalid skuscheme'));
48
		}
49
		$options = array('conditions' => array('Skuscheme.' . $this->Skuscheme->primaryKey => $id));
50
		$this->set('skuscheme', $this->Skuscheme->find('first', $options));
51
	}
52
 
53
/**
54
 * admin_add method
55
 *
56
 * @return void
57
 */
58
	public function admin_add() {
59
		if ($this->request->is('post')) {
60
			$url = $this->apihost."discountInfo/addSkuSchemeDetails";
61
			$jsonVar = json_encode($this->request->data['Skuscheme'], JSON_NUMERIC_CHECK );
62
			$response = $this->make_request($url,$jsonVar);
63
			if (key($response)) {
64
				$this->Session->setFlash(current($response));
65
				return $this->redirect(array('action' => 'index'));
66
			} else {
67
				$this->Session->setFlash(current($response));
68
			}
69
			/*$this->Skuscheme->create();
70
			if ($this->Skuscheme->save($this->request->data)) {
71
				$this->Session->setFlash(__('The skuscheme has been saved.'));
72
				return $this->redirect(array('action' => 'index'));
73
			} else {
74
				$this->Session->setFlash(__('The skuscheme could not be saved. Please, try again.'));
75
			}*/
76
		}
77
	}
78
 
79
/**
80
 * admin_edit method
81
 *
82
 * @throws NotFoundException
83
 * @param string $id
84
 * @return void
85
 */
86
	public function admin_edit($id = null) {
87
		if (!$this->Skuscheme->exists($id)) {
88
			throw new NotFoundException(__('Invalid skuscheme'));
89
		}
90
		if ($this->request->is(array('post', 'put'))) {
91
			if ($this->Skuscheme->save($this->request->data)) {
92
				$this->Session->setFlash(__('The skuscheme has been saved.'));
93
				return $this->redirect(array('action' => 'index'));
94
			} else {
95
				$this->Session->setFlash(__('The skuscheme could not be saved. Please, try again.'));
96
			}
97
		} else {
98
			$options = array('conditions' => array('Skuscheme.' . $this->Skuscheme->primaryKey => $id));
99
			$this->request->data = $this->Skuscheme->find('first', $options);
100
		}
101
	}
102
 
103
/**
104
 * admin_delete method
105
 *
106
 * @throws NotFoundException
107
 * @param string $id
108
 * @return void
109
 */
110
	public function admin_delete($id = null) {
111
		$this->Skuscheme->id = $id;
112
		if (!$this->Skuscheme->exists()) {
113
			throw new NotFoundException(__('Invalid skuscheme'));
114
		}
115
		$this->request->onlyAllow('post', 'delete');
116
		if ($this->Skuscheme->delete()) {
117
			$this->Session->setFlash(__('The skuscheme has been deleted.'));
118
		} else {
119
			$this->Session->setFlash(__('The skuscheme could not be deleted. Please, try again.'));
120
		}
121
		return $this->redirect(array('action' => 'index'));
122
	}}