public function init()
 {
     parent::init();
     // If no shopping cart doesn't exist, redirect to base
     if (!ShoppingCart::create()->getItems()->exists()) {
         return $this->redirect(ShoppingCart::config()->url_segment);
     }
 }
 public function init()
 {
     parent::init();
     // Check if payment slug is set and that corresponds to a payment
     if ($this->request->param('ID') && ($method = CommercePaymentMethod::get()->byID($this->request->param('ID')))) {
         $this->payment_method = $method;
     } elseif ($method = CommercePaymentMethod::get()->byID(Session::get('Commerce.PaymentMethodID'))) {
         $this->payment_method = $method;
     }
     // Setup payment handler
     if ($this->payment_method && $this->payment_method !== null) {
         $handler = $this->payment_method->ClassName;
         $handler = $handler::$handler;
         $this->payment_handler = $handler::create();
         $this->payment_handler->setRequest($this->request);
         $this->payment_handler->setURLParams = $this->request->allParams();
         $this->payment_handler->setPaymentGateway($this->getPaymentMethod());
     }
 }
 public function __construct()
 {
     // If items are stored in a session, get them now
     if (Session::get('Commerce.ShoppingCart.Items')) {
         $this->items = unserialize(Session::get('Commerce.ShoppingCart.Items'));
     } else {
         $this->items = ArrayList::create();
     }
     // If discounts stored in a session, get them, else create new list
     if (Session::get('Commerce.ShoppingCart.Discount')) {
         $this->discount = unserialize(Session::get('Commerce.ShoppingCart.Discount'));
     }
     // If we don't have any discounts, a user is logged in and he has
     // access to discounts through a group, add the discount here
     if (!$this->discount && Member::currentUserID()) {
         $member = Member::currentUser();
         $this->discount = $member->getDiscount();
         Session::set('Commerce.ShoppingCart.Discount', serialize($this->discount));
     }
     parent::__construct();
 }
 /**
  * The ContentController will take the URLSegment parameter from the URL and use that to look
  * up a SiteTree record.
  */
 public function __construct($dataRecord = null)
 {
     $this->dataRecord = $dataRecord;
     $this->failover = $this->dataRecord;
     parent::__construct();
 }