/**
  * Login form handler method
  *
  * This method is called when the user clicks on "Log in"
  *
  * @param array $data Submitted data
  */
 public function dologin($data)
 {
     if ($this->performLogin($data)) {
         $this->logInUserAndRedirect($data);
     } else {
         if (array_key_exists('Email', $data)) {
             Session::set('SessionForms.MemberLoginForm.Email', $data['Email']);
             Session::set('SessionForms.MemberLoginForm.Remember', isset($data['Remember']));
         }
         if (isset($_REQUEST['BackURL'])) {
             $backURL = $_REQUEST['BackURL'];
         } else {
             $backURL = null;
         }
         if ($backURL) {
             Session::set('BackURL', $backURL);
         }
         // Show the right tab on failed login
         $loginLink = Store_OrderController::get_link() . "/place";
         if ($backURL) {
             $loginLink .= '?BackURL=' . urlencode($backURL);
         }
         $this->controller->redirect($loginLink . '#' . $this->FormName() . '_tab');
     }
 }
 public function __construct($controller, $name, $order_id)
 {
     $Order = Order::get_by_id("Order", $order_id);
     /* Fields */
     $fields = FieldList::create(HiddenField::create("business", "business", DataObject::get_one("Gateway_PayPal")->EmailAddress), HiddenField::create("cmd", "cmd", "_xclick"), HiddenField::create("notify_url", "notify_url", Director::absoluteURL(Store_OrderController::create()->link() . "/payment/response?gateway=Gateway_PayPal")), HiddenField::create("custom", "custom", $order_id), HiddenField::create("item_name", "item_name", "Order No. " . $order_id . " @ " . StoreSettings::get_settings()->StoreSettings_StoreName), HiddenField::create("amount", "amount", Order::create()->calculateOrderTotal($Order)), HiddenField::create("currency_code", "currency_code", DataObject::get_one("StoreCurrency", "(`SystemCreated`='1')")->Code), HiddenField::create("no_note", "no_note", "1"), HiddenField::create("no_shipping", "no_shipping", "1"), HiddenField::create("return", "return", Director::absoluteURL(Store_OrderController::create()->link()) . "/payment/success?gateway=Gateway_PayPal"), HiddenField::create("rm", "rm", "2"), HiddenField::create("cbt", "cbt", "Return to " . StoreSettings::get_settings()->StoreSettings_StoreName), HiddenField::create("cancel_return", "cancel_return", Director::absoluteURL(Store_OrderController::create()->link()) . "/payment/cancelled?gateway=Gateway_PayPal"));
     /* Actions */
     $actions = FieldList::create(FormAction::create('', 'If you are not transferred to PayPal in 5 seconds, click here.'));
     /* Required Fields */
     $required = new RequiredFields(array("business", "cmd", "notify_url", "item_name", "amount", "currency_code"));
     /*
      * Now we create the actual form with our fields and actions defined 
      * within this class.
      */
     return parent::__construct($controller, $name, $fields, $actions, $required);
 }
 /**
  * Return the PayPal Payments Standard Form
  *
  * @param Int $order_id The ID of the order we are collecting payment for.
  * @return Form
  */
 public function PayPalForm($order_id)
 {
     $Form = Gateway_PayPal_Form::create(Store_OrderController::create(), "PayPalForm", $order_id);
     /* Set Form Action */
     $URL = "https://www.paypal.com/cgi-bin/webscr";
     $SandboxURL = "https://www.sandbox.paypal.com/cgi-bin/webscr";
     $Form->setFormAction(DataObject::get_one("Gateway_PayPal")->Sandbox ? $SandboxURL : $URL);
     $Form->setFormMethod("POST");
     return $Form;
 }
 /** 
  * FORM ACTION /createaccount
  * Create a new record for the customer in to the Customer DataObject, 
  * send them a confirmation email, sign their new account in to the
  * site and redirect them to stage two of the order process.
  *
  * @return null.
  */
 public function createaccount($data, $form)
 {
     /* Save Data */
     $customer = new Customer();
     $form->saveInto($customer);
     $customer->write();
     /* TODO - Send Confirmation Email */
     /* If the new customer can be signed in, redirect to order stage two. */
     if (Customer::get_one("Customer", "(`Email`='" . $customer->Email . "')")->logIn()) {
         return $this->redirect(Store_OrderController::get_link() . "/place/two");
     } else {
         $form->sessionMessage("An unexpected error occurred, please try again.", "bad");
         return $this->redirectBack();
     }
 }
 /**
  * LogoutLink
  * Return a logout link 
  *
  * @param String $location The location to direct to. i.e. storefront, basket, placeorder
  * @return URL
  */
 public function LogoutLink($location = null)
 {
     $security = new Security();
     /* Set $BackURL based on $location */
     switch ($location) {
         /* Basket */
         case "basket":
             $Store_BasketController = new Store_BasketController();
             $BackURL = $Store_BasketController->link();
             break;
             /* Order Step 1 */
         /* Order Step 1 */
         case "placeorder":
             $Store_OrderController = new Store_OrderController();
             $BackURL = $Store_OrderController->link() . "/place/one";
             break;
             /* Storefront */
         /* Storefront */
         default:
             $BackURL = self::get_link();
             break;
     }
     return $security->Link('logout') . "?BackURL=" . $BackURL;
 }
 /**
  * ACTION /placeorder
  * Redirect the user to /order/place action on Store_Controller to pickup order process.
  */
 public function placeorder($data)
 {
     return $this->redirect(Store_OrderController::get_link() . "/place");
 }