Commit f723ca003d934176d6650c5016eb735ffed648df
1 parent
b9ae3614
test
Showing
3 changed files
with
67 additions
and
0 deletions
Show diff stats
src/app/frontend/controllers/MenuController.php
| ... | ... | @@ -484,6 +484,13 @@ class MenuController extends \controllers\ControllerBase |
| 484 | 484 | 'count_items' => $count_items |
| 485 | 485 | ]; |
| 486 | 486 | $this->session->set( 'in_cart', $in_cart ); |
| 487 | + //save basket in DB | |
| 488 | + $data = [ | |
| 489 | + 'user_id' => $this->session->get('id'), | |
| 490 | + 'register' => $this->session->get('isAuth'), | |
| 491 | + 'letter' => '0' | |
| 492 | + ]; | |
| 493 | + $this->models->getBasket()->addData($data); | |
| 487 | 494 | |
| 488 | 495 | $count = count($in_cart); |
| 489 | 496 | } | ... | ... |
src/lib/models.php
| ... | ... | @@ -4,6 +4,9 @@ |
| 4 | 4 | |
| 5 | 5 | namespace |
| 6 | 6 | { |
| 7 | + | |
| 8 | + use models\basket; | |
| 9 | + | |
| 7 | 10 | /** |
| 8 | 11 | * models |
| 9 | 12 | * |
| ... | ... | @@ -54,6 +57,7 @@ namespace |
| 54 | 57 | protected $_manager_mail = false; |
| 55 | 58 | protected $_promo_to_user = false; |
| 56 | 59 | protected $_discount = false; |
| 60 | + protected $_basket = false; | |
| 57 | 61 | |
| 58 | 62 | |
| 59 | 63 | |
| ... | ... | @@ -650,6 +654,17 @@ namespace |
| 650 | 654 | |
| 651 | 655 | return $this->_promo_to_user; |
| 652 | 656 | } |
| 657 | + | |
| 658 | + public function getBasket() | |
| 659 | + { | |
| 660 | + if( empty($this->_basket) ) | |
| 661 | + { | |
| 662 | + $this->_basket = new basket(); | |
| 663 | + $this->_basket->setDi( $this->getDi() ); | |
| 664 | + } | |
| 665 | + | |
| 666 | + return $this->_discount; | |
| 667 | + } | |
| 653 | 668 | } |
| 654 | 669 | } |
| 655 | 670 | ... | ... |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Created by PhpStorm. | |
| 4 | + * User: Alex Savenko | |
| 5 | + * Date: 12.01.2017 | |
| 6 | + * Time: 12:59 | |
| 7 | + */ | |
| 8 | + | |
| 9 | +namespace models; | |
| 10 | + | |
| 11 | + | |
| 12 | +class basket extends \db | |
| 13 | +{ | |
| 14 | + public function addData($data) | |
| 15 | + { | |
| 16 | + | |
| 17 | + return $this->get( | |
| 18 | + ' | |
| 19 | + INSERT INTO | |
| 20 | + public.basket | |
| 21 | + ( | |
| 22 | + user_id, | |
| 23 | + register, | |
| 24 | + letter, | |
| 25 | + last_mod | |
| 26 | + ) | |
| 27 | + VALUES | |
| 28 | + ( | |
| 29 | + :user_id, | |
| 30 | + :register, | |
| 31 | + :letter, | |
| 32 | + CURRENT_TIMESTAMP | |
| 33 | + ) | |
| 34 | + RETURNING id | |
| 35 | + ', | |
| 36 | + [ | |
| 37 | + 'user_id' => $data['user_id'], | |
| 38 | + 'register' => $data['register'], | |
| 39 | + 'letter' => $data['letter'] | |
| 40 | + ], | |
| 41 | + -1 | |
| 42 | + ); | |
| 43 | + | |
| 44 | + } | |
| 45 | +} | |
| 0 | 46 | \ No newline at end of file | ... | ... |