Commit 2942e27d491a8b945cee9fe1e0929f52c55dee37
Merge branch 'discount' of gitlab.artweb.com.ua:Alex/semena
Showing
3 changed files
with
109 additions
and
14 deletions
Show diff stats
src/app/backend/controllers/DiscountController.php
| @@ -32,12 +32,11 @@ class DiscountController extends Controller | @@ -32,12 +32,11 @@ class DiscountController extends Controller | ||
| 32 | 32 | ||
| 33 | $params = $this->dispatcher->getParams(); | 33 | $params = $this->dispatcher->getParams(); |
| 34 | $page = !empty( $params['page'] ) ? $params['page'] : 1; | 34 | $page = !empty( $params['page'] ) ? $params['page'] : 1; |
| 35 | - | ||
| 36 | $data = $this->models->getDiscount()->getAllData(); | 35 | $data = $this->models->getDiscount()->getAllData(); |
| 37 | $total = $this->models->getDiscount()->countData(); | 36 | $total = $this->models->getDiscount()->countData(); |
| 38 | 37 | ||
| 39 | - if( $total['0']['total'] > \config::get( 'limits/items') ) | ||
| 40 | - { | 38 | + if( $total['0']['total'] > \config::get( 'limits/items') ) { |
| 39 | + | ||
| 41 | $paginate = $this->common->paginate( | 40 | $paginate = $this->common->paginate( |
| 42 | [ | 41 | [ |
| 43 | 'page' => $page, | 42 | 'page' => $page, |
| @@ -47,6 +46,7 @@ class DiscountController extends Controller | @@ -47,6 +46,7 @@ class DiscountController extends Controller | ||
| 47 | 'index_page' => 'discount_index' | 46 | 'index_page' => 'discount_index' |
| 48 | ], true | 47 | ], true |
| 49 | ); | 48 | ); |
| 49 | + | ||
| 50 | } | 50 | } |
| 51 | $this->view->setVars([ | 51 | $this->view->setVars([ |
| 52 | 'info' => $data, | 52 | 'info' => $data, |
| @@ -62,16 +62,19 @@ class DiscountController extends Controller | @@ -62,16 +62,19 @@ class DiscountController extends Controller | ||
| 62 | public function addAction() { | 62 | public function addAction() { |
| 63 | 63 | ||
| 64 | $titlecmp = function ($a, $b) { | 64 | $titlecmp = function ($a, $b) { |
| 65 | + | ||
| 65 | return strcasecmp($a['title'], $b['title']); | 66 | return strcasecmp($a['title'], $b['title']); |
| 67 | + | ||
| 66 | }; | 68 | }; |
| 69 | + | ||
| 67 | $lang_id = 1; // ua language | 70 | $lang_id = 1; // ua language |
| 68 | - if( !$this->session->get('isAdminAuth') ) | ||
| 69 | - { | 71 | + if( !$this->session->get('isAdminAuth') ) { |
| 72 | + | ||
| 70 | return $this->response->redirect([ 'for' => 'admin_login' ]); | 73 | return $this->response->redirect([ 'for' => 'admin_login' ]); |
| 74 | + | ||
| 71 | } | 75 | } |
| 72 | 76 | ||
| 73 | - if( $this->request->isPost() ) | ||
| 74 | - { | 77 | + if( $this->request->isPost() ) { |
| 75 | 78 | ||
| 76 | $data['name'] = $this->request->getPost('name', 'string', NULL ); | 79 | $data['name'] = $this->request->getPost('name', 'string', NULL ); |
| 77 | $data['description'] = $this->request->getPost('description'); | 80 | $data['description'] = $this->request->getPost('description'); |
| @@ -79,14 +82,16 @@ class DiscountController extends Controller | @@ -79,14 +82,16 @@ class DiscountController extends Controller | ||
| 79 | $data['end_date'] = $this->request->getPost('end_date'); | 82 | $data['end_date'] = $this->request->getPost('end_date'); |
| 80 | $data['discount'] = $this->request->getPost('discount', 'string', NULL ); | 83 | $data['discount'] = $this->request->getPost('discount', 'string', NULL ); |
| 81 | 84 | ||
| 82 | - if($this->models->getDiscount()->addData( $data )) | ||
| 83 | - { | 85 | + if($this->models->getDiscount()->addData( $data )) { |
| 86 | + | ||
| 84 | $this->flash->success( 'Сохранение прошло успешно' ); | 87 | $this->flash->success( 'Сохранение прошло успешно' ); |
| 85 | return $this->response->redirect([ 'for' => 'discount_index' ]); | 88 | return $this->response->redirect([ 'for' => 'discount_index' ]); |
| 89 | + | ||
| 86 | } | 90 | } |
| 87 | - else | ||
| 88 | - { | 91 | + else { |
| 92 | + | ||
| 89 | $this->flash->error( 'Выберите товары для промокода' ); | 93 | $this->flash->error( 'Выберите товары для промокода' ); |
| 94 | + | ||
| 90 | } | 95 | } |
| 91 | } | 96 | } |
| 92 | 97 | ||
| @@ -99,4 +104,74 @@ class DiscountController extends Controller | @@ -99,4 +104,74 @@ class DiscountController extends Controller | ||
| 99 | 104 | ||
| 100 | } | 105 | } |
| 101 | 106 | ||
| 107 | + /** | ||
| 108 | + * Delete discount by $id | ||
| 109 | + * @param $id | ||
| 110 | + * @return \Phalcon\Http\ResponseInterface | ||
| 111 | + */ | ||
| 112 | + public function deleteAction($id) { | ||
| 113 | + | ||
| 114 | + if( !$this->session->get('isAdminAuth') ) { | ||
| 115 | + | ||
| 116 | + return $this->response->redirect([ 'for' => 'admin_login' ]); | ||
| 117 | + | ||
| 118 | + } | ||
| 119 | + $this->models->getDiscount()->deleteData($id); | ||
| 120 | + | ||
| 121 | + return $this->response->redirect([ 'for' => 'discount_index' ]); | ||
| 122 | + | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + /** | ||
| 126 | + * Update discount form | ||
| 127 | + * @param $id | ||
| 128 | + * @return \Phalcon\Http\ResponseInterface | ||
| 129 | + */ | ||
| 130 | + public function updateAction($id) { | ||
| 131 | + | ||
| 132 | + $titlecmp = function ($a, $b) { | ||
| 133 | + | ||
| 134 | + return strcasecmp($a['title'], $b['title']); | ||
| 135 | + | ||
| 136 | + }; | ||
| 137 | + | ||
| 138 | + $lang_id = 1; // ua language | ||
| 139 | + | ||
| 140 | + if( !$this->session->get('isAdminAuth') ) { | ||
| 141 | + | ||
| 142 | + return $this->response->redirect([ 'for' => 'admin_login' ]); | ||
| 143 | + | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + $data = $this->models->getDiscount()->getOneData($id); | ||
| 147 | + | ||
| 148 | + if( $this->request->isPost() ) { | ||
| 149 | + | ||
| 150 | + $data[0]['name'] = $this->request->getPost('name', 'string', NULL ); | ||
| 151 | + $data[0]['discount'] = $this->request->getPost('discount', 'string', NULL ); | ||
| 152 | + $data[0]['start_date'] = $this->request->getPost('start_date'); | ||
| 153 | + $data[0]['end_date'] = $this->request->getPost('end_date'); | ||
| 154 | + $data[0]['description'] = $this->request->getPost('description'); | ||
| 155 | + | ||
| 156 | + if($this->models->getDiscount()->updateData( $data[0], $id ) ) { | ||
| 157 | + | ||
| 158 | + $this->flash->success( 'Сохранение прошло успешно' ); | ||
| 159 | + return $this->response->redirect([ 'for' => 'discount_index' ]); | ||
| 160 | + | ||
| 161 | + } | ||
| 162 | + else { | ||
| 163 | + | ||
| 164 | + $this->flash->error( 'Update error.' ); | ||
| 165 | + | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + $this->view->pick( 'discount/addEdit' ); | ||
| 171 | + | ||
| 172 | + $this->view->setVars([ | ||
| 173 | + 'page' => $data | ||
| 174 | + ]); | ||
| 175 | + | ||
| 176 | + } | ||
| 102 | } | 177 | } |
| 103 | \ No newline at end of file | 178 | \ No newline at end of file |
src/app/backend/views/discount/index.php
| @@ -35,9 +35,9 @@ | @@ -35,9 +35,9 @@ | ||
| 35 | $data_pages .= | 35 | $data_pages .= |
| 36 | '<div class="one_page_edit header_gradient clearfix">'. | 36 | '<div class="one_page_edit header_gradient clearfix">'. |
| 37 | '<div class="one_page_edit_check float"></div>'. | 37 | '<div class="one_page_edit_check float"></div>'. |
| 38 | - '<div class="one_page_edit_name float"><a href="/promo_codes_update/'.$p['id'].'" title="">'.$p['name'].'</a></div>'. | ||
| 39 | - '<div class="one_page_delete_ico float_right"><a href="/promo_codes_delete/'.$p['id'].'" title="Удалить" onclick="return confirm(\'Вы действительно хотите удалить информацию?\')"></a></div>'. | ||
| 40 | - '<div class="one_page_edit_ico float_right"><a href="/promo_codes_update/'.$p['id'].'" title="Редактировать"></a></div>'. | 38 | + '<div class="one_page_edit_name float"><a href="/discount_update/'.$p['id'].'" title="">'.$p['name'].'</a></div>'. |
| 39 | + '<div class="one_page_delete_ico float_right"><a href="/discount_delete/'.$p['id'].'" title="Удалить" onclick="return confirm(\'Вы действительно хотите удалить информацию?\')"></a></div>'. | ||
| 40 | + '<div class="one_page_edit_ico float_right"><a href="/discount_update/'.$p['id'].'" title="Редактировать"></a></div>'. | ||
| 41 | '</div>'; | 41 | '</div>'; |
| 42 | } | 42 | } |
| 43 | 43 |
www-backend/index.php
| @@ -1099,6 +1099,26 @@ try | @@ -1099,6 +1099,26 @@ try | ||
| 1099 | ) | 1099 | ) |
| 1100 | ->setName('discount_add'); | 1100 | ->setName('discount_add'); |
| 1101 | 1101 | ||
| 1102 | + $router->add | ||
| 1103 | + ( | ||
| 1104 | + '/discount_update', | ||
| 1105 | + [ | ||
| 1106 | + 'controller' => 'discount', | ||
| 1107 | + 'action' => 'update' | ||
| 1108 | + ] | ||
| 1109 | + ) | ||
| 1110 | + ->setName('discount_update'); | ||
| 1111 | + | ||
| 1112 | + $router->add | ||
| 1113 | + ( | ||
| 1114 | + '/discount_delete', | ||
| 1115 | + [ | ||
| 1116 | + 'controller' => 'discount', | ||
| 1117 | + 'action' => 'delete' | ||
| 1118 | + ] | ||
| 1119 | + ) | ||
| 1120 | + ->setName('discount_delete'); | ||
| 1121 | + | ||
| 1102 | /* *************************************** */ | 1122 | /* *************************************** */ |
| 1103 | 1123 | ||
| 1104 | $router->add | 1124 | $router->add |