From c4094a9550bb50a85450b1de1b9942a10cdef06f Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 20 Dec 2016 16:25:02 +0200 Subject: [PATCH] add/edit --- src/app/backend/controllers/DiscountController.php | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- src/app/backend/views/discount/addEdit.php | 283 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/app/backend/views/discount/index.php | 2 +- src/app/backend/views/partial/sidebar.php | 2 +- www-backend/index.php | 10 ++++++++++ 5 files changed, 348 insertions(+), 3 deletions(-) create mode 100644 src/app/backend/views/discount/addEdit.php diff --git a/src/app/backend/controllers/DiscountController.php b/src/app/backend/controllers/DiscountController.php index 839a34d..bdf8716 100644 --- a/src/app/backend/controllers/DiscountController.php +++ b/src/app/backend/controllers/DiscountController.php @@ -10,10 +10,18 @@ namespace controllers; use Phalcon\Mvc\Controller; - +/** + * Class DiscountController + * @package controllers + * @property \models models + */ class DiscountController extends Controller { + /** + * Displays all discounts with pagination + * @return \Phalcon\Http\ResponseInterface + */ public function indexAction() { if( !$this->session->get('isAdminAuth') ) { @@ -47,4 +55,48 @@ class DiscountController extends Controller } + /** + * Add discount form + * @return \Phalcon\Http\ResponseInterface + */ + public function addAction() { + + $titlecmp = function ($a, $b) { + return strcasecmp($a['title'], $b['title']); + }; + $lang_id = 1; // ua language + if( !$this->session->get('isAdminAuth') ) + { + return $this->response->redirect([ 'for' => 'admin_login' ]); + } + + if( $this->request->isPost() ) + { + + $data['name'] = $this->request->getPost('name', 'string', NULL ); + $data['description'] = $this->request->getPost('description'); + $data['start_date'] = $this->request->getPost('start_date'); + $data['end_date'] = $this->request->getPost('end_date'); + $data['discount'] = $this->request->getPost('discount', 'string', NULL ); + + if($this->models->getDiscount()->addData( $data )) + { + $this->flash->success( 'Сохранение прошло успешно' ); + return $this->response->redirect([ 'for' => 'discount_index' ]); + } + else + { + $this->flash->error( 'Выберите товары для промокода' ); + } + } + + $catalog_temp = $this->common->getTypeSubtype1(NULL, $lang_id)['catalog']; + usort($catalog_temp, $titlecmp); + + + $this->view->setVar('catalog_temp', $catalog_temp); + $this->view->pick( 'discount/addEdit' ); + + } + } \ No newline at end of file diff --git a/src/app/backend/views/discount/addEdit.php b/src/app/backend/views/discount/addEdit.php new file mode 100644 index 0000000..3de7751 --- /dev/null +++ b/src/app/backend/views/discount/addEdit.php @@ -0,0 +1,283 @@ +
+
flash->output(); ?>
+
+ +
+
+ \ No newline at end of file diff --git a/src/app/backend/views/discount/index.php b/src/app/backend/views/discount/index.php index 966c6f1..87d5129 100644 --- a/src/app/backend/views/discount/index.php +++ b/src/app/backend/views/discount/index.php @@ -20,7 +20,7 @@
discounts
- +
diff --git a/src/app/backend/views/partial/sidebar.php b/src/app/backend/views/partial/sidebar.php index 6da682d..ef417c3 100644 --- a/src/app/backend/views/partial/sidebar.php +++ b/src/app/backend/views/partial/sidebar.php @@ -57,7 +57,7 @@