diff --git a/core/lib/Thelia/Config/Resources/form.xml b/core/lib/Thelia/Config/Resources/form.xml index 3548a8016..cf9ccd489 100644 --- a/core/lib/Thelia/Config/Resources/form.xml +++ b/core/lib/Thelia/Config/Resources/form.xml @@ -118,6 +118,7 @@
+ diff --git a/core/lib/Thelia/Controller/Admin/ConfigStoreController.php b/core/lib/Thelia/Controller/Admin/ConfigStoreController.php new file mode 100644 index 000000000..1a9172ec1 --- /dev/null +++ b/core/lib/Thelia/Controller/Admin/ConfigStoreController.php @@ -0,0 +1,105 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Admin; + + +use Thelia\Core\Security\Resource\AdminResources; +use Thelia\Core\Security\AccessManager; +use Thelia\Form\ConfigStoreForm; +use Thelia\Log\Tlog; +use Thelia\Model\ConfigQuery; +/** + * Class ConfigStoreController + * @package Thelia\Controller\Admin + * @author Christophe Laffont + */ +class ConfigStoreController extends BaseAdminController +{ + + protected function renderTemplate() + { + return $this->render('config-store'); + } + + public function defaultAction() + { + if (null !== $response = $this->checkAuth(AdminResources::STORE, array(), AccessManager::VIEW)) return $response; + + // Hydrate the store configuration form + $configStoreForm = new ConfigStoreForm($this->getRequest(), 'form', array( + 'store_name' => ConfigQuery::read("store_name"), + 'store_email' => ConfigQuery::read("store_email"), + 'store_business_id' => ConfigQuery::read("store_business_id"), + 'store_phone' => ConfigQuery::read("store_phone"), + 'store_fax' => ConfigQuery::read("store_fax"), + 'store_address1' => ConfigQuery::read("store_address1"), + 'store_address2' => ConfigQuery::read("store_address2"), + 'store_address3' => ConfigQuery::read("store_address3"), + 'store_zipcode' => ConfigQuery::read("store_zipcode"), + 'store_city' => ConfigQuery::read("store_city"), + 'store_country' => ConfigQuery::read("store_country") + )); + + $this->getParserContext()->addForm($configStoreForm); + + return $this->renderTemplate(); + } + + public function saveAction() + { + if (null !== $response = $this->checkAuth(AdminResources::STORE, array(), AccessManager::UPDATE)) return $response; + + $error_msg = false; + + $configStoreForm = new ConfigStoreForm($this->getRequest()); + + try { + $form = $this->validateForm($configStoreForm); + + $data = $form->getData(); + + // Update store + foreach($data as $name => $value) { + if(! in_array($name , array('success_url', 'error_message'))) + ConfigQuery::write($name, $value, false); + } + + $this->adminLogAppend(AdminResources::STORE, AccessManager::UPDATE, "Store configuration changed"); + + $this->redirectToRoute('admin.configuration.store.default'); + + } catch (\Exception $ex) { + $error_msg = $ex->getMessage(); + } + + $this->setupFormErrorContext( + $this->getTranslator()->trans("Store configuration failed."), + $error_msg, + $configStoreForm, + $ex + ); + + return $this->renderTemplate(); + } +} diff --git a/core/lib/Thelia/Core/Security/Resource/AdminResources.php b/core/lib/Thelia/Core/Security/Resource/AdminResources.php index e953b83aa..a3e834d9d 100644 --- a/core/lib/Thelia/Core/Security/Resource/AdminResources.php +++ b/core/lib/Thelia/Core/Security/Resource/AdminResources.php @@ -100,5 +100,7 @@ final class AdminResources const SYSTEM_LOG = "admin.configuration.system-log"; + const STORE = "admin.configuration.store"; + const TRANSLATIONS = "admin.configuration.translations"; } diff --git a/core/lib/Thelia/Form/ConfigStoreForm.php b/core/lib/Thelia/Form/ConfigStoreForm.php new file mode 100644 index 000000000..6f6c0f705 --- /dev/null +++ b/core/lib/Thelia/Form/ConfigStoreForm.php @@ -0,0 +1,121 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints; +use Thelia\Model\ConfigQuery; +use Symfony\Component\Validator\ExecutionContextInterface; +use Thelia\Log\Tlog; +use Thelia\Core\Translation\Translator; + +class ConfigStoreForm extends BaseForm +{ + protected function buildForm() + { + $this->formBuilder + ->add("store_name", "text", array( + "label" => Translator::getInstance()->trans('Store name'), + "label_attr" => array( + "for" => "store_name" + ) + )) + ->add("store_email", "text", array( + "label" => Translator::getInstance()->trans('Store email address'), + "label_attr" => array( + "for" => "store_email" + ) + )) + ->add("store_business_id", "text", array( + "label" => Translator::getInstance()->trans('Business ID'), + "label_attr" => array( + "for" => "store_business_id" + ) + )) + ->add("store_phone", "text", array( + "label" => Translator::getInstance()->trans("Phone"), + "label_attr" => array( + "for" => "store_phone" + ) + )) + ->add("store_fax", "text", array( + "label" => Translator::getInstance()->trans("Fax"), + "label_attr" => array( + "for" => "store_fax" + ) + )) + ->add("store_address1", "text", array( + "constraints" => array( + new Constraints\NotBlank() + ), + "label_attr" => array( + "for" => "store_address1" + ), + "label" => Translator::getInstance()->trans("Street Address ") + )) + ->add("store_address2", "text", array( + "label" => Translator::getInstance()->trans("Address Line 2"), + "label_attr" => array( + "for" => "store_address2" + ) + )) + ->add("store_address3", "text", array( + "label" => Translator::getInstance()->trans("Address Line 3"), + "label_attr" => array( + "for" => "store_address3" + ) + )) + ->add("store_zipcode", "text", array( + "constraints" => array( + new Constraints\NotBlank() + ), + "label" => Translator::getInstance()->trans("Zip code"), + "label_attr" => array( + "for" => "store_zipcode" + ) + )) + ->add("store_city", "text", array( + "constraints" => array( + new Constraints\NotBlank() + ), + "label" => Translator::getInstance()->trans("City"), + "label_attr" => array( + "for" => "store_city" + ) + )) + ->add("store_country", "text", array( + "constraints" => array( + new Constraints\NotBlank() + ), + "label" => Translator::getInstance()->trans("Country"), + "label_attr" => array( + "for" => "store_country" + ) + )) + ; + } + + public function getName() + { + return "thelia_configuration_store"; + } +} diff --git a/templates/backOffice/default/config-store.html b/templates/backOffice/default/config-store.html new file mode 100644 index 000000000..fec18c8cc --- /dev/null +++ b/templates/backOffice/default/config-store.html @@ -0,0 +1,170 @@ +{extends file="admin-layout.tpl"} + +{block name="page-title"}{intl l='Store'}{/block} + +{block name="check-resource"}admin.configuration.store{/block} +{block name="check-access"}update{/block} + +{block name="main-content"} +
+ +
+ + + +
+
+
+ +
+ {intl l="Store configuration"} +
+
+ +
+
+
+ {form name='thelia.configuration.store'} + + {form_hidden_fields form=$form} + + {include + file = "includes/inner-form-toolbar.html" + hide_flags = true + + page_url = "{url path='/admin/configuration/store'}" + close_url = "{url path='/admin/configuration'}" + } +
+
+

{intl l='General'}

+ + {if $form_error} +
{$form_error_message}
+ {/if} + +
+ {form_field form=$form field='store_name'} +
+ + +
+ +
+
+ {/form_field} + + {form_field form=$form field='store_business_id'} +
+ + +
+ +
+
+ {/form_field} + + {form_field form=$form field='store_email'} +
+ + +
+ +
+
+ {/form_field} + + {form_field form=$form field='store_phone'} +
+ + +
+ +
+
+ {/form_field} + + {form_field form=$form field='store_fax'} +
+ + +
+ +
+
+ {/form_field} +
+
+ +

{intl l="Store address"}

+ + {form_field form=$form field='store_address1'} +
+ + +
+ {/form_field} + + {form_field form=$form field='store_address2'} +
+ +
+ {/form_field} + + {form_field form=$form field='store_address3'} +
+ +
+ {/form_field} + + {form_field form=$form field='store_zipcode'} +
+ + +
+ {/form_field} + + {form_field form=$form field='store_city'} +
+ + +
+ {/form_field} + + {form_field form=$form field='store_country'} +
+ + +
+ {/form_field} + + +
+
+ + {include + file = "includes/inner-form-toolbar.html" + hide_flags = true + + page_url = "{url path='/admin/configuration/store'}" + close_url = "{url path='/admin/configuration'}" + } + + + {/form} +
+
+
+
+
+
+
+{/block} diff --git a/templates/backOffice/default/configuration.html b/templates/backOffice/default/configuration.html index dec253917..debaaa6fb 100644 --- a/templates/backOffice/default/configuration.html +++ b/templates/backOffice/default/configuration.html @@ -116,6 +116,13 @@ {module_include location='system_configuration_top'} + {loop type="auth" name="pcc-store" role="ADMIN" resource="admin.configuration.store" access="VIEW"} + + {intl l='Store'} + + + {/loop} + {loop type="auth" name="pcc2" role="ADMIN" resource="admin.configuration.variable" access="VIEW"} {intl l='System variables'}