fix ordercheck and add method to make cart live longer
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sat, 17 Nov 2007 18:25:27 +0000 (18:25 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sat, 17 Nov 2007 18:25:27 +0000 (18:25 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@77 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

www/inc/cart.php

index 7ebb0f3..ff26359 100644 (file)
@@ -175,6 +175,7 @@ class Cart
                global $db;
                //sanity check
                if($amount<=0)return false;
+               $this->renewCart();
                //check that ticket can be sold
                $event=new Event($eventid);
                if($event->isCancelled())return false;
@@ -207,8 +208,12 @@ class Cart
                global $db;
                $res=$db->select("cart_ticket","*","where cartid=".$db->escapeString($this->cartid));
                if(count($res)>0)
-               foreach($res as $k=>$tc)
-                       $ret[]=new CartTicket($tc["cartid"],$tc["eventid"],$tc["amount"]);
+               foreach($res as $k=>$tc){
+                       $evt=new Event($tc["eventid"]);
+                       //TODO: add more checks (event over, cancelled, etc.pp.)
+                       if($evt->availableTicketAmount()<$tc["amount"])
+                               $ret[]=new CartError(CE_EVENTNOTICKETS,$tc["eventid"]);
+               }
                //vouchers are ok by default, just check amount
                $itmcnt=count($res);
                $res=$db->select("cart_voucher","cvid","where cartid=".$db->escapeString($this->cartid));
@@ -219,6 +224,13 @@ class Cart
                //return...
                return $ret;
        }
+       
+       /**makes sure the cart continues to exist*/
+       public function renewCart()
+       {
+               global $db;
+               $db->update("cart",array("timeout"=>(time()+$CartTimeout)),"cartid=".$db->escapeInt($this->cartid));
+       }
 };
 
 ?>
\ No newline at end of file