diff --git a/fop_customcss.php b/fop_customcss.php index 14c8181..66d218e 100644 --- a/fop_customcss.php +++ b/fop_customcss.php @@ -56,7 +56,7 @@ public function __construct() parent::__construct(); - $this->displayName = $this->l('FOP - Custom css'); + $this->displayName = $this->l('FOP - Custom CSS'); $this->description = $this->l('Add some custom css for your template'); $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); @@ -76,16 +76,17 @@ public function install() */ public function getContent() { - /** - * If values have been submitted in the form, process. - */ - if (((bool) Tools::isSubmit('submitFop_customcssModule')) == true) { - $this->postProcess(); + $notifcation = null; + + if (((bool) Tools::isSubmit('submitFop_customcssModule')) === true) { + if ($this->postProcess()) { + $notifcation =$this->displayConfirmation($this->l('Custom CSS saved !')); + } else { + $notifcation = $this->displayError($this->l('An error was occured during save.')); + } } - $this->context->smarty->assign(['module_dir', $this->_path]); - - return $this->renderForm(); + return $notifcation . $this->renderForm(); } /** @@ -118,6 +119,8 @@ protected function renderForm() /** * Create the structure of your form. + * + * @return array */ protected function getConfigForm() { @@ -139,7 +142,7 @@ protected function getConfigForm() ), array( 'type' => 'html', - 'name' => '', + 'name' => '', ), ), @@ -152,30 +155,35 @@ protected function getConfigForm() /** * Set values for the inputs. + * + * @return array */ protected function getConfigFormValues() { return array( - 'FOP_CUSTOMCSS_' => Tools::file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . $this->css_file), + 'FOP_CUSTOMCSS_' => Tools::file_get_contents($this->getCssFile()), ); } /** - * Save form data. + * Save form data + * + * @return bool */ protected function postProcess() { - + $result = false; $compiledCSS = Tools::getValue('css_real_value'); - - $css_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . $this->css_file; - - file_put_contents($css_file, $compiledCSS); - - //update cache version of ccccss + $cssFilePath = $this->getCssFile(); $version = (int) Configuration::get('PS_CCCCSS_VERSION'); - Configuration::updateValue('PS_CCCCSS_VERSION', ++$version); + // Write CSS in file + if (false !== file_put_contents($cssFilePath, $compiledCSS)) { + $result = true; + } + + //Update cache version of ccccss & return + return $result && Configuration::updateValue('PS_CCCCSS_VERSION', ++$version); } /** @@ -197,8 +205,17 @@ public function hookBackOfficeHeader() */ public function hookHeader() { - if (file_exists(dirname(__FILE__) . DIRECTORY_SEPARATOR . $this->css_file)) { + if (file_exists($this->getCssFile())) { $this->context->controller->addCSS($this->_path . $this->css_file); } } + + /** + * Return CSS file path + * + * @return string + */ + private function getCssFile() { + return dirname(__FILE__) . DIRECTORY_SEPARATOR . $this->css_file; + } } diff --git a/translations/fr.php b/translations/fr.php new file mode 100644 index 0000000..a7951c3 --- /dev/null +++ b/translations/fr.php @@ -0,0 +1,12 @@ +fop_customcss_6c8955a3bed22711cf6afb7eaa5a20fc'] = 'FOP - Custom CSS'; +$_MODULE['<{fop_customcss}prestashop>fop_customcss_a2cf0507b2e8f530e13ea6d093a36537'] = 'Personnalisez votre boutique en y ajoutant du CSS personnalisé'; +$_MODULE['<{fop_customcss}prestashop>fop_customcss_6066a42946fe9e9374b5f80c84207f3a'] = 'CSS personnalisé sauvegardé !'; +$_MODULE['<{fop_customcss}prestashop>fop_customcss_283b01d5c55830c98ad76c2f294e82e0'] = 'Une erreur est survenue lors de l\'enregistrement'; +$_MODULE['<{fop_customcss}prestashop>fop_customcss_f4f70727dc34561dfde1a3c529b6205c'] = 'Paramètres'; +$_MODULE['<{fop_customcss}prestashop>fop_customcss_42e6feb7f76e910efcda54034ecc83ce'] = 'CSS personnalisé'; +$_MODULE['<{fop_customcss}prestashop>fop_customcss_0343dd0268c320841a78d7a66443e4cb'] = 'CSS'; +$_MODULE['<{fop_customcss}prestashop>fop_customcss_c9cc8cce247e49bae79f15173ce97354'] = 'Enregistrer';