<!--tickets in the cart-->
<Column name="eventid" type="int32" notnull="yes" foreignkey="event:eventid" primarykey="yes">the event the ticket is for</Column>
<Column name="pricecategoryid" type="int32" foreignkey="pricecategory:pricecategoryid" primarykey="yes">the price category of the ticket</Column>
- <Column name="origpricecategoryid" type="int32" foreignkey="pricecategory:pricecategoryid" primarykey="yes">the price category of the ticket</Column>
+ <Column name="origpricecategoryid" type="int32" foreignkey="pricecategory:pricecategoryid">the price category of the ticket</Column>
<Column name="amount" type="int32" notnull="yes">amount of tickets of this type in the cart</Column>
<Column name="seating" type="string:255" null="yes" version="01.05"/>
</Table>
<Call lang="php" method="WOWebCart::removeVoucher($this);"/>
<Output/>
</Transaction>
-</Wolf>
\ No newline at end of file
+
+ <Transaction name="WebCartAddCoupon">
+ <Doc>Called from Web UI only: adds a coupon to the cart</Doc>
+ <Input>
+ <Var name="cartid" type="astring">The cart to add into</Var>
+ <Var name="couponid" type="astring">The coupon to add</Var>
+ </Input>
+ <Call lang="php" method="WOWebCart::addCoupon($this);"/>
+ <Output/>
+ </Transaction>
+</Wolf>
$basevars['script']['changeDeliveryAddress']=$BaseUrl."?mode=changeDeliveryAddress";
$basevars['script']['customerResetLogin']=$BaseUrl."?mode=customerResetLogin";
$basevars['script']['setlanguage']=$BaseUrl."?mode=setlanguage&lang=";
+ $basevars['script']['addcoupon']=$BaseUrl."?mode=addcoupon";
// form elements
$basevars['inputnames']['amountTickets']="amountTickets";
$basevars['inputnames']['event']="event";
$basevars['inputnames']['address']['zip']='addr_zip';
$basevars['inputnames']['address']['state']='addr_state';
$basevars['inputnames']['address']['country']='addr_country';
+ $basevars['inputnames']['coupon']='coupon';
//end of basevars
}
///checks whether the event has already started at the given timestamp
public function eventHasStarted($timestamp)
{
- return $timestamp>=$this->event->getstarttime();
+ return $timestamp>=$this->event->getstart();
}
///checks whether the event has already ended at the given timestamp
public function eventHasEnded($timestamp)
{
- return $timestamp>=$this->event->getendtime();
+ return $timestamp>=$this->event->getend();
}
///adds the ticket to the list of new tickets and validates whether the sale is possible;
private $couponid=null;
private $coupon=null;
+ ///create a new verifier object
public function __construct($couponid)
{
$this->couponid=$couponid;
$this->coupon=WOCoupon::fromTablecoupon(WTcoupon::getFromDB($couponid));
}
+ ///checks that the coupon can be used
public function isUseableOrNull()
{
if($this->coupon===null)return true;
return true;
}
+ ///verify the contents of the event plan
public function verify($eventplan)
{
if(!$this->isUseableOrNull())return false;
return $vret;
}
+ ///verification if the coupon is NULL
private function verifyNull($eventplan)
{
$vret=true;
}
return $vret;
}
+
+ ///applies the coupon to the WebCart
+ //TODO: check limits, check time
+ static public function applyToCart($cartid)
+ {
+ //get cart
+ $dcart=WTcart::getFromDB($cartid);
+ if(!is_a($dcart,"WTcart"))return;
+ //get coupon
+ $coupon=WOCoupon::fromTablecoupon(WTcoupon::getFromDB($dcart->couponid));
+ if(!is_a($coupon,"WOCoupon"))return;
+ //collect
+ global $db;
+ $tlines=WTcartticket::selectFromDB("cartid=".$db->escapeString($cartid));
+ foreach($tlines as $tick){
+ //get event
+ $event=WOEvent::fromTableevent(WTevent::getFromDB($tick->eventid));
+ //get price ID
+ if($db->isNull($tick->origpricecategoryid))
+ $pid=$tick->pricecategoryid;
+ else
+ $pid=$tick->origpricecategoryid;
+ //check for rule
+ $npid=$pid;
+ foreach($coupon->getrules() as $rule){
+ if($rule->getfromcategory()==$pid){
+ $n=$rule->gettocategory();
+ foreach($event->getprice() as $prc){
+ if($prc->getpricecategoryid()==$n){
+ $npid=$n;
+ break;
+ }
+ }
+ if($npid!=$pid)break;
+ }
+ }
+ //TODO: this may fail if the user adds more tickets later
+ $tick->pricecategoryid=$npid;
+ $tick->origpricecategoryid=$pid;
+ $tick->update();
+ }
+ }
};
redirectHome(array("mode"=>"cart","cartid"=>$cartid));
}
+///called from index.php - adds a coupon to the cart
+static public function addCoupon()
+{
+ global $HTTPARGS,$basevars;
+ //get the cart
+ $cartid=self::getOrCreateCart();
+ //find event
+// echo "checking";
+ $vi=$basevars['inputnames']['coupon'];
+ if(!isset($HTTPARGS[$vi])){
+ $basevars['invalidcoupon']='none';
+ return;
+ }
+ //price
+ $cpid=strtoupper(trim($HTTPARGS[$vi]));
+ //add
+// echo "adding";
+ try{
+ WTrWebCartAddCoupon::execute($cartid,$cpid);
+ }catch(WobTransactionError $e){
+ $basevars['invalidcoupon']=$cpid;
+ }
+ //rendering is called after this...
+}
+
/**called from index.php - removes tickets/vouchers from cart*/
static public function removeItem()
{
$p=$twig->loadTemplate("carterror.html");
return $p->render($basevars);
}
+
+ //apply coupon
+ CouponVerifier::applyToCart($cartid);
//cart is ok, now get the object
$cart = WOWebCart::fromTablecart(WTcart::getFromDB($cartid));
$p=$twig->loadTemplate("carterror.html");
return $p->render($basevars);
}
- //push it to order
- $trans=WTrCreateOrder::execute($cart,false);
+ //push it to order; TODO: add voucher feature (arg #3)
+ $trans=WTrCreateOrder::execute($cart,false,array());
//delete cart
if($trans->resultorder()!==false){
$where="cartid = ".$db->escapeString($cartid);
// die ("hallo");
}
+ ///transaction to add coupon to cart
+ static public function addCoupon($trans)
+ {
+ $cartid=$trans->getcartid();
+ $cpid=$trans->getcouponid();
+ //get cart
+ $dcart=WTcart::getFromDB($cartid);
+ $cart=WOWebCart::fromTablecart($dcart);
+ if(!is_a($cart,"WOWebCart")){
+ $trans->abortWithError("no cart");
+ return;
+ }
+ //find coupon
+ $dcoup=WTcoupon::getFromDB($cpid);
+ if(!is_a($dcoup,"WTcoupon")){
+ $trans->abortWithError("no coupon");
+ return;
+ }
+ //TODO: check validity
+ //update
+ $dcart->couponid=$cpid;
+ $dcart->update();
+ }
+
/**transaction to remove tickets from cart*/
static public function removeTickets($trans)
{
$cartid=$trans->getcartid();
$evid=$trans->geteventid();
$pcid=$trans->getpricecategoryid();
+ error_log("hallo ".$cartid." ".$evid." ".$pcid);
//get cart
$cart=WOWebCart::fromTablecart(WTcart::getFromDB($cartid));
if(!is_a($cart,"WOWebCart"))return;
case "cart": // show current cart (can be called from anywhere in order process)
$page=WebCart::createCartOverview();
break;
+ case "addcoupon"://add a coupon to the cart
+ WebCart::addCoupon();
+ $page=WebCart::createCartOverview();
+ break;
case "removeItem": // remove something from cart
WebCart::removeItem();
break;
{# end of the table #}
</table>
+
+ {% if invalidcoupon is defined %}
+ <p>The coupon could not be added to your cart.
+ {% endif %}
+ {% if cart.couponid is null %}
+ <p><form action="{{script.addcoupon}}" method="get"><input type="hidden" name="mode" value="addcoupon"></input>
+ Coupon: <input type="text" name="{{inputnames.coupon}}"></input><input type="submit" value="Add Coupon"></input>
+ {% else %}
+ <p>Coupon: {{cart.couponid}}
+ {% endif %}
{# actions the user may want to take #}
<p><a href="{{script.orderLogin}}">Checkout</a></p>