Blame | Last modification | View Log | RSS feed
<?phpApp::uses('AppController', 'Controller');/*** CategoryDiscounts Controller** @property CategoryDiscount $CategoryDiscount* @property PaginatorComponent $Paginator*/class CategoryDiscountsController extends AppController {/*** Components** @var array*/public $components = array('Paginator');public $apihost;public function beforeFilter() {parent::beforeFilter();$this->loadModel('Pythonapi');// Configure::load('live');$this->apihost = Configure::read('pythonapihost');}/*** index method** @return void*/public function index() {$this->CategoryDiscount->recursive = 0;$this->set('categoryDiscounts', $this->Paginator->paginate());}/*** view method** @throws NotFoundException* @param string $id* @return void*/public function view($id = null) {if (!$this->CategoryDiscount->exists($id)) {throw new NotFoundException(__('Invalid category discount'));}$options = array('conditions' => array('CategoryDiscount.' . $this->CategoryDiscount->primaryKey => $id));$this->set('categoryDiscount', $this->CategoryDiscount->find('first', $options));}/*** add method** @return void*/public function add() {if ($this->request->is('post')) {$this->CategoryDiscount->create();if ($this->CategoryDiscount->save($this->request->data)) {$this->Session->setFlash(__('The category discount has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The category discount could not be saved. Please, try again.'));}}$categories = $this->CategoryDiscount->Category->find('list');$this->set(compact('categories'));}/*** edit method** @throws NotFoundException* @param string $id* @return void*/public function edit($id = null) {if (!$this->CategoryDiscount->exists($id)) {throw new NotFoundException(__('Invalid category discount'));}if ($this->request->is(array('post', 'put'))) {if ($this->CategoryDiscount->save($this->request->data)) {$this->Session->setFlash(__('The category discount has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The category discount could not be saved. Please, try again.'));}} else {$options = array('conditions' => array('CategoryDiscount.' . $this->CategoryDiscount->primaryKey => $id));$this->request->data = $this->CategoryDiscount->find('first', $options);}$categories = $this->CategoryDiscount->Category->find('list');$this->set(compact('categories'));}/*** delete method** @throws NotFoundException* @param string $id* @return void*/public function delete($id = null) {$this->CategoryDiscount->id = $id;if (!$this->CategoryDiscount->exists()) {throw new NotFoundException(__('Invalid category discount'));}$this->request->onlyAllow('post', 'delete');if ($this->CategoryDiscount->delete()) {$this->Session->setFlash(__('The category discount has been deleted.'));} else {$this->Session->setFlash(__('The category discount could not be deleted. Please, try again.'));}return $this->redirect(array('action' => 'index'));}/*** admin_index method** @return void*/public function admin_index() {$url = $this->apihost."discountInfo/getAllCategoryDiscount";$response = $this->make_request($url,null);$this->set('categoryDiscounts',$response);$this->loadModel('Category');// $categories = $this->Category->find('list');$categories = Configure::read('Categories');$this->set('categories',$categories);}/*** admin_view method** @throws NotFoundException* @param string $id* @return void*/public function admin_view($id = null) {if (!$this->CategoryDiscount->exists($id)) {throw new NotFoundException(__('Invalid category discount'));}$options = array('conditions' => array('CategoryDiscount.' . $this->CategoryDiscount->primaryKey => $id));$this->set('categoryDiscount', $this->CategoryDiscount->find('first', $options));}/*** admin_add method** @return void*/public function admin_new() {if ($this->request->is('post')) {$url = $this->apihost."discountInfo/addCategoryDiscount";$jsonVar = json_encode($this->request->data['CategoryDiscount'], 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));}}$this->loadModel('Brand');$allbrands = $this->Brand->find('list');foreach ($allbrands as $key => $value) {$brands[$value] = $value;}$this->loadModel('Category');$categories = $this->Category->find('list',array('conditions'=>array('parent_id !='=>0)));$this->set(compact('categories','brands'));}/*** admin_edit method** @throws NotFoundException* @param string $id* @return void*/public function admin_edit($id = null) {// if (!$this->CategoryDiscount->exists($id)) {// throw new NotFoundException(__('Invalid category discount'));// }if ($this->request->is(array('post', 'put'))) {if ($this->CategoryDiscount->save($this->request->data)) {$this->Session->setFlash(__('The category discount has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The category discount could not be saved. Please, try again.'));}} else {$options = array('conditions' => array('CategoryDiscount.' . $this->CategoryDiscount->primaryKey => $id));$this->request->data = $this->CategoryDiscount->find('first', $options);}$categories = $this->CategoryDiscount->Category->find('list');$this->set(compact('categories'));}/*** admin_delete method** @throws NotFoundException* @param string $id* @return void*/public function admin_delete($id = null) {$this->CategoryDiscount->id = $id;if (!$this->CategoryDiscount->exists()) {throw new NotFoundException(__('Invalid category discount'));}$this->request->onlyAllow('post', 'delete');if ($this->CategoryDiscount->delete()) {$this->Session->setFlash(__('The category discount has been deleted.'));} else {$this->Session->setFlash(__('The category discount could not be deleted. Please, try again.'));}return $this->redirect(array('action' => 'index'));}}