Commit 6a2e27dbaacb8bf70dd1e50fa0ec373bd9361af3

Authored by Alex Savenko
1 parent 817a8c23

price display basket

src/app/frontend/controllers/MenuController.php
... ... @@ -17,25 +17,22 @@ class MenuController extends \controllers\ControllerBase
17 17 return $this->response->redirect('dealer/cart');
18 18 }
19 19  
20   - $lang_url = $this->seoUrl->getChangeLangUrl();
21   - $in_cart = $this->session->get('in_cart', []);
22   - $customer_id = $this->session->get('id');
23   - $customer_email = $this->session->get('customer_email');
24   -
  20 + $lang_url = $this->seoUrl->getChangeLangUrl();
  21 + $in_cart = $this->session->get('in_cart', []);
  22 + $customer_id = $this->session->get('id');
  23 + $customer_email = $this->session->get('customer_email');
25 24 $session_promo_code = $this->session->get('promo_code');
  25 + $customer = !empty( $customer_id ) ? $this->models->getCustomers()->getCustomer( $customer_id ) : [];
26 26  
27   - $customer = !empty( $customer_id ) ? $this->models->getCustomers()->getCustomer( $customer_id ) : [];
28   - $this->session->set( 'return_url', 'basket' ); // для redirect после авторизации на соц сетях
  27 + $this->session->set( 'return_url', 'basket' ); // для redirect после авторизации на соц сетях
29 28  
30   - $items = [];
31   - $total_price = 0;
32   - $err = 0;
33   -
34   - $cities_ = $this->novaposhta->city();
  29 + $items = [];
  30 + $total_price = 0;
  31 + $err = 0;
  32 + $cities_ = $this->novaposhta->city();
35 33  
36 34 foreach( $cities_->item as $c )
37 35 {
38   -
39 36 $cities[strval($c->CityID)] = strval($c->Description);
40 37 }
41 38  
... ... @@ -43,24 +40,36 @@ class MenuController extends \controllers\ControllerBase
43 40 {
44 41 $cart = $this->common->getCartItems($in_cart, $this->lang_id);
45 42  
  43 + //promocode
46 44 if(!empty($session_promo_code)) {
47 45 if($this->common->applyPromoCode($session_promo_code, $cart['items'])) {
48 46 $this->common->countOrderSum($cart);
49 47 $cart['total_price'] = $cart['total_sum'];
50 48 }
51 49 }
52   - $total_price = $cart['total_price'];
53   - $items = $cart['items'];
54   - $items_ = $cart['items_'];
55 50  
56   - }
  51 + //discount
  52 + $discount = $this->getDi()->get('models')->getDiscount()->getActiveData();
  53 + if (!empty($discount)) {
  54 + $discount = $discount[0];
  55 + $discount['group_ids'] = str_replace('{', '', $discount['group_ids']);
  56 + $discount['group_ids'] = str_replace('}', '', $discount['group_ids']);
  57 + $discount['group_ids'] = explode(',', $discount['group_ids']);
  58 + }
  59 + if ($this->common->applyPromoCode($discount, $cart['items'])) {
  60 + $this->common->countOrderSum($cart);
  61 + $cart['total_price'] = $cart['total_sum'];
  62 + }
57 63  
  64 + $total_price = $cart['total_price'];
  65 + $items = $cart['items'];
  66 + $items_ = $cart['items_'];
  67 + }
58 68  
59 69 if ( $this->request->isPost() )
60 70 {
61 71 $order['email'] = $this->request->getPost('login_email', 'string', NULL );
62 72 $order['passwd'] = $this->request->getPost('login_passwd', 'string', NULL );
63   -
64 73 $promo_code = $this->request->getPost('promo_code', 'string', NULL );
65 74  
66 75 if(empty($session_promo_code)) {
... ... @@ -73,8 +82,8 @@ class MenuController extends \controllers\ControllerBase
73 82  
74 83 $order_items = $this->request->getPost('count_items', NULL, [] );
75 84 $order_color = $this->request->getPost('color', NULL, [] );
76   - $order_size = $this->request->getPost('size', NULL, [] );
77   - $order_is = $this->request->getPost('is', NULL, [] );
  85 + $order_size = $this->request->getPost('size', NULL, [] );
  86 + $order_is = $this->request->getPost('is', NULL, [] );
78 87 $order['total_sum'] = 0;
79 88  
80 89 foreach( $order_items as $key => $val )
... ... @@ -83,15 +92,12 @@ class MenuController extends \controllers\ControllerBase
83 92 $items_[$key]['total_price'] = round($val*$items_[$key]['price2'], 1);
84 93  
85 94 if(isset($order_color[$key]))
86   - $items_[$key]['color'] = $order_color[$key];
  95 + $items_[$key]['color'] = $order_color[$key];
87 96  
88   - $items_[$key]['size'] = $order_size[$key];
89   - $items_[$key]['is'] = $order_is[$key];
90   -
  97 + $items_[$key]['size'] = $order_size[$key];
  98 + $items_[$key]['is'] = $order_is[$key];
91 99 $order['items'][] = $items_[$key];
92 100 $order['total_sum'] += $items_[$key]['total_price'];
93   -
94   -
95 101 $item_id_in_cart = $this->common->array_column( $in_cart, 'item_id' );
96 102  
97 103 if( in_array( $key, $item_id_in_cart ) )
... ... @@ -106,9 +112,10 @@ class MenuController extends \controllers\ControllerBase
106 112 }
107 113 }
108 114  
109   - $order['total_sum'] = round( $order['total_sum'], 1 );
  115 + $order['total_sum'] = round( $order['total_sum'], 1 );
110 116  
111 117 $this->session->set( 'in_cart', $in_cart );
  118 +
112 119 if ( !empty( $order['email'] ) && !empty( $order['passwd'] ) )
113 120 {
114 121  
... ... @@ -130,8 +137,6 @@ class MenuController extends \controllers\ControllerBase
130 137 $this->flash->success($this->languages->getTranslation()->_("please_change_the_password"));
131 138 $this->session->set( 'customer_email', $order['email'] );
132 139 return $this->response->redirect([ 'for' => 'finish_registration', 'language' => $this->lang_name ]);
133   -
134   -
135 140 }
136 141 }
137 142  
... ... @@ -251,7 +256,6 @@ class MenuController extends \controllers\ControllerBase
251 256 return $this->response->redirect([ 'for' => 'basket', 'language' => $this->lang_name ]);
252 257 }
253 258 }
254   -
255 259 }
256 260  
257 261 $static_page_alias = '/basket'. $this->lang_name;
... ...
src/lib/common.php
... ... @@ -1229,24 +1229,23 @@ namespace
1229 1229 }
1230 1230  
1231 1231 public function getCartItems($in_cart, $lang_id, $special_user = null) {
1232   - $result = [];
1233   - $total_price = 0;
1234   - $item_ids = $this->array_column( $in_cart, 'item_id' );
1235   - $items = $this->getDi()->get('models')->getItems()->getItemsByIds( $lang_id, $item_ids );
1236   - $groups_ids = $this->array_column( $items, 'group_id' );
1237   - $groups_data = $this->getDi()->get('models')->getItems()->getItemsByColorAndGroupsId(join(',',$groups_ids));
1238   - $colors = array_unique($this->array_column( $groups_data, 'color_id' ));
1239   - $color_info = $this->getDi()->get('models')->getItems()->getColorsInfoByColorsId( $lang_id, join(',',$colors) );
  1232 + $result = [];
  1233 + $total_price = 0;
  1234 + $item_ids = $this->array_column( $in_cart, 'item_id' );
  1235 + $items = $this->getDi()->get('models')->getItems()->getItemsByIds( $lang_id, $item_ids );
  1236 + $groups_ids = $this->array_column( $items, 'group_id' );
  1237 + $groups_data = $this->getDi()->get('models')->getItems()->getItemsByColorAndGroupsId(join(',',$groups_ids));
  1238 + $colors = array_unique($this->array_column( $groups_data, 'color_id' ));
  1239 + $color_info = $this->getDi()->get('models')->getItems()->getColorsInfoByColorsId( $lang_id, join(',',$colors) );
  1240 +
1240 1241 foreach($color_info as $k =>$v){
1241 1242 $colors_info[$v['id']] = $v;
1242 1243 }
1243 1244  
1244   -
1245 1245 foreach($groups_data as $k =>$v){
1246 1246 if($groups_data[$k]['color_id'] != 0){
1247 1247 $groups_data[$k]['color'] = $colors_info[$groups_data[$k]['color_id']]['color_title'];
1248 1248 $groups_data[$k]['absolute_color'] = $colors_info[$groups_data[$k]['color_id']]['absolute_color'];
1249   -
1250 1249 } else {
1251 1250 $groups_data[$k]['color'] = 0;
1252 1251 $groups_data[$k]['absolute_color'] = 0;
... ... @@ -1257,9 +1256,7 @@ namespace
1257 1256 $groups_data[$v['id']] = $v;
1258 1257 }
1259 1258  
1260   - foreach ( $in_cart as $c )
1261   - {
1262   -
  1259 + foreach ( $in_cart as $c ) {
1263 1260 $count_item[$c['item_id']] = $c['count_items'];
1264 1261 }
1265 1262  
... ... @@ -1269,14 +1266,9 @@ namespace
1269 1266 }
1270 1267 }
1271 1268  
1272   -
1273   -
1274   - foreach ( $items as $k => $i )
1275   - {
1276   - $items[$k]['cover'] = !empty( $i['group_cover'] ) ? $this->getDi()->get('storage')->getPhotoUrl( $i['item_cover'], 'avatar', '128x' ) : '/images/packet.jpg';
1277   - $items[$k]['alias'] = $this->getDi()->get('url')->get([ 'for' => 'item', 'subtype' => $i['catalog_alias'], 'group_alias' => $i['group_alias'], 'item_id' => $i['id'] ]);
1278   -
1279   -
  1269 + foreach ( $items as $k => $i ) {
  1270 + $items[$k]['cover'] = !empty( $i['group_cover'] ) ? $this->getDi()->get('storage')->getPhotoUrl( $i['item_cover'], 'avatar', '128x' ) : '/images/packet.jpg';
  1271 + $items[$k]['alias'] = $this->getDi()->get('url')->get([ 'for' => 'item', 'subtype' => $i['catalog_alias'], 'group_alias' => $i['group_alias'], 'item_id' => $i['id'] ]);
1280 1272  
1281 1273 if(isset($i['prices'][0])) {
1282 1274 $items[$k]['total_price'] = round($count_item[$i['id']] * $i['prices'][$special_user['status']], 2);
... ... @@ -1285,24 +1277,25 @@ namespace
1285 1277 $items[$k]['total_price'] = round($count_item[$i['id']] * $i['price2'], 2);
1286 1278 }
1287 1279  
1288   - $items[$k]['count'] = $count_item[$i['id']];
1289   - $total_price += $items[$k]['total_price'];
1290   - $items[$k]['color'] = $groups_data[$i['id']]['color'];
1291   - $items[$k]['absolute_color'] = $groups_data[$i['id']]['absolute_color'];
1292   - $items_[$i['id']] = $items[$k];
  1280 + $items[$k]['count'] = $count_item[$i['id']];
  1281 + $total_price += $items[$k]['total_price'];
  1282 + $items[$k]['color'] = $groups_data[$i['id']]['color'];
  1283 + $items[$k]['absolute_color'] = $groups_data[$i['id']]['absolute_color'];
  1284 + $items_[$i['id']] = $items[$k];
1293 1285 }
1294 1286  
1295   - $total_price = round( $total_price, 2 );
  1287 + $total_price = round( $total_price, 2 );
  1288 + $result['total_price'] = $total_price;
  1289 + $result['items'] = $items;
  1290 + $result['items_'] = $items_;
1296 1291  
1297   - $result['total_price'] = $total_price;
1298   - $result['items'] = $items;
1299   - $result['items_'] = $items_;
1300 1292 return $result;
1301 1293 }
1302 1294  
1303   - public function countOrderSum(&$order) {
  1295 + public function countOrderSum(&$order)
  1296 + {
1304 1297 $sum = 0;
1305   - foreach($order['items'] as $k => $item) {
  1298 + foreach ($order['items'] as $k => $item) {
1306 1299 $sum += $item['total_price'];
1307 1300 }
1308 1301 $order['total_sum'] = $sum;
... ...