public function init()
 {
     parent::init();
     if ($this->userId == 0) {
         $this->_redirect("login/index");
     }
 }
 /**
  * ACTION /
  * Redirect back to the storefront as /product/ has no content.
  */
 public function index()
 {
     return $this->redirect(Store_Controller::get_link(), 404);
 }
 /**
  * updatePaymentRecord
  * Take the existing Order_Payment_PayPal record and update it with
  * the data from the current IPN response.
  *
  * @param SS_HTTPRequest $request
  * @param Int $payment_record_id The ID of the Order_Payment_PayPal record we are updating.
  * @param String $status The value of status field on the new Order_Payment record.
  * @param String $order_status The SystemTitle of the Order_Status we are to use on the Order record.
  * @return true
  */
 public function updatePaymentRecord($request, $payment_record_id, $status, $order_status)
 {
     /**
      * Array of fields values to be updated.
      * Items without a value will use $request->postVar($key) 
      * in the for loop below.
      */
     $fields = array("order_payment.status" => $status, "order.status" => DataObject::get_one("Order_Statuses", "(`SystemTitle`='" . $order_status . "')")->ID, "test_ipn" => null, "txn_id" => null, "parent_txn_id" => null, "txn_type" => null, "payer_id" => null, "payer_status" => null, "custom" => null, "payment_date" => null, "mc_fee" => null, "mc_gross" => null, "payment_status" => null, "pending_reason" => null, "payment_type" => null, "reason_code" => null, "protection_eligibility" => null);
     /* Form a string for the SQL SET segment. */
     $set_statement = "";
     $fields_count = count($fields);
     $i = 1;
     foreach ($fields as $field_name => $value) {
         $set_statement .= $field_name . "='";
         $set_statement .= $value == null ? $request->postVar($field_name) : $value;
         $set_statement .= "'";
         if ($i < $fields_count) {
             $set_statement .= ", ";
         }
         $i++;
     }
     /* Update Order_Payment_PayPal record */
     $record_update = DB::Query("\n\t\t\tUPDATE \n\t\t\t\torder_payment_paypal\n\t\t\t\tLEFT JOIN order_payment ON order_payment.id = order_payment_paypal.id \n\t\t\t\tLEFT JOIN `order` ON `order`.`id` = order_payment.OrderID\n\t\t\tSET \n\t\t\t\t{$set_statement}\n\t\t\tWHERE \n\t\t\t\torder_payment_paypal.id = '{$payment_record_id}'\n\t\t");
     /* If all has been successful, return true. */
     if ($record_update) {
         return Store_Controller::create()->httpError(200);
     } else {
         $this->newLogEntry("Could not update record" . "MySQL error in Gateway_PayPal::newPaymentRecord().");
         exit;
     }
 }
 /**
  * LogoutLink
  * Return a logout link 
  *
  * @uses Store_Controller::LogoutLink
  * @param String $location The location to direct to. i.e. storefront, basket, placeorder
  * @return URL
  */
 public function LogoutLink($location = null)
 {
     $Store_Controller = new Store_Controller();
     return $Store_Controller->LogoutLink($location);
 }
 /**
  * get_link
  * Return the link for this controller.
  *
  * @return URL
  */
 public static function get_link()
 {
     return Store_Controller::create()->link();
 }
 /**
  * ACTION /continueshopping
  * Return the customer to the store front.
  */
 public function continueshopping($data)
 {
     return $this->redirect(Store_Controller::get_link());
 }