Commit 4f14e82f106f4d33ed2e876d02e3b51469be0746
Merge branch 'discount' of gitlab.artweb.com.ua:Alex/semena
Conflicts: src/app/frontend/controllers/PageController.php
Showing
2 changed files
with
30 additions
and
2 deletions
Show diff stats
src/app/frontend/controllers/PageController.php
| ... | ... | @@ -135,8 +135,9 @@ |
| 135 | 135 | $timestamp_left = $left_date->getTimestamp(); |
| 136 | 136 | $active_sales[$k]['seconds_left'] = $timestamp_left - $now; |
| 137 | 137 | } |
| 138 | - | |
| 139 | - $discount = $this->models->getDiscount()->getOneData(4); | |
| 138 | + | |
| 139 | + $discount = $this->models->getDiscount()->getActiveData(); | |
| 140 | + | |
| 140 | 141 | $discount = $discount[0]['discount']; |
| 141 | 142 | |
| 142 | 143 | $css = [ | ... | ... |
src/lib/models/discount.php
| ... | ... | @@ -55,6 +55,33 @@ class discount extends \db |
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | + * Get actual discount | |
| 59 | + * @param $id | |
| 60 | + * @return array | |
| 61 | + */ | |
| 62 | + public function getActiveData($id) | |
| 63 | + { | |
| 64 | + return $this->get( | |
| 65 | + ' | |
| 66 | + SELECT * | |
| 67 | + FROM public.discount | |
| 68 | + WHERE | |
| 69 | + id = :id | |
| 70 | + AND | |
| 71 | + current_timestamp > start_date | |
| 72 | + AND | |
| 73 | + current_timestamp < end_date | |
| 74 | + | |
| 75 | + ', | |
| 76 | + [ | |
| 77 | + 'id' => $id | |
| 78 | + ], | |
| 79 | + -1 | |
| 80 | + ); | |
| 81 | + } | |
| 82 | + | |
| 83 | + | |
| 84 | + /** | |
| 58 | 85 | * Delete discount with `id`=$id |
| 59 | 86 | * @param $id |
| 60 | 87 | * @return bool | ... | ... |