Commit bb5cfdd0234ed8f732156e78e22b85ad4cb044eb
1 parent
c4094a95
add/edit
Showing
2 changed files
with
40 additions
and
40 deletions
Show diff stats
src/app/backend/controllers/PromoCodesController.php
... | ... | @@ -38,54 +38,54 @@ class PromoCodesController extends Controller |
38 | 38 | } |
39 | 39 | |
40 | 40 | public function addAction() { |
41 | - $titlecmp = function ($a, $b) { | |
42 | - return strcasecmp($a['title'], $b['title']); | |
43 | - }; | |
44 | - $lang_id = 1; // ua language | |
45 | - if( !$this->session->get('isAdminAuth') ) | |
46 | - { | |
47 | - return $this->response->redirect([ 'for' => 'admin_login' ]); | |
48 | - } | |
41 | + $titlecmp = function ($a, $b) { | |
42 | + return strcasecmp($a['title'], $b['title']); | |
43 | + }; | |
44 | + $lang_id = 1; // ua language | |
45 | + if( !$this->session->get('isAdminAuth') ) | |
46 | + { | |
47 | + return $this->response->redirect([ 'for' => 'admin_login' ]); | |
48 | + } | |
49 | 49 | |
50 | - if( $this->request->isPost() ) | |
50 | + if( $this->request->isPost() ) | |
51 | + { | |
52 | + | |
53 | + $data['name'] = $this->request->getPost('name', 'string', NULL ); | |
54 | + $data['code'] = $this->request->getPost('code', 'string', NULL ); | |
55 | + $data['start_date'] = $this->request->getPost('start_date'); | |
56 | + $data['end_date'] = $this->request->getPost('end_date'); | |
57 | + $data['single_use'] = $this->request->getPost('single_use'); | |
58 | + $data['discount'] = $this->request->getPost('discount', 'string', NULL ); | |
59 | + $data['description'] = $this->request->getPost('description'); | |
60 | + $data['catalog_ids'] = $this->request->getPost('catalog', 'string', NULL ); | |
61 | + $data['group_ids'] = $this->request->getPost('items', 'string', NULL ); | |
62 | + $data['all_items'] = $this->request->getPost('all_items', 'int', NULL); | |
63 | + $data['image'] = $this->uploadImage(); | |
64 | + | |
65 | + if( empty($this->models->getPromoCodes()->getPromoByCode( $data['code'] )[0]) ) | |
51 | 66 | { |
52 | - | |
53 | - $data['name'] = $this->request->getPost('name', 'string', NULL ); | |
54 | - $data['code'] = $this->request->getPost('code', 'string', NULL ); | |
55 | - $data['start_date'] = $this->request->getPost('start_date'); | |
56 | - $data['end_date'] = $this->request->getPost('end_date'); | |
57 | - $data['single_use'] = $this->request->getPost('single_use'); | |
58 | - $data['discount'] = $this->request->getPost('discount', 'string', NULL ); | |
59 | - $data['description'] = $this->request->getPost('description'); | |
60 | - $data['catalog_ids'] = $this->request->getPost('catalog', 'string', NULL ); | |
61 | - $data['group_ids'] = $this->request->getPost('items', 'string', NULL ); | |
62 | - $data['all_items'] = $this->request->getPost('all_items', 'int', NULL); | |
63 | - $data['image'] = $this->uploadImage(); | |
64 | - | |
65 | - if( empty($this->models->getPromoCodes()->getPromoByCode( $data['code'] )[0]) ) | |
67 | + if(!empty($data['group_ids']) && $this->models->getPromoCodes()->addData( $data )) | |
66 | 68 | { |
67 | - if(!empty($data['group_ids']) && $this->models->getPromoCodes()->addData( $data )) | |
68 | - { | |
69 | - $this->flash->success( 'Сохранение прошло успешно' ); | |
70 | - return $this->response->redirect([ 'for' => 'promo_codes_index' ]); | |
71 | - } | |
72 | - else | |
73 | - { | |
74 | - $this->flash->error( 'Выберите товары для промокода' ); | |
75 | - } | |
69 | + $this->flash->success( 'Сохранение прошло успешно' ); | |
70 | + return $this->response->redirect([ 'for' => 'promo_codes_index' ]); | |
76 | 71 | } |
77 | - else { | |
78 | - $this->flash->error('Такой промокод уже существует'); | |
72 | + else | |
73 | + { | |
74 | + $this->flash->error( 'Выберите товары для промокода' ); | |
79 | 75 | } |
80 | 76 | } |
77 | + else { | |
78 | + $this->flash->error('Такой промокод уже существует'); | |
79 | + } | |
80 | + } | |
81 | 81 | |
82 | - $catalog_temp = $this->common->getTypeSubtype1(NULL, $lang_id)['catalog']; | |
83 | - usort($catalog_temp, $titlecmp); | |
82 | + $catalog_temp = $this->common->getTypeSubtype1(NULL, $lang_id)['catalog']; | |
83 | + usort($catalog_temp, $titlecmp); | |
84 | 84 | |
85 | 85 | |
86 | - $this->view->setVar('catalog_temp', $catalog_temp); | |
87 | - $this->view->pick( 'promo_codes/addEdit' ); | |
88 | - } | |
86 | + $this->view->setVar('catalog_temp', $catalog_temp); | |
87 | + $this->view->pick( 'promo_codes/addEdit' ); | |
88 | +} | |
89 | 89 | |
90 | 90 | public function deleteAction($id) { |
91 | 91 | if( !$this->session->get('isAdminAuth') ) | ... | ... |