From: Konrad Rosenbaum Date: Wed, 21 Mar 2012 20:59:26 +0000 (+0100) Subject: add buying with a new customer X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=81e3bf7334672e696f7c84beb1138493ec70f426;p=web%2Fkonrad%2Fsmoke.git add buying with a new customer --- diff --git a/www/inc/classes/basevars.php b/www/inc/classes/basevars.php index 4afad74..ea9f9a2 100644 --- a/www/inc/classes/basevars.php +++ b/www/inc/classes/basevars.php @@ -113,17 +113,18 @@ public static function initPriv(){ $basevars['inputnames']['login']['name']='customer_mail'; $basevars['inputnames']['login']['passwd']='customer_passwd'; $basevars['inputnames']['login']['passwdrepeat']='customer_passwd2'; - $basevars['inputnames']['login']['name']='customer_name'; + $basevars['inputnames']['login']['lastname']='customer_name'; $basevars['inputnames']['login']['firstname']='customer_firstname'; $basevars['inputnames']['login']['title']='customer_title'; $basevars['inputnames']['address']['setaddress']='setaddr'; $basevars['inputnames']['address']['createaddress']='createaddr'; - $basevars['inputnames']['address']['name']='name'; - $basevars['inputnames']['address']['addr1']='addr1'; - $basevars['inputnames']['address']['addr2']='addr2'; - $basevars['inputnames']['address']['city']='city'; - $basevars['inputnames']['address']['state']='state'; - $basevars['inputnames']['address']['country']='country'; + $basevars['inputnames']['address']['name']='addr_name'; + $basevars['inputnames']['address']['addr1']='addr_line1'; + $basevars['inputnames']['address']['addr2']='addr_line2'; + $basevars['inputnames']['address']['city']='addr_city'; + $basevars['inputnames']['address']['zip']='addr_zip'; + $basevars['inputnames']['address']['state']='addr_state'; + $basevars['inputnames']['address']['country']='addr_country'; //end of basevars } diff --git a/www/inc/rendering/cart_listing.php b/www/inc/rendering/cart_listing.php index a8c64bd..b6a2772 100644 --- a/www/inc/rendering/cart_listing.php +++ b/www/inc/rendering/cart_listing.php @@ -375,6 +375,7 @@ static public function changeAddressPage($mode) $at->addr1=getHttpArg($basevars['inputnames']['address']['addr1']); $at->addr2=getHttpArg($basevars['inputnames']['address']['addr2']); $at->city=getHttpArg($basevars['inputnames']['address']['city']); + $at->zipcode=getHttpArg($basevars['inputnames']['address']['zip']); $at->state=getHttpArg($basevars['inputnames']['address']['state']); $at->countryid=getHttpArg($basevars['inputnames']['address']['country']); $at->insert(); @@ -392,7 +393,7 @@ static public function changeAddressPage($mode) $list=$basevars; $list['customer']=$cust; $list['cart']=$cart; - $list['countries']=WOCountry::fromTableArraycountry(WTcountry::selectFromDB("")); + $list['countries']=WOCountry::fromTableArraycountry(WTcountry::selectFromDB("","ORDER BY countryname")); return $twig->loadTemplate('changeaddress.html')->render($list); } diff --git a/www/inc/wext/customer.php b/www/inc/wext/customer.php index c411c61..ca2b101 100644 --- a/www/inc/wext/customer.php +++ b/www/inc/wext/customer.php @@ -370,7 +370,7 @@ class WOCustomer extends WOCustomerAbstract \param script.customerLogin the page to call for logging in \param script.customerRegistration the page to call for registering a new customer - \param customer_name the name of the customer (or an empty string if unknown) + \param customer_name the name (mail) of the customer (or an empty string if unknown) */ /** creates a login page @@ -422,6 +422,7 @@ class WOCustomer extends WOCustomerAbstract $list["customer_name"]=$cust->getemail(); } } + $list['countries']=WOCountry::fromTableArraycountry(WTcountry::selectFromDB("","ORDER BY countryname")); //display $p=$twig->loadTemplate("login.html"); return $p->render($list); @@ -433,7 +434,7 @@ class WOCustomer extends WOCustomerAbstract The loginerror.html template is used to render customer login and registering errors. - \param errorType the type of error: "login" - the login failed (wrong mail or password), "exist" - an account with the same mail already exists, "mismatch" - the new passwords do no match + \param errorType the type of error: "login" - the login failed (wrong mail or password), "exist" - an account with the same mail already exists, "mismatch" - the new passwords do no match, "create" for unspecified errors during creation of the new account (e.g. missing or invalid parameters) \param backUrl the URL to call back to the login page */ @@ -512,10 +513,80 @@ class WOCustomer extends WOCustomerAbstract redirectHome(array("mode"=>$next)); } + ///attempts to register a customer: if ok it creates a new customer object and redirects to the createaddress page, otherwise it shows the loginerror page static public function registerCustomer() { - global $HTTPARGS,$db,$basevars; - die ("not implemented"); + global $HTTPARGS,$db,$basevars,$twig; + //check whether params are there + $nameidx=$basevars['inputnames']['login']['name']; + $passidx=$basevars['inputnames']['login']['passwd']; + $passidx2=$basevars['inputnames']['login']['passwdrepeat']; + if(!isset($HTTPARGS[$nameidx]) || !isset($HTTPARGS[$passidx]) || !isset($HTTPARGS[$passidx2])) + return self::loginError("create"); + //check whether the chosen email is valid and does not exist yet + $mail=$HTTPARGS[$nameidx]; + $ct=WTcustomer::selectFromDB("email=".$db->escapeString($mail)); + if(count($ct)>0) + return self::loginError("exist"); + //check the password + $pass=$HTTPARGS[$passidx];$pass2=$HTTPARGS[$passidx2]; + if($pass != $pass2 || $pass=="")return self::loginError("mismatch"); + //create customer + $ct=WTcustomer::newRow(); + $ct->email=$mail; + $ct->passwd=Session::passwdHash($pass); + if(isset($HTTPARGS[$basevars['inputnames']['login']['firstname']])) + $ct->firstname=$HTTPARGS[$basevars['inputnames']['login']['firstname']]; + if(isset($HTTPARGS[$basevars['inputnames']['login']['lastname']])) + $ct->name=$HTTPARGS[$basevars['inputnames']['login']['lastname']]; + if(isset($HTTPARGS[$basevars['inputnames']['login']['title']])) + $ct->title=$HTTPARGS[$basevars['inputnames']['login']['title']]; + if(!$ct->insert()) + return self::loginError("create"); + //create address + $addr=WTaddress::newRow(); + $addr->customerid=$ct->customerid; + $addr->lastused=time(); + if(isset($HTTPARGS[$basevars['inputnames']['address']['addr1']])) + $addr->addr1=$HTTPARGS[$basevars['inputnames']['address']['addr1']]; + if(isset($HTTPARGS[$basevars['inputnames']['address']['addr2']])) + $addr->addr2=$HTTPARGS[$basevars['inputnames']['address']['addr2']]; + if(isset($HTTPARGS[$basevars['inputnames']['address']['city']])) + $addr->city=$HTTPARGS[$basevars['inputnames']['address']['city']]; + if(isset($HTTPARGS[$basevars['inputnames']['address']['zip']])) + $addr->zipcode=$HTTPARGS[$basevars['inputnames']['address']['zip']]; + if(isset($HTTPARGS[$basevars['inputnames']['address']['state']])) + $addr->state=$HTTPARGS[$basevars['inputnames']['address']['state']]; + $addr->insert(); + //attempt to set countryid (done separately since it is a foreign key and not quite as essential + if(isset($HTTPARGS[$basevars['inputnames']['address']['country']])) + $addr->countryid=$HTTPARGS[$basevars['inputnames']['address']['country']]; + $addr->update(); + //log into cart + $cartid=WebCart::getCart(); + if($cartid==""){ + $p=$twig->loadTemplate("carterror.html"); + return $p->render($basevars); + } + //get customer data + $cart=WTcart::getFromDB($cartid); + $cart->customerid=$ct->customerid; + $cart->update(); + //get address if there is none yet + if($cart->deliveryaddress==false){ + $addrs=WTaddress::selectFromDB("customerid=".$ct->customerid,"ORDER BY lastused DESC"); + if(count($addrs)>0){ + $cart->deliveryaddress=$addrs[0]->addressid; + $cart->update(); + } + } + //store in session + $sess=WOWebSession::getOrCreateWebSession(); + $st=WTwebsession::getFromDB($sess->getsessionid()); + $st->customerid=$ct->customerid; + $st->update(); + //go to checkout page + redirectHome(array("mode"=>"checkout")); } }; diff --git a/www/template/en/login.html b/www/template/en/login.html index 8d2e21c..1b61d50 100644 --- a/www/template/en/login.html +++ b/www/template/en/login.html @@ -25,11 +25,13 @@ {# the create account dialog #}
+ Please enter a valid email address and a secure password for your account. All order information will be sent to this email address. You will need the password to order tickets and to see your order status - anyone who knows this password can order in your name. If you forget your password you can reset it at any time.
E-mail address:
Select a Password:
Repeat Password:

+ Please enter an address to which your order will be sent:
- + + + + + +
Title: @@ -41,8 +43,18 @@ Frau
Name:
Last Name:
First Name:
Address:
+
City:
ZIP code:
State:
Country: