Advertisement
RcPel

cart.php

Oct 29th, 2016
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.28 KB | None | 0 0
  1. function cart(){
  2.     global $conn;
  3.  
  4.    
  5.     $fabric_options = '';
  6.     $query2 = "SELECT * FROM almofadas";
  7.     $result = mysqli_query($conn,$query2);
  8.     while($rows = mysqli_fetch_assoc($result)){
  9.      
  10.       $tecido=$rows['tecido'];
  11.       $id_price=$rows['id_price'];
  12.      
  13.       $t50='50';
  14.       $t45='45';
  15.        
  16.        
  17.       $fabric_options .= '<option value="'.$id_price.'" >'.$tecido.'</option>';
  18.  
  19.     }
  20.  
  21.    
  22. $total = 0;
  23. $all_products=0;
  24.  
  25.  if(!isset($_SESSION['product'])){
  26.                $_SESSION['product']=NULL;
  27.                $_SESSION['total']=NULL;
  28.               }
  29.  
  30.     foreach ($_SESSION['product'] as $id => $value) {
  31.         if($value > 0){
  32.            
  33.  
  34.                 $query = "SELECT *
  35.                          FROM gallery2
  36.                          WHERE gallery2.id =".escape_string($id). "";
  37.                 $run_item = mysqli_query($conn,$query);
  38. echo $query."<br>";
  39.              
  40.                
  41.                
  42.     while($rows = mysqli_fetch_assoc($run_item)){
  43.         $vari   = $rows['variante'];
  44.         $num    = $rows['title'];
  45.         $id     = $rows['id'];
  46.  
  47.        
  48.        if(!isset($_SESSION['icms'][$id])) {
  49.         $_SESSION['icms'][$id]='0';
  50.         }else{
  51.         $_SESSION['icms'][$id];
  52.         }
  53.            
  54.  
  55.          $btn_add ='<button type="button" class="btn btn-success actions plus" data-action="plus" product_id="'.$id.'"><i class="fa fa-plus fa-lg" aria-hidden="true" add_btn></i> '.$id.' </button>';
  56.          $btn_remove ='<button type="button" class="btn btn-warning actions less" data-action="remove" product_id="'.$id.'"><i class="fa fa-minus fa-lg" aria-hidden="true" remove_btn></i></button>';
  57.          $btn_delete ='<button type="button" class="btn btn-default actions" data-action="delete" product_id="'.$id.'" onclick="deleteRow(this)"><i class="fa fa-times fa-lg" aria-hidden="true"></i></button>';
  58.  
  59.         if($rows['variante'] < 1){
  60.         $dash="";
  61.          $vari="";
  62.         }else{
  63.           $dash="-";
  64.          $vari =$rows['variante'];
  65.         }
  66.  
  67.         $subtotal=$value * $_SESSION['icms'][$id];
  68.         $cost=$_SESSION['icms'][$id];
  69.         $all_products +=$value;
  70.  
  71.         $product = '
  72.        <tr>
  73.          <td style="width:100px; "><img src="../'.$rows['image'].'" style="width:90%;border: 1px solid black;"></td>
  74.          <td>'.$num.''.$dash.''.$vari.'</td>
  75.  
  76.          <input type="hidden" value="'.$num.'" name="numero[]">
  77.          <input type="hidden" value="'.$vari.'" name="vari[]">
  78.          <input type="hidden" value="'.$rows['image'].'" name="desenho[]">
  79.  
  80.          <td style="width:15%;" class="row">
  81.            <select name="fabric[]" class="fabric select form-control selectpicker" required="" data-id="'.$id.'"  >
  82.                '. $fabric_options . '  
  83.            </select>
  84.          </td>
  85.            
  86.          <td class="row">
  87.            <select  data-id="'.$id.'" class="select size form-control selectpicker" required style="width:80%;"  name="size[]">
  88.              <option value="'.$t50.'" name="'.$t50.'">50x'.$t50.'</option>
  89.              <option value="'.$t45.'" name="'.$t50.'">45x'.$t45.'</option>
  90.                  
  91.            </select>
  92.          </td>
  93.          
  94.  
  95.          <td  class="product'.$id.' " value="'.$value.'" type="text" >'.$value.'</td>
  96.          <input class="product'.$id.' "  type="hidden" name="qnty[]" value="'.$value.'"/>
  97.  
  98.          <td  class="cost" data-id="'.$id.'" name="'.$cost.'">R$:'.$cost.'</td>
  99.          <input type="hidden" name="cost[]" value="'.$cost.'"/>
  100.  
  101.          <td  class="subtotal" data-id="'.$id.'" >R$:'.number_format($subtotal, 2, '.', '') .'</td>
  102.          <input class="subtotal" type="hidden" name="subtotal[]" value="'.number_format($subtotal, 2, '.', '') .'"/>
  103.          <td>
  104.             '.$btn_add.' '.$btn_remove.' '.$btn_delete.'
  105.          </td>
  106.            <input type="hidden" name="all[]" value="'. $_SESSION['total'].'"/>
  107.        </tr>';
  108.         echo $product;
  109.                
  110.                 }
  111.                 $_SESSION['total']=$total += $subtotal;//count the total $cost of all products
  112.                 $_SESSION['total_products']= $all_products;//count the total of all products
  113.                
  114.  
  115.                // print_r($value."<br>");
  116.  
  117.            
  118.         }
  119.     }  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement