Commit dd724469d4d3be20f8562f837ebf4f4510bfca86
1 parent
d95a040a
vip prices tests
Showing
2 changed files
with
13 additions
and
1 deletions
Show diff stats
src/app/frontend/controllers/MenuController.php
... | ... | @@ -414,7 +414,7 @@ class MenuController extends \controllers\ControllerBase |
414 | 414 | //vip |
415 | 415 | $users_group_id = $this->session->get('users_group_id'); |
416 | 416 | if (isset($users_group_id) && $users_group_id == 37) { |
417 | - if ($this->common->applyPromoCode(5, $cart_items['items'])) { | |
417 | + if ($this->common->applyDiscount(5, $cart_items['items'])) { | |
418 | 418 | $this->common->countOrderSum($cart_items); |
419 | 419 | $cart_items['total_price'] = $cart_items['total_sum']; |
420 | 420 | } | ... | ... |
src/lib/common.php
... | ... | @@ -1335,6 +1335,18 @@ namespace |
1335 | 1335 | public function parseArray($str) { |
1336 | 1336 | return explode(',', preg_replace('[{|}]', '' , $str)); |
1337 | 1337 | } |
1338 | + | |
1339 | + public function applyDiscount($discount_value, &$items) { | |
1340 | + if (empty($discount_value) || $discount_value < 0 || $discount_value > 100) { | |
1341 | + return false; | |
1342 | + } | |
1343 | + foreach($items as $k => $item) { | |
1344 | + $items[$k]['price2'] = number_format($item['price2'] - ($item['price2'] * $discount_value / 100), 1, '.', ''); | |
1345 | + $items[$k]['total_price'] = number_format($items[$k]['price2'] * $item['count'], 1, '.', ''); | |
1346 | + } | |
1347 | + return true; | |
1348 | + } | |
1349 | + | |
1338 | 1350 | } |
1339 | 1351 | } |
1340 | 1352 | ... | ... |