Source of file OrderModifierFormController.php
Size: 3,016 Bytes - Last Modified: 2021-12-23T10:39:35+00:00
/var/www/docs.ssmods.com/process/src/src/Control/OrderModifierFormController.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 | <?php namespace Sunnysideup\Ecommerce\Control; use SilverStripe\Control\Controller; use SilverStripe\Control\Director; use SilverStripe\Core\Config\Config; use SilverStripe\Forms\Form; use Sunnysideup\Ecommerce\Api\ShoppingCart; use Sunnysideup\Ecommerce\Model\Order; /** * This controller allows you to submit modifier forms from anywhere on the site, * Most likely this will be from the the cart / checkout page. */ class OrderModifierFormController extends Controller { /** * @var Order */ protected $currentOrder; /** * @var string */ private static $url_segment = 'ecommercemodifierformcontroller'; /** * @var array */ private static $allowed_actions = [ 'removemodifier', ]; /** * @ToDO: check this method * It looks like this: /$ClassName/$action/ * * @param null|mixed $action * * @return string */ public function Link($action = null) { $URLSegment = Config::inst()->get(static::class, 'url_segment'); if (! $URLSegment) { $URLSegment = static::class; } return Controller::join_links( Director::BaseURL(), $URLSegment, $action ); } public function removemodifier() { //@TODO: See issue 149 } /** * sets virtual methods and order. */ protected function init() { parent::init(); $this->currentOrder = ShoppingCart::current_order(); $this->initVirtualMethods(); } /** * Inits the virtual methods from the name of the modifier forms to * redirect the action method to the form class. */ protected function initVirtualMethods() { if ($this->currentOrder) { $forms = $this->currentOrder->getModifierForms($this); if ($forms) { foreach ($forms as $form) { if (! ($form instanceof Form)) { $form = $form->Form; } $this->addWrapperMethod($form->getName(), 'getOrderModifierForm'); self::$allowed_actions[] = $form->getName(); // add all these forms to the list of allowed actions also } } } } /** * Return a specific {@link OrderModifierForm} by it's name. * * @param string $name The name of the form to return * * @return Form|null` */ protected function getOrderModifierForm($name) { if ($this->currentOrder) { $forms = $this->currentOrder->getModifierForms($this); if ($forms) { foreach ($forms as $form) { if (! ($form instanceof Form)) { $form = $form->Form; } if ($form->getName() === $name) { return $form; } } } } return null; } } |