Commit c99e7b14da846967d8d5b888015c19f13b8a9684
1 parent
24048434
debugging
Showing
2 changed files
with
28 additions
and
42 deletions
Show diff stats
src/app/frontend/controllers/MenuController.php
| ... | ... | @@ -476,7 +476,6 @@ class MenuController extends \controllers\ControllerBase |
| 476 | 476 | if( in_array( $item_id, $item_id_in_cart ) ) |
| 477 | 477 | { |
| 478 | 478 | die( json_encode( 0 ) ); |
| 479 | - //die( json_encode( [0, 'This item already is already in basket'] ) ); | |
| 480 | 479 | } |
| 481 | 480 | |
| 482 | 481 | $in_cart[] = |
| ... | ... | @@ -489,20 +488,14 @@ class MenuController extends \controllers\ControllerBase |
| 489 | 488 | $count = count($in_cart); |
| 490 | 489 | |
| 491 | 490 | //save basket in DB |
| 492 | - $user_id = $this->session->get('id'); | |
| 493 | 491 | if ($this->session->get('isAuth')) { |
| 494 | - $data = [ | |
| 495 | - 'user_id' => $user_id, | |
| 496 | - 'letter' => '0', | |
| 497 | - 'items' => $in_cart | |
| 498 | - ]; | |
| 499 | - $this->models->getBasket()->updateBasket($user_id, $data); | |
| 492 | + $user_id = $this->session->get('id'); | |
| 493 | + $this->models->getBasket()->updateBasket($user_id, $in_cart, 0); | |
| 500 | 494 | } |
| 501 | 495 | |
| 502 | 496 | } |
| 503 | 497 | |
| 504 | 498 | die (json_encode($count)); |
| 505 | - //die( json_encode('Count items in basket: '.$count) ); | |
| 506 | 499 | |
| 507 | 500 | } |
| 508 | 501 | |
| ... | ... | @@ -530,14 +523,9 @@ class MenuController extends \controllers\ControllerBase |
| 530 | 523 | $count = count($in_cart); |
| 531 | 524 | |
| 532 | 525 | //save basket in DB |
| 533 | - $user_id = $this->session->get('id'); | |
| 534 | 526 | if ($this->session->get('isAuth')) { |
| 535 | - $data = [ | |
| 536 | - 'user_id' => $user_id, | |
| 537 | - 'letter' => '0', | |
| 538 | - 'items' => $in_cart | |
| 539 | - ]; | |
| 540 | - $this->models->getBasket()->updateBasket($user_id, $data); | |
| 527 | + $user_id = $this->session->get('id'); | |
| 528 | + $this->models->getBasket()->updateBasket($user_id, $in_cart, 0); | |
| 541 | 529 | } |
| 542 | 530 | } |
| 543 | 531 | |
| ... | ... | @@ -565,15 +553,11 @@ class MenuController extends \controllers\ControllerBase |
| 565 | 553 | } |
| 566 | 554 | |
| 567 | 555 | $this->session->set( 'in_cart', $in_cart ); |
| 556 | + | |
| 568 | 557 | //save basket in DB |
| 569 | - $user_id = $this->session->get('id'); | |
| 570 | 558 | if ($this->session->get('isAuth')) { |
| 571 | - $data = [ | |
| 572 | - 'user_id' => $user_id, | |
| 573 | - 'letter' => '0', | |
| 574 | - 'items' => $in_cart | |
| 575 | - ]; | |
| 576 | - $this->models->getBasket()->updateBasket($user_id, $data); | |
| 559 | + $user_id = $this->session->get('id'); | |
| 560 | + $this->models->getBasket()->updateBasket($user_id, $in_cart, 0); | |
| 577 | 561 | } |
| 578 | 562 | } |
| 579 | 563 | ... | ... |
src/lib/models/basket.php
| ... | ... | @@ -217,15 +217,19 @@ class basket extends \db |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
| 220 | - * @param array $data | |
| 220 | + * @param int $user_id | |
| 221 | + * @param array $items | |
| 222 | + * @param bool $letter | |
| 221 | 223 | * @return string |
| 222 | 224 | */ |
| 223 | - public function addData($data) { | |
| 225 | + public function addData($user_id, $items, $letter) { | |
| 224 | 226 | |
| 225 | - $query_basket = $this->addUser($data['user_id'], $data['letter']); | |
| 227 | + $query_basket = $this->addUser($user_id, $letter); | |
| 228 | + | |
| 229 | + foreach ($items as $item) { | |
| 230 | + | |
| 231 | + $this->addItem($user_id, $item['item_id'], $item['count_items']); | |
| 226 | 232 | |
| 227 | - foreach ($data['items'] as $item) { | |
| 228 | - $this->addItem($data['user_id'], $item['item_id'], $item['count_items']); | |
| 229 | 233 | } |
| 230 | 234 | |
| 231 | 235 | return 'User #'.$query_basket[0]['user_id'].' added'; |
| ... | ... | @@ -233,40 +237,38 @@ class basket extends \db |
| 233 | 237 | } |
| 234 | 238 | |
| 235 | 239 | /** |
| 236 | - * @param $data | |
| 237 | - * @return string | |
| 240 | + * @param int $user_id | |
| 241 | + * @param array $items | |
| 242 | + * @param bool $letter | |
| 243 | + * @return string | |
| 238 | 244 | */ |
| 239 | - public function updateData($data) { | |
| 245 | + public function updateData($user_id, $items, $letter) { | |
| 240 | 246 | |
| 241 | 247 | //update user last mod |
| 242 | - $query_basket = $this->updateUser($data['user_id'], $data['letter']); | |
| 248 | + $query_basket = $this->updateUser($user_id, $letter); | |
| 243 | 249 | |
| 244 | 250 | //clear deprecated items |
| 245 | - $this->deleteAllItems($data['user_id']); | |
| 251 | + $this->deleteAllItems($user_id); | |
| 246 | 252 | |
| 247 | - foreach ($data['items'] as $item) { | |
| 253 | + foreach ($items as $item) { | |
| 248 | 254 | |
| 249 | 255 | //add items 1 by 1 |
| 250 | - $this->addItem($data['user_id'], $item['item_id'], $item['count_items']); | |
| 256 | + $this->addItem($user_id, $item['item_id'], $item['count_items']); | |
| 251 | 257 | |
| 252 | 258 | } |
| 253 | 259 | return 'User #'.$query_basket[0]['user_id'].' updated'; |
| 254 | 260 | } |
| 255 | 261 | |
| 256 | - /** | |
| 257 | - * @param $user_id | |
| 258 | - * @param $data | |
| 259 | - */ | |
| 260 | - public function updateBasket($user_id, $data) { | |
| 262 | + public function updateBasket($user_id, $items, $letter) { | |
| 261 | 263 | |
| 262 | 264 | if ($this->checkUserExist($user_id)) { |
| 263 | 265 | |
| 264 | - $this->updateData($data); | |
| 266 | + $this->updateData($user_id, $items, $letter); | |
| 265 | 267 | |
| 266 | 268 | } |
| 267 | 269 | else { |
| 268 | 270 | |
| 269 | - $this->addData($data); | |
| 271 | + $this->addData($user_id, $items, $letter); | |
| 270 | 272 | |
| 271 | 273 | } |
| 272 | 274 | ... | ... |