diff --git a/src/app/backend/controllers/PromoCodesController.php b/src/app/backend/controllers/PromoCodesController.php index a220839..d9a1d5b 100644 --- a/src/app/backend/controllers/PromoCodesController.php +++ b/src/app/backend/controllers/PromoCodesController.php @@ -38,54 +38,54 @@ class PromoCodesController extends Controller } 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' ]); - } + $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() ) + if( $this->request->isPost() ) + { + + $data['name'] = $this->request->getPost('name', 'string', NULL ); + $data['code'] = $this->request->getPost('code', 'string', NULL ); + $data['start_date'] = $this->request->getPost('start_date'); + $data['end_date'] = $this->request->getPost('end_date'); + $data['single_use'] = $this->request->getPost('single_use'); + $data['discount'] = $this->request->getPost('discount', 'string', NULL ); + $data['description'] = $this->request->getPost('description'); + $data['catalog_ids'] = $this->request->getPost('catalog', 'string', NULL ); + $data['group_ids'] = $this->request->getPost('items', 'string', NULL ); + $data['all_items'] = $this->request->getPost('all_items', 'int', NULL); + $data['image'] = $this->uploadImage(); + + if( empty($this->models->getPromoCodes()->getPromoByCode( $data['code'] )[0]) ) { - - $data['name'] = $this->request->getPost('name', 'string', NULL ); - $data['code'] = $this->request->getPost('code', 'string', NULL ); - $data['start_date'] = $this->request->getPost('start_date'); - $data['end_date'] = $this->request->getPost('end_date'); - $data['single_use'] = $this->request->getPost('single_use'); - $data['discount'] = $this->request->getPost('discount', 'string', NULL ); - $data['description'] = $this->request->getPost('description'); - $data['catalog_ids'] = $this->request->getPost('catalog', 'string', NULL ); - $data['group_ids'] = $this->request->getPost('items', 'string', NULL ); - $data['all_items'] = $this->request->getPost('all_items', 'int', NULL); - $data['image'] = $this->uploadImage(); - - if( empty($this->models->getPromoCodes()->getPromoByCode( $data['code'] )[0]) ) + if(!empty($data['group_ids']) && $this->models->getPromoCodes()->addData( $data )) { - if(!empty($data['group_ids']) && $this->models->getPromoCodes()->addData( $data )) - { - $this->flash->success( 'Сохранение прошло успешно' ); - return $this->response->redirect([ 'for' => 'promo_codes_index' ]); - } - else - { - $this->flash->error( 'Выберите товары для промокода' ); - } + $this->flash->success( 'Сохранение прошло успешно' ); + return $this->response->redirect([ 'for' => 'promo_codes_index' ]); } - else { - $this->flash->error('Такой промокод уже существует'); + else + { + $this->flash->error( 'Выберите товары для промокода' ); } } + else { + $this->flash->error('Такой промокод уже существует'); + } + } - $catalog_temp = $this->common->getTypeSubtype1(NULL, $lang_id)['catalog']; - usort($catalog_temp, $titlecmp); + $catalog_temp = $this->common->getTypeSubtype1(NULL, $lang_id)['catalog']; + usort($catalog_temp, $titlecmp); - $this->view->setVar('catalog_temp', $catalog_temp); - $this->view->pick( 'promo_codes/addEdit' ); - } + $this->view->setVar('catalog_temp', $catalog_temp); + $this->view->pick( 'promo_codes/addEdit' ); +} public function deleteAction($id) { if( !$this->session->get('isAdminAuth') ) diff --git a/www-backend/index.php b/www-backend/index.php index af3c398..f073b89 100644 --- a/www-backend/index.php +++ b/www-backend/index.php @@ -1093,7 +1093,7 @@ try ( '/discount_add', [ - 'controller' => 'promo_codes', + 'controller' => 'discount', 'action' => 'add' ] ) -- libgit2 0.21.4