From beede4a8f442fc4ea114c87e6074b4df7b8da17b Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 4 Jul 2010 21:14:55 +0000 Subject: [PATCH] cart display, shipping and product items missing git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@525 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- wob/cart.wolf | 12 ++++++ www/inc/db/dbupgrade.php | 4 +- www/inc/rendering/cart_listing.php | 21 +++++++++-- www/inc/wext/webcart.php | 69 ++++++++++++++++++++++++++++++++++- www/index.php | 1 + www/template/en/cart.html | 22 ++++++++++-- 6 files changed, 118 insertions(+), 11 deletions(-) diff --git a/wob/cart.wolf b/wob/cart.wolf index 389a6bf..860b3db 100644 --- a/wob/cart.wolf +++ b/wob/cart.wolf @@ -173,4 +173,16 @@ + + + Called from the Web UI only: adds tickets to a specific event + + The cart to add into + The event to buy tickets for + Price category of that event + amount of tickets + + + + \ No newline at end of file diff --git a/www/inc/db/dbupgrade.php b/www/inc/db/dbupgrade.php index cb9be73..28f0582 100644 --- a/www/inc/db/dbupgrade.php +++ b/www/inc/db/dbupgrade.php @@ -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]))); } diff --git a/www/inc/rendering/cart_listing.php b/www/inc/rendering/cart_listing.php index 4c42836..d159da9 100644 --- a/www/inc/rendering/cart_listing.php +++ b/www/inc/rendering/cart_listing.php @@ -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*/ diff --git a/www/inc/wext/webcart.php b/www/inc/wext/webcart.php index 98eb67a..b6eeb7c 100644 --- a/www/inc/wext/webcart.php +++ b/www/inc/wext/webcart.php @@ -13,12 +13,77 @@ 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 diff --git a/www/index.php b/www/index.php index f62cdc5..8cc6930 100644 --- a/www/index.php +++ b/www/index.php @@ -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"; diff --git a/www/template/en/cart.html b/www/template/en/cart.html index 11fc777..0b8c674 100644 --- a/www/template/en/cart.html +++ b/www/template/en/cart.html @@ -8,10 +8,26 @@ {% block title %}Cart{% endblock %} {% block page %} +

This is cart {{cart.cartid}}

+ {% if cart.isempty %} + This cart is empty. + {% else %} + + + {% for ticket in cart.tickets %} + + {% endfor %} + {% for voucher in cart.vouchers %} + + {% endfor %} - {{cart.cartid}} - - Continue Shopping

+

+ +
ItemItem PriceAmountSum
Ticket: {{ticket.event.title}}{{ticket.price}}{{ticket.amount}}{{ticket.pricesum}}
Voucher{{voucher.value}}1{{voucher.value}}
Shipping: {{cart.shipping.name}}{{cart.shipping.price}}1{{cart.shippingprice}}
Sum:{{cart.sum}}
+

Checkout

+ {% endif %} + +

Continue Shopping

{% endblock %} -- 1.7.2.5