Skip to content

Commit

Permalink
Merge pull request #4 from Sinepel/develop
Browse files Browse the repository at this point in the history
FR translation + error/success notification + improvements
  • Loading branch information
nenes25 authored Apr 10, 2020
2 parents 12d41ac + a143099 commit 0480cf2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 21 deletions.
59 changes: 38 additions & 21 deletions fop_customcss.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand All @@ -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();
}

/**
Expand Down Expand Up @@ -118,6 +119,8 @@ protected function renderForm()

/**
* Create the structure of your form.
*
* @return array
*/
protected function getConfigForm()
{
Expand All @@ -139,7 +142,7 @@ protected function getConfigForm()
),
array(
'type' => 'html',
'name' => '<textarea style="display:none" name="css_real_value">' . Tools::file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . $this->css_file) . '</textarea>',
'name' => '<textarea style="display:none" name="css_real_value">' . Tools::file_get_contents($this->getCssFile()) . '</textarea>',
),

),
Expand All @@ -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);
}

/**
Expand All @@ -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;
}
}
12 changes: 12 additions & 0 deletions translations/fr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

global $_MODULE;
$_MODULE = array();
$_MODULE['<{fop_customcss}prestashop>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';

0 comments on commit 0480cf2

Please sign in to comment.