Created
February 17, 2016 03:25
-
-
Save hailwood/87ed7d1f7ade6f8ef97a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class FoxcommerceConfiguration_AdminSection extends FoxcommerceAdminSection | |
{ | |
protected static $url_segment = 'ecommerce'; | |
protected static $url_priority = 75; | |
protected static $url_rule = '/FoxcommerceConfig/Configuration'; | |
protected static $menu_title = 'Basic Configuration'; | |
protected static $description = 'Manage the basic config for your shop'; | |
protected static $tree_class = 'FoxcommerceConfig'; | |
protected static $is_subsection = true; | |
protected static $url_handlers = [ | |
'FoxcommerceConfig/Configuration/SettingsForm' => 'SettingsForm', | |
'FoxcommerceConfig/Configuration' => 'Settings' | |
]; | |
public function init() | |
{ | |
parent::init(); | |
$this->modelClass = 'FoxcommerceConfig'; | |
} | |
public function getSubsectionFormFields() | |
{ | |
$fields = parent::getSubsectionFormFields(); | |
$config = FoxcommerceConfig::current(); | |
$fields->addFieldsToTab('Root.Main', [ | |
DropdownField::create('TaxStyle', 'Tax style', | |
['Inclusive' => 'Inclusive', 'Exclusive' => 'Exclusive'], $config->TaxStyle), | |
]); | |
return $fields; | |
} | |
public function getSubsectionFormActions() | |
{ | |
$actions = parent::getSubsectionFormActions(); | |
$actions->add( | |
FormAction::create('saveSettings', _t('GridFieldDetailForm.Save', 'Save')) | |
->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')); | |
return $actions; | |
} | |
public function saveSettings($data, CMSForm $form) | |
{ | |
$config = FoxcommerceConfig::current(); | |
$config->TaxStyle = $data['TaxStyle']; | |
$config->write(); | |
$form->sessionMessage('Shop basic configuration updated', 'good'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment