Subversion Repositories SmartDukaan

Rev

Rev 13646 | Rev 14517 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
App::uses('AppController', 'Controller');
/**
 * Exceptionalskudiscounts Controller
 *
 * @property Exceptionalskudiscount $Exceptionalskudiscount
 * @property PaginatorComponent $Paginator
 */
class ExceptionalskudiscountsController extends AppController {

/**
 * Components
 *
 * @var array
 */
        public $components = array('Paginator');

        public $apihost;

        public function beforeFilter() {
                parent::beforeFilter();
                //Configure::load('live');
                $this->apihost = Configure::read('pythonapihost');
        }
/**
 * admin_index method
 *
 * @return void
 */
        public function admin_index() {
                $url = $this->apihost."discountInfo/getAllExceptionalSkuDiscount";
                $response = $this->make_request($url,null);
                $this->set('exceptionalskudiscounts', $response);
        }

/**
 * admin_view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function admin_view($id = null) {
                if (!$this->Exceptionalskudiscount->exists($id)) {
                        throw new NotFoundException(__('Invalid exceptionalskudiscount'));
                }
                $options = array('conditions' => array('Exceptionalskudiscount.' . $this->Exceptionalskudiscount->primaryKey => $id));
                $this->set('exceptionalskudiscount', $this->Exceptionalskudiscount->find('first', $options));
        }

/**
 * admin_add method
 *
 * @return void
 */
        public function admin_add() {
                if ($this->request->is('post')) {
                        $url = $this->apihost."discountInfo/addExceptionalSkuDiscount";
                        $jsonVar = json_encode($this->request->data['Exceptionalskudiscount'], JSON_NUMERIC_CHECK );
                        $response = $this->make_request($url,$jsonVar);
                        if (key($response)) {
                                $this->Session->setFlash(current($response));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(current($response));
                        }       
                }
        }

/**
 * admin_edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function admin_edit($id = null) {
                if (!$this->Exceptionalskudiscount->exists($id)) {
                        throw new NotFoundException(__('Invalid exceptionalskudiscount'));
                }
                if ($this->request->is(array('post', 'put'))) {
                        if ($this->Exceptionalskudiscount->save($this->request->data)) {
                                $this->Session->setFlash(__('The exceptionalskudiscount has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The exceptionalskudiscount could not be saved. Please, try again.'));
                        }
                } else {
                        $options = array('conditions' => array('Exceptionalskudiscount.' . $this->Exceptionalskudiscount->primaryKey => $id));
                        $this->request->data = $this->Exceptionalskudiscount->find('first', $options);
                }
        }

/**
 * admin_delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function admin_delete($id = null) {
                $this->Exceptionalskudiscount->id = $id;
                if (!$this->Exceptionalskudiscount->exists()) {
                        throw new NotFoundException(__('Invalid exceptionalskudiscount'));
                }
                $this->request->onlyAllow('post', 'delete');
                if ($this->Exceptionalskudiscount->delete()) {
                        $this->Session->setFlash(__('The exceptionalskudiscount has been deleted.'));
                } else {
                        $this->Session->setFlash(__('The exceptionalskudiscount could not be deleted. Please, try again.'));
                }
                return $this->redirect(array('action' => 'index'));
        }}