Permalink
Browse files

NEW: Introduced ShopUserInfo class for storing and retrieving data wh…

…ich we gather about the visitor. This can then be used to pre-populate other forms etc.
  • Loading branch information...
1 parent 3fa6079 commit 6ad2bb8faae4baf0db23470bace4d16b2fb5abfa @jedateach jedateach committed Nov 22, 2012
Showing with 44 additions and 3 deletions.
  1. +31 −0 code/ShopUserInfo.php
  2. +13 −3 code/steppedcheckout/CheckoutStep_Address.php
View
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Collects and stores data about the user
+ */
+class ShopUserInfo extends Object{
+
+ private static $singleton = null;
+ protected static function singleton(){
+ if(!self::$singleton){
+ self::$singleton = new ShopUserInfo();
+ }
+ return self::$singleton;
+ }
+
+ protected function setLocation($address){
+ if(is_array($address)){
+ $address = new Address($address);
+ }
+ Session::set("UserInfo.Location",$address);
+ $this->extend("onAfterSetLocation",$address);
+ }
+
+ static function set_location($address){
+ ShopUserInfo::singleton()->setLocation($address);
+ }
+
+ static function get_location(){
+ return Session::get("UserInfo.Location");
+ }
+
+}
@@ -13,10 +13,15 @@ class CheckoutStep_Address extends CheckoutStep{
function shippingaddress(){
$form = $this->AddressForm();
+ if($shopuser = ShopUserInfo::get_location()){
+ $form->loadDataFrom($shopuser->toMap());
+ }
if($member = Member::currentUser()){
- $form->loadDataFrom($member->DefaultShippingAddress());
+ $form->loadDataFrom($member->DefaultShippingAddress()->toMap());
+ }
+ if(ShoppingCart::curr()->ShippingAddress()->exists()){
+ $form->loadDataFrom(ShoppingCart::curr()->ShippingAddress());
}
- $form->loadDataFrom(ShoppingCart::curr()->ShippingAddress());
$form->Fields()->push(
new CheckboxField("SeperateBilling","Bill to a different address from this")
);
@@ -38,10 +43,15 @@ function AddressForm(){
function billingaddress(){
$form = $this->AddressForm();
+ if($shopuser = ShopUserInfo::get_location()){
+ $form->loadDataFrom($shopuser);
+ }
if($member = Member::currentUser()){
$form->loadDataFrom($member->DefaultBillingAddress());
}
- $form->loadDataFrom(ShoppingCart::curr()->BillingAddress());
+ if(ShoppingCart::curr()->BillingAddress()->exists()){
+ $form->loadDataFrom(ShoppingCart::curr()->BillingAddress());
+ }
$form->Actions()->emptyItems();
$form->Actions()->push(
new FormAction("setbillingaddress","Continue")

0 comments on commit 6ad2bb8

Please sign in to comment.