Subversion Repositories SmartDukaan

Rev

Rev 13579 | Rev 13637 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 13579 Rev 13633
Line 12... Line 12...
12
 * Components
12
 * Components
13
 *
13
 *
14
 * @var array
14
 * @var array
15
 */
15
 */
16
	public $components = array('Paginator');
16
	public $components = array('Paginator');
-
 
17
	public $apihost;
17
 
18
 
-
 
19
	public function beforeFilter() {
-
 
20
		parent::beforeFilter();
-
 
21
		$this->loadModel('Pythonapi');
-
 
22
		Configure::load('live');
-
 
23
		$this->apihost = Configure::read('pythonapihost');
-
 
24
	}
18
/**
25
/**
19
 * index method
26
 * index method
20
 *
27
 *
21
 * @return void
28
 * @return void
22
 */
29
 */
Line 110... Line 117...
110
 * admin_index method
117
 * admin_index method
111
 *
118
 *
112
 * @return void
119
 * @return void
113
 */
120
 */
114
	public function admin_index() {
121
	public function admin_index() {
-
 
122
		$url = $this->apihost."discountInfo/getAllCategoryDiscount";
-
 
123
		$response = $this->make_request($url,$jsonVar);
115
		$this->CategoryDiscount->recursive = 0;
124
		$this->set('categoryDiscounts',$response);
-
 
125
		$this->loadModel('Category');
-
 
126
		$categories = $this->Category->find('list');
116
		$this->set('categoryDiscounts', $this->Paginator->paginate());
127
		$this->set('categories',$categories);
117
	}
128
	}
118
 
129
 
119
/**
130
/**
120
 * admin_view method
131
 * admin_view method
121
 *
132
 *
Line 134... Line 145...
134
/**
145
/**
135
 * admin_add method
146
 * admin_add method
136
 *
147
 *
137
 * @return void
148
 * @return void
138
 */
149
 */
139
	public function admin_add() {		
150
	public function admin_new() {		
140
		if ($this->request->is('post')) {
151
		if ($this->request->is('post')) {
141
			$conditions = array('category_id'=>$this->request->data['CategoryDiscount']['category_id'],'brand'=>$this->request->data['CategoryDiscount']['brand']);
-
 
142
			$count = $this->CategoryDiscount->find('count',array('conditions'=>$conditions,'recursive'=>-1));
152
			$url = $this->apihost."discountInfo/addCategoryDiscount";
143
			if($count > 0){
-
 
144
				$this->Session->setFlash(__('Duplicate category and brand combination.'));
153
			$jsonVar = json_encode($this->request->data['CategoryDiscount'], JSON_NUMERIC_CHECK );
145
			}else{
-
 
146
				$this->CategoryDiscount->create();
154
			$response = $this->make_request($url,$jsonVar);
147
				if ($this->CategoryDiscount->save($this->request->data)) {
155
			if (key($response)) {
148
					$this->Session->setFlash(__('The category discount has been saved.'));
156
				$this->Session->setFlash(current($response));
149
					return $this->redirect(array('action' => 'index'));
157
				return $this->redirect(array('action' => 'index'));
150
				} else {
158
			} else {
151
					$this->Session->setFlash(__('The category discount could not be saved. Please, try again.'));
159
				$this->Session->setFlash(current($response));
152
				}
-
 
153
			}
160
			}
154
		}
161
		}
155
		$this->loadModel('Brand');
162
		$this->loadModel('Brand');
156
		$allbrands = $this->Brand->find('list');
163
		$allbrands = $this->Brand->find('list');
157
		foreach ($allbrands as $key => $value) {
164
		foreach ($allbrands as $key => $value) {
158
			$brands[$value] = $value;
165
			$brands[$value] = $value;
159
		}
166
		}
-
 
167
		$this->loadModel('Category');
160
		$categories = $this->CategoryDiscount->Category->find('list',array('conditions'=>array('parent_id !='=>0)));
168
		$categories = $this->Category->find('list',array('conditions'=>array('parent_id !='=>0)));
161
		$this->set(compact('categories','brands'));
169
		$this->set(compact('categories','brands'));
162
	}
170
	}
163
 
171
 
164
/**
172
/**
165
 * admin_edit method
173
 * admin_edit method