</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
//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])));
}
/**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*/
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
$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";
{% 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 %}