E
E
Evgeny Startsev2018-02-16 16:28:25
MySQL
Evgeny Startsev, 2018-02-16 16:28:25

What's with the db glitch?

Hello everyone
Such a moment, there is a store. The client placed an order - added goods to the basket and proceeded to checkout. And here is the most interesting thing ...
ajax passed the data from the form, formed an array to fill in the order, but the order itself (the record in the table) remained unchanged
after sending a message (smtp received a new order) and returned the result true
and info was sent to the mail - the order is new - the order number is null, the price is 0, the customer is the data from the form...
Moreover, when placing an order, you can immediately register and looking at the table in the database, the registration was successful, there is a record and the date of registration coincides with the date of placing the order...
Order not the first, but already the 2314th (by id) ...
But such a glitch is the first
design code itself

<?php 
  $name = $request->get('name');
  $email = $request->get('email');
  $phone = $request->get('phone');
  $reg = (int)$request->get('registration');
    
  $city = $request->get('city');
  $street = $request->get('street');
  $home = $request->get('home');
  $housing = $request->get('housing');
  $apartment = $request->get('apartment');
  
  $comment = $request->get('message');
    
  // если клиент хочет зарегистрироватся
  if($reg==1)
  {
    $password = $request->get('password');
    
    $userModel = new User();
    
    $resEmail = $userModel->getClientEmail($email);
    
    if(isset($resEmail['email']))// а такой емаил есть в бд...
    {
      return json_encode(['result'=>false]);  
    }
    
    $dataUserUpdate = [
      'name' => $name,
      'login' => $email,
      'email' => $email,
      'phone' => $phone,
      'password' => bcrypt($password),
      'active' => 1,
      'created_at'=>date('Y-m-d H:i:s')
    ];
    
    $userModel->updateClient($_SESSION['client_id'], $dataUserUpdate);
    
    $clAdModel = new ClientsAdress();
      
      $dataAdres = [
        'client_id'=>$_SESSION['client_id'],
        'main'=>1,
        'city'=>$city,
        'street'=>$street,
        'home'=>$home,
        'housing'=>$housing,
        'apartment'=>$apartment,
      ];
      
      $clAdModel->addAdress($dataAdres);
      
      $message = "Здравствуйте,
        
      Ваши учетные данные для доступа к сайту

      Логин: {$email}
      Пароль: {$password}

      ---
      С Уважением";
          
      Mailsend::sendEmail('Ваш доступ к сайту', $message, $email);
  }
    
    $other = 'Оплата: ' . $request->get('payment');
    $other .= "\nДоставка: ";
    
    // какая доставка выбрана
    $delivery = (int)$request->get('delivery');
    
    if($delivery == 2)
    {
      $other .= 'Курьерская доставка по СПб';
    }
    else if($delivery == 3)
    {
      $other .= 'Самовывоз';
    }
    else
    {
      $other .= 'Доставка по Ленобласти и РФ';
    }
    
    $message = $other . "\nКомментарий: ".$comment;
    
    $adress = 'Город: '.$city."\n".
    'Улица: '.$street."\n".
    'Дом: '.$home."\n".
    'Корпус: '.$housing."\n".
    'Квартира: '.$apartment;
    
    // получаем список продуктов из корзины через сессию
    $cartModel = new Cart();
    
    $prodts = $cartModel->getAllCart($_SESSION['client_id']);
    
    $total = 0;
    $messageMail = '';
    $prodmes2 = '';
    
    //формируем стоимость и скидки а также месседж в почту
    foreach($prodts as $row)
    {
      $total += $row->price * $row->count_prod;
      
      $messageMail .= $row->name . " - " . ($row->count_prod/10) . " кг \n";
      
      $prodmes2 .= $row->name . ' - ' . ($row->count_prod/10) . ' кг ' . ' - ' . ($row->price * $row->count_prod) . " руб.\n";
      
      $cartModel->updateProdID($row->cart_id, $row->prod_id,$row->count_prod,$row->price);
    }
    
    $priceDostavka = ($total < 3000 && $delivery == 2) ? 250 : 0;
    
    //обновили корзину
    $order = $cartModel->updateCart($_SESSION['client_id'], $message, $phone, $total, $adress, $name, $email, $priceDostavka,);

    $messageMail .= "-------------
Сумма заказа - {$total} руб.
Мы свяжемся с Вами ближайшее время\n
---
С Уважением";

$messageMail = "Здравствуйте,

Спасибо за Ваш заказ!
Заказ #{$order}
Состав:
-------------\n" . $messageMail;
    if($email != '')
    {
      Mailsend::sendEmail('Ваш заказ #'.$order.' на сайте', $messageMail, $email);
    }
    
    $messageMail2 = "---------------------
Заказ - {$order}
Сумму - {$total} руб.
Клиент - {$email}
Телефон - {$phone}
Комментарий - {$comment}
Дата заказа - ".date('d,m,Y H:i')."
Адрес: {$adress}
---------------------\n".$prodmes2;
    
    Mailsend::sendEmail('Заказ - '.$order, $messageMail2, '[email protected]');
    
    return json_encode(['result'=>true);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Станислав Б, 2018-02-16
@S_Borchev

//обновили корзину
    $order = $cartModel->updateCart($_SESSION['client_id'], $message, $phone, $total, $adress, $name, $email, $priceDostavka,);

запятая в конце? это правда парсеррор, тогда бы вообще не работало.
а так копайте начиная от $prodts = $cartModel->getAllCart($_SESSION['client_id']);
оттуда пустой массив получили

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question