Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

E-Commerce Modules /

Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.

Moderators: martimiz, Nicolaas, Sean, Ed, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba

Extending CheckoutPage_Controller


Go to End


3 Posts   1214 Views

Avatar
Quadra

Community Member, 16 Posts

20 October 2009 at 2:27am

Hi

I need to add an extra action to the CheckoutPage_Controller class. I want to do this in a way that does not change any module code so that I can easily update the module at a later date.

I have been able to achieve this by adding my action method into the Page_Controller class which CheckoutPage_Controller inherits from, but this is a little messy for me as that action will now be available on all controllers that inherit from Page_Controller.

Is there a way to use the Decorator pattern to achieve the same thing. I have tried using the Extension class, and although I know the class is being hooked in (overrode the setOwner method to check) the new action Method is not allowed.

placed in mysite/_config.php

Object::add_extension('CheckoutPage_Controller','ExtendedCheckoutPage_Controller');

class ExtendedCheckoutPage_Controller extends Extension {	
		
	function LocalOrderForm() {
		return new LocalOrderForm($this->owner, 'LocalOrderForm');
	}
	
}

Anyone got any advice here?

Many thanks
Jason

Avatar
Andre

Community Member, 146 Posts

14 November 2009 at 12:39am

The Extension Class has to look the Following:

class ExtendedCheckoutPage_Controller extends Extension {  

   public static $allowed_actions = array('LocalOrderForm');
       
   function LocalOrderForm() { 
      return new LocalOrderForm($this->owner, 'LocalOrderForm'); 
   } 
    
}

That worked for me on extending the Polls Module.

Greetings

Andre

Avatar
Quadra

Community Member, 16 Posts

14 November 2009 at 1:11am

Thanks Andre

I will have a go with that, makes sense though.

Cheers
Jason