cart display, shipping and product items missing
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 4 Jul 2010 21:14:55 +0000 (21:14 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 4 Jul 2010 21:14:55 +0000 (21:14 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@525 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

wob/cart.wolf
www/inc/db/dbupgrade.php
www/inc/rendering/cart_listing.php
www/inc/wext/webcart.php
www/index.php
www/template/en/cart.html

index 389a6bf..860b3db 100644 (file)
                        </Map>
                </Mapping>
        </Class>
+       
+       <Transaction name="WebCartAddTicket">
+               <Doc>Called from the Web UI only: adds tickets to a specific event</Doc>
+               <Input>
+                       <Var name="cartid" type="astring">The cart to add into</Var>
+                       <Var name="eventid" type="int">The event to buy tickets for</Var>
+                       <Var name="pricecategoryid" type="int">Price category of that event</Var>
+                       <Var name="amount" type="int">amount of tickets</Var>
+               </Input>
+               <Call lang="php" method="WOWebCart::addTickets($this);"/>
+               <Output/>
+       </Transaction>
 </Wolf>
\ No newline at end of file
index cb9be73..28f0582 100644 (file)
@@ -200,13 +200,13 @@ class DBUpgrade
                                //eliminate trailing empty lines
                                if($l=="")continue;
                                //zip code alone?
-                               if(ereg("^[0-9]+$",$l)){
+                               if(preg_match("/^[0-9]+$/",$l)){
                                        $ai["zipcode"]=$l;
                                        continue;
                                }
                                //city plus zipcode? or only city?
                                $x=explode(" ",$l);
-                               if(ereg("^[0-9]+$",$x[0])){
+                               if(preg_match("/^[0-9]+$/",$x[0])){
                                        $ai["zipcode"]=$x[0];
                                        $l=trim(substr($l,strlen($x[0])));
                                }
index 4c42836..d159da9 100644 (file)
@@ -19,10 +19,23 @@ const cartIdName = "smoke_cartid";
 /**called from index.php - add tickets to cart*/
 static public function addTickets(){
        global $HTTPARGS;
-       $cart=self::getOrCreateCart();
-//     echo $cart;
-       
-       redirectHome(array("mode"=>"cart","cartid"=>$cart));
+       //get the cart
+       $cartid=self::getOrCreateCart();
+       //find event
+       if(!isset($HTTPARGS['event']) || !isset($HTTPARGS['amountTickets']))
+               redirectHome();
+       $evid=$HTTPARGS['event']+0;
+       //find price categories
+       $pcs=$HTTPARGS['amountTickets'];
+       if(!is_array($pcs) || count($pcs)==0)
+               redirectHome();
+       //go through them
+       foreach($pcs as $pcid => $amount){
+               $pcid=$pcid+0;$amount=$amount+0;
+               WTrWebCartAddTicket::execute($cartid,$evid,$pcid,$amount);
+       }
+       //go to the cart
+       redirectHome(array("mode"=>"cart","cartid"=>$cartid));
 }
 
 /**returns the current cart ID, or an empty string if there is no cart, automatically updates its timeout*/
index 98eb67a..b6eeb7c 100644 (file)
 
 class WOWebCart extends WOWebCartAbstract
 {
-
+       /**returns array data for twig*/
        public function getParserData()
        {
-               return $this->propertyArray();
+               $ret=$this->propertyArray();
+               //check whether it is empty
+               $ret['isempty']=count($this->prop_tickets)==0 && count($this->prop_vouchers)==0 && count($this->prop_items)==0;
+               $prc=0;
+               //go through tickets and add some data
+               $lang=LanguageManager::singleton();
+               foreach($ret['tickets'] as $id=>$tck){
+                       $ev=WOEvent::fromTableevent(WTevent::getFromDB($tck['eventid']));
+                       $ret['tickets'][$id]['event']=$ev->propertyArray();
+                       $pc=WOEventPrice::fromTableeventprice(WTeventprice::getFromDB($tck['eventid'],$tck['pricecategoryid']));
+                       $ret['tickets'][$id]['pricecategory']=$pc->propertyArray();
+                       $p=$pc->getprice();
+                       $ret['tickets'][$id]['price']=$lang->getPrice($p);
+                       $ret['tickets'][$id]['pricecents']=$p;
+                       $p*=$tck['amount'];
+                       $ret['tickets'][$id]['pricesum']=$lang->getPrice($p);
+                       $ret['tickets'][$id]['pricesumcents']=$p;
+                       $prc+=$p;
+               }
+               //go through vouchers add to sum
+               foreach($ret['vouchers'] as $id=>$vou){
+                       $prc+=$vou['value'];
+                       $ret['vouchers'][$id]['valuecents']=$vou['value'];
+                       $ret['vouchers'][$id]['value']=$lang->getPrice($vou['value']);
+               }
+               //TODO: go through items add to sum
+               //TODO: add shipping option
+               $ret["shippingid"]=false;
+               //add sum to return value
+               $ret['sumcents']=$prc;
+               $ret['sum']=$lang->getPrice($prc);
+               //return...
+               return $ret;
        }
 
+       /**transaction to add tickets to cart*/
+       static public function addTickets($trans)
+       {
+               $cartid=$trans->getcartid();
+               $evid=$trans->geteventid();
+               $pcid=$trans->getpricecategoryid();
+               $amount=$trans->getamount();
+               //get cart
+               $cart=WOWebCart::fromTablecart(WTcart::getFromDB($cartid));
+               if(!is_a($cart,"WOWebCart"))return;
+               $event=WTevent::getFromDB($evid);
+               if(!is_a($event,"WTevent"))return;
+               //ignore non-buy
+               if($amount<1)return;
+               //find category, match with event
+               $pc=WTeventprice::getFromDB($evid,$pcid);
+               if(!is_a($pc,"WTeventprice"))return;
+               //find whether cart contains this
+               $itm=WTcartticket::getFromDB($cartid,$evid,$pcid);
+               if(is_a($itm,"WTcartticket")){
+                       //yes: add to it
+                       $itm->amount+=$amount;
+                       $itm->update();
+               }else{
+                       //no: add new item
+                       $itm=WTcartticket::newRow();
+                       $itm->cartid=$cartid;
+                       $itm->eventid=$evid;
+                       $itm->pricecategoryid=$pcid;
+                       $itm->amount=$amount;
+                       $itm->insert();
+               }
+       }
 };
 
 ?>
\ No newline at end of file
index f62cdc5..8cc6930 100644 (file)
@@ -38,6 +38,7 @@ $basevars['script']['eventDetails']=$_SERVER['SCRIPT_NAME']."?mode=eventDetails&
 $basevars['script']['eventOrder']=$_SERVER['SCRIPT_NAME']."?mode=eventOrder&event=";
 $basevars['script']['cart']=$_SERVER['SCRIPT_NAME']."?mode=cart";
 $basevars['script']['mycart']=$_SERVER['SCRIPT_NAME']."?mode=mycart";
+$basevars['script']['checkout']=$_SERVER['SCRIPT_NAME']."?mode=checkout";
 //$basevars['script']['orderLogin']=$_SERVER['SCRIPT_NAME']."?mode=orderLogin";
 //$basevars['script']['customerRegistration']=$_SERVER['SCRIPT_NAME']."?mode=customerRegistration";
 //$basevars['script']['orderOverview']=$_SERVER['SCRIPT_NAME']."?mode=orderOverview";
index 11fc777..0b8c674 100644 (file)
@@ -8,10 +8,26 @@
 {% block title %}Cart{% endblock %}
 
 {% block page %}
+ <p style="font-size:40%;">This is cart {{cart.cartid}}</p>
 
+ {% if cart.isempty %}
+  This cart is empty.
+ {% else %}
+  <table frame="1" border="1">
+  <tr><td><b>Item</b></td><td><b>Item Price</b></td><td><b>Amount</b></td><td><b>Sum</b></td></tr>
+  {% for ticket in cart.tickets %}
+  <tr><td>Ticket: {{ticket.event.title}}</td><td>{{ticket.price}}</td><td>{{ticket.amount}}</td><td>{{ticket.pricesum}}</td></tr>
+  {% endfor %}
+  {% for voucher in cart.vouchers %}
+  <tr><td>Voucher</td><td>{{voucher.value}}</td><td>1</td><td>{{voucher.value}}</td></tr>
+  {% endfor %}
   
-  {{cart.cartid}}
-  
-  <a href="{{script.root}}">Continue Shopping</a><p/>
+  <tr><td>Shipping: {{cart.shipping.name}}</td><td>{{cart.shipping.price}}</td><td>1</td><td>{{cart.shippingprice}}</td></tr>
+  <tr><td colspan="3" align="right"><b>Sum:</b></td><td>{{cart.sum}}</td></tr>
+  </table>
+  <p><a href="{{script.checkout}}">Checkout</a></p>
+ {% endif %}
+
+ <p><a href="{{script.root}}">Continue Shopping</a></p>
 
 {% endblock %}