Jump to:

2082 Posts in 1002 Topics by 452 members

E-Commerce Modules

SilverStripe Forums » E-Commerce Modules » Extending CheckoutPage_Controller

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, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba, simon_w

Page: 1
Go to End
Author Topic: 885 Views
  • e-scape
    Avatar
    Community Member
    16 Posts

    Extending CheckoutPage_Controller Link to this post

    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

  • Andre
    Avatar
    Community Member
    126 Posts

    Re: Extending CheckoutPage_Controller Link to this post

    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

  • e-scape
    Avatar
    Community Member
    16 Posts

    Re: Extending CheckoutPage_Controller Link to this post

    Thanks Andre

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

    Cheers
    Jason

    885 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.