Blame view

ajax/basket.php 4.17 KB
42868d70   andryeyev   Создал GIT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  <?php    
      
      header("Content-type: text/html; charset=windows-1251");
      require("../libs/setup.php");
      
      $setup = new setup();
      $objCatalogs = $setup->setupClass("Catalogs");
  
           switch($_SESSION['lang']){
            case 'ru' : include('../langs/ru.php');$setup->tpl->assign('lang_prefix',''); break;
            case 'ukr' : include('../langs/ukr.php');$setup->tpl->assign('lang_prefix','ukr/'); break;
            default : include('../langs/ru.php'); $setup->tpl->assign('lang_prefix','');break;
           } 	
  
      if(!isset($_SESSION['curs']))$_SESSION['curs'] = "uah";
  
      if(isset($_GET['clear'])){
          unset($_SESSION['basket']);
  		unset($_SESSION['shopcart']);
  		unset($_SESSION['cart']);
  		//print_r($_SESSION);
      }
      
      // $discount
      if(isset($_SESSION['catalog_user']) && $userID=$objCatalogs->isUser($_SESSION['catalog_user']['login'],$_SESSION['catalog_user']['psw'])){
          $discount = $objCatalogs->getUserDiscount($userID);
      } else { $discount = 0; }
  
      if(isset($_GET['product_id']) && $_GET['product_id']>0){
          
          
          $_SESSION['basket'][] = $_GET['product_id'];
   
      // ========== ZLODEYEV ============
   
          // ========================================
          // ============= êîðçèíà ==================
          // ========================================
          
              // ==== îáíîâëÿåì ====
          
              // Âûáèðàåì èíôî î òîâàðå
              $sql4 = "SELECT p.*, m.*,m.sale as msale, m.id as mod_id,IF(m.cine>0,m.cine,p.cine) as cine FROM catalogs_modifications as m
                      LEFT JOIN catalogs_products as p
                      ON p.id=m.product_id 
                      WHERE m.id='".$_GET['product_id']."' ";
              $result4 = mysql_query($sql4) or die(mysql_error());
              if (mysql_affected_rows()!=0) {	
                  $item=mysql_fetch_assoc($result4);
  				$item['cine'] = round($item['cine'] - ($item['cine']*$item['msale']/100));
              }    
              
              $f=0;
              
              if (isset($_SESSION['shopcart'])) {
              
                  foreach ($_SESSION['shopcart'] as $i => $cart) {
   
                      if ($cart['code']==$_GET['product_id']) {
  						//echo$cart['code']."=".$_GET['product_id']."<br>";
                          $f=1;
                          $_SESSION['shopcart'][$i]['count']=($_SESSION['shopcart'][$i]['count']+1);
                          $_SESSION['shopcart'][$i]['total']=$_SESSION['shopcart'][$i]['count']*$_SESSION['shopcart'][$i]['price'];
                          if ($_SESSION['shopcart'][$i]['total']==0) {
                              unset($_SESSION['shopcart'][$i]);
                          }
                          break;
                      }
                  }
              }
              // ==== äîáàâëÿåì ====
              
              // Åñëè íåò â ìàññèâå òî äîáàâëÿåì		
              if ($f==0) {
                  
                  // äîáàâëÿåì â êîðçèíó
                  
                  $_SESSION['shopcart'][] = 
                      array(
                          "code"=>$item['mod_id'],
  						"code_txt"=>$item['code'],	
                          "price"=>$item['cine'], 
                          "count"=>1,
                          "total"=>$item['cine'],
                      );
              }
          
      // ========== ZLODEYEV ============
          
      }
      if(isset($_SESSION['basket']) && count($_SESSION['basket'])){
       $cine_products = 0; $i=-1;
       foreach($_SESSION['basket'] as $product_id){ $i++;
       
          $cine_products = $cine_products + $objCatalogs->getProductCine($product_id);
          
          $_SESSION['cart'][$i]['price']=$objCatalogs->getProductCine($product_id);
        
       }
  
      $cine_products_discount = $cine_products - (($cine_products*$discount)/100);
  
          $_SESSION['cart']['total']= $cine_products_discount;
  
      $count_products = count($_SESSION['basket']);
      }
      else {$count_products = 0;$cine_products = 0;}
      $setup->error();
      $objCatalogs->viewVarCurs($_SESSION['curs']);
       if(isset($_SESSION['basket']))$objCatalogs->viewBasketProducts($_SESSION['basket'],$curs,$objCatalogs->getUserDiscount($userID));
      $objCatalogs->displayBasket($count_products,$cine_products,$cine_products_discount,$discount);
      ?>