Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.94 KB | None | 0 0
  1. <?php
  2.     require_once 'core/init.php';
  3.     include 'includes/head.php';
  4.     include 'includes/navigation.php';
  5.     include 'includes/headerpartial.php';
  6.    
  7.     if($cart_id != '') {
  8.         $cartQ = $db->query("SELECT * FROM cart WHERE id = '{$cart_id}'");
  9.         $result = mysqli_fetch_assoc($cartQ);
  10.         $items = json_decode($result['items'],true);
  11.         $i = 1;
  12.         $sub_total = 0;
  13.         $item_count = 0;
  14.     }
  15. ?>
  16.    
  17.    
  18.     <div class="col-md-12">
  19.         <div class="row">
  20.             <h2 class="text-center">Моя корзина</h2><hr>
  21.             <?php if($cart_id == ''): ?>
  22.             <div class="bg-danger">
  23.                 <p class="text-center text-danger">
  24.                     Ваша корзина пуста!
  25.                 </p>
  26.             </div>
  27.             <?php else: ?>
  28.             <table class="table table-bordered table-condensed table-striped">
  29.                 <thead><th>#</th><th>Наименование</th><th>Цена</th><th>Количество</th><th>Общая стоимость</th></thead>
  30.                 <tbody>
  31.                     <?php
  32.                         foreach($items as $item) {
  33.                             $product_id = $item['id'];
  34.                             $productQ = $db->query("SELECT * FROM products WHERE id = '{$product_id}'");
  35.                             $product = mysqli_fetch_array($productQ);
  36.                             ?>
  37.                            
  38.                             <tr>
  39.                                 <td><?=$i; ?></td>
  40.                                 <td><?=$product['title'];?></td>
  41.                                 <td><?=number_format($product['list_price']).' рублей'; ?></td>
  42.                                 <td>
  43.                                     <button class="btn btn-xs btn-default" onclick="update_cart('removeone','<?=$product['id']; ?>');">-</button>
  44.                                     <?=$item['quantity']; ?>
  45.                                     <?php if($item['quantity'] < 999): ?>
  46.                                     <button class="btn btn-xs btn-default" onclick="update_cart('addone','<?=$product['id']; ?>');">+</button>
  47.                                     <?php else: ?>
  48.                                     <span class="text-danger">Max!</span>
  49.                                     <?php endif; ?>
  50.                                     </td>
  51.                                 <td><?=number_format($item['quantity'] * $product['list_price']).' рублей'; ?></td>
  52.                             </tr>
  53.                            
  54.                             <?php
  55.                                 $i++;
  56.                                 $item_count += $item['quantity'];
  57.                                 $sub_total += ($product['list_price'] * $item['quantity']);
  58.                                
  59.                                 }
  60.                                 $grand_total = $sub_total;
  61.                                 ?>
  62.                 </tbody>
  63.             </table>
  64.                
  65.                 <legend>Итог:</legend>
  66.                
  67.            
  68.             <table class="table table-bordered table-condensed text-right">
  69.                 <thead class="totals-table-header"><th>Всего товаров</th><th>К оплате</th></thead>
  70.                 <tbody>
  71.                     <tr>
  72.                         <td><?=$item_count.' ед.'; ?></td>
  73.                         <td class="bg-success"><?=number_format($grand_total).' рублей'; ?></td>
  74.                     </tr>
  75.                 </tbody>
  76.             </table>
  77.  
  78.                     <!-- Оформление заказа -->
  79.         <button type="button" class="btn btn-primary pull-right" data-toggle="modal" data-target="#checkoutModal">
  80.          <span class="glyphicon glyphicon-shopping-cart"></span> Оформить заказ >>
  81.         </button>
  82.        
  83.         <!-- Modal -->
  84.         <div class="modal fade" id="checkoutModal" tabindex="-1" role="dialog" aria-labelledby="checkoutModalLabel">
  85.           <div class="modal-dialog modal-lg" role="document">
  86.             <div class="modal-content">
  87.               <div class="modal-header">
  88.                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  89.                 <h4 class="modal-title" id="checkoutModalLabel">Оформление заказа</h4>
  90.               </div>
  91.               <div class="modal-body">
  92.                  
  93.                   <script type='text/javascript'>
  94.                         <!--
  95.                         function showhideBlocks(val){
  96.                                 if (val == 0){
  97.                                     document.getElementById('i1').style.display='none';                                
  98.                                 }
  99.                                 else{
  100.                                    document.getElementById('i1').style.display='none';                                    
  101.                                    document.getElementById('i'+val).style.display='block';  
  102.                                 }  
  103.                         }
  104.                         -->
  105.                 </script>
  106.                 <style type='text/css'>
  107.                         #i1,#i2,#i3{display:none}      
  108.                 </style>
  109.  
  110.                  
  111.                 <div class="row">
  112.                      
  113.                    
  114.                 <form action="https://demomoney.yandex.ru/eshop.xml" method="post" id="payment-form">
  115.                     <span id="payment-errors"></span>
  116.                     <input type="hidden" name="sub_total" value="<?=$sub_total;?>">
  117.                     <input type="hidden" name="grand_total" value="<?=$grand_total;?>">
  118.                     <input type="hidden" name="cart_id" value="<?=$cart_id;?>">
  119.                    
  120.                     <input name="shopId" value="129299" type="hidden">
  121.                     <input name="scid" value="551452" type="hidden">
  122.                    
  123.                     <input name="customerNumber" value="<?=$cart_id?>" type="hidden">                  
  124.                     <input name="sum" value="<?=$sub_total;?>" type="hidden">
  125.                     <input type="hidden" name="items" value="<?=$result['items']; ?>">             
  126.                     <input type="hidden" name="description" value="<?=$item_count.' item'.(($item_count>1)?'s':'').' from Florentis.';?>">
  127.                    
  128.                     <div id="step1" style="display:block">
  129.                         <div class="form-group col-md-6">
  130.                             <label for="full_name">ФИО<span class="redStar">*</span>:</label>
  131.                             <input type="text" class="form-control" id="full_name" name="full_name">
  132.                         </div>
  133.                         <div class="form-group col-md-6">
  134.                             <label for="email">Email<span class="redStar">*</span>:</label>
  135.                             <input type="email" class="form-control" id="email" name="email">
  136.                         </div>
  137.                         <div class="form-group col-md-6">
  138.                             <label for="phone">Телефон<span class="redStar">*</span>:</label>
  139.                             <input type="text" class="form-control" id="phone" name="phone">
  140.                         </div>
  141.                        
  142.                         <div class="form-group col-md-6">
  143.                             <label for="notation">Комментарий:</label>
  144.                             <input type="text" class="form-control" id="notation" name="notation">
  145.                         </div>
  146.                         <div class="form-group col-md-6">
  147.                             <label for="delivery">Способ доставки<span class="redStar">*</span>:</label>
  148.                             <select class="form-control" id="delivery" name="delivery" onchange="showhideBlocks(this.value)">
  149.                                 <option>-Выберите способ доставки-</option>
  150.                                 <option value="1">Самовывоз</option>
  151.                                 <option value="1">Доставка курьером</option>
  152.                             </select>
  153.                         </div>
  154.                              
  155.                    
  156.                         <div class="form-group col-md-6">
  157.                             <label for="recipient">Получатель<span class="redStar">*</span>:</label>
  158.                             <select class="form-control" id="recipient" name="recipient">
  159.                                 <option>-Выберите получателя-</option>
  160.                                 <option>Получаю сам(а)</option>
  161.                                 <option>Получает другой человек</option>
  162.                             </select><br><br>                          
  163.                          </div>
  164.                          
  165.                          
  166.                          <div id="i1">
  167.                         <div class="modal-header">
  168.                 <h4 class="modal-title" id="checkoutModalLabel">Информация о получателе</h4>
  169.                         </div>
  170.                                                      <div class="modal-body">                
  171.                                             <div class="form-group col-md-6">
  172.                                                <label for="full_name2">ФИО получателя<span class="redStar">*</span>:</label>
  173.                                                <input type="text" class="form-control" id="full_name2" name="full_name2">
  174.                                             </div>
  175.                                            
  176.                                             <div class="form-group col-md-6">
  177.                                                <label for="phone2">Телефон получателя<span class="redStar">*</span>:</label>
  178.                                                <input type="text" class="form-control" id="phone2" name="phone2">
  179.                                             </div>
  180.                                            
  181.                                              <div class="form-group col-md-6">
  182.                                                <label for="street">Адрес доставки<span class="redStar">*</span>:</label>
  183.                                                <input type="text" class="form-control" id="street" name="street">
  184.                                             </div>
  185.  
  186.                                 </div>
  187.                          </div>
  188.                            
  189.                     </div>
  190.                    
  191.                    
  192.                     <div id="step2" style="display:none">
  193.                         <div class="form-group col-md-3">
  194.                             <label for="name">Выберите способ оплаты:<span class="redStar">*</span>:</label>
  195.                             <input type="radio" name="pay-method" id="pay-method" value="Оплата при получении"> Оплата при получении<br>
  196.                             <input type="radio" name="pay-method" id="pay-method" value="Оплата через платежную систему"> Оплата по карте<br>
  197.  
  198.                         </div>
  199.                        
  200.                        
  201.                     </div>  
  202.                 </div>             
  203.               </div>
  204.                        
  205.               <div class="modal-footer">
  206.                 <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
  207.                 <button type="button" class="btn btn-primary" onclick="check_address();" id="next_button">Далее >></button>
  208.                 <button type="button" class="btn btn-primary" onclick="back_address();" id="back_button" style="display:none;">Назад</button>
  209.                 <button type="submit" class="btn btn-primary" id="checkout_button" style="display:none;">Отправить заказ >></button>
  210.                
  211.    
  212.                
  213.                    </form>
  214.                    
  215.          
  216.              
  217.               </div>
  218.             </div>
  219.           </div>
  220.         </div>
  221.  
  222.             <?php endif; ?>
  223.         </div>
  224.     </div>
  225.    
  226.    
  227.    
  228.     <script>
  229.        
  230.         function back_address() {
  231.             jQuery('#payment-errors').html("");
  232.             jQuery('#payment-errors').html("");
  233.             jQuery('#step1').css("display","block");
  234.             jQuery('#step2').css("display","none");
  235.             jQuery('#next_button').css("display","inline-block");
  236.             jQuery('#back_button').css("display","none");
  237.             jQuery('#checkout_button').css("display","none");
  238.             jQuery('#checkoutModalLabel').html("Оформление заказа");
  239.         }
  240.        
  241.        
  242.         function check_address(){
  243.             var data = {
  244.                 'full_name' : jQuery('#full_name').val(),
  245.                 'full_name2' : jQuery('#full_name2').val(),
  246.                 'email' : jQuery('#email').val(),
  247.                 'phone' : jQuery('#phone').val(),
  248.                 'phone2' : jQuery('#phone2').val(),
  249.                 'street' : jQuery('#street').val(),
  250.                
  251.             };
  252.             jQuery.ajax({
  253.                 url : 'admin/parsers/check_address.php',
  254.                 method : 'POST',
  255.                 data : data,
  256.                 success : function(data){
  257.                     if(data != true){
  258.                         jQuery('#payment-errors').html(data);
  259.                     }
  260.                     if(data == true) {
  261.                         jQuery('#payment-errors').html("");
  262.                         jQuery('#step1').css("display","none");
  263.                         jQuery('#step2').css("display","block");
  264.                         jQuery('#next_button').css("display","none");
  265.                         jQuery('#back_button').css("display","inline-block");
  266.                         jQuery('#checkout_button').css("display","inline-block");
  267.                         jQuery('#checkoutModalLabel').html("Проверка данных и оплата");
  268.                     }
  269.                 },
  270.                 error : function(){alert("Произошло что-то непредвиденное...");},
  271.             });
  272.         }
  273.     </script>
  274.    
  275.      <br><br><br>
  276. <?php
  277.     include 'includes/footer.php';
  278. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement