Search code examples
configurationprestashopprestashop-1.6

Configure prestashop through theme configuration


I am wondering if it possible to configure some of the shop’s options when enabling a theme.

Let me explain, I am already generating a config.xml in the root of the theme zip to enable/disable some modules or hooks. But I want to do more.

Indeed, I would like to be able to, for example, enable the CCC “Move JavaScript to the end” when the theme.

I see that some themes (including the community theme) include a config.xml inside the theme folder. I often see stuff like <ccc available="true" />.

But I’m not sure it does anything. Does it do anything?

I can’t find any reference for that config.xml file, is there any way to achieve what I want?

Using the latest Prestashop 1.6.


Solution

  • Those lines check configuration values but only when <ccc available="false" />.

    So if you have <ccc available="true" /> you are saying that your theme is CCC compatible and it doesn't matter if the shop has CCC enabled or not.

    If you set that to false, the installation will check if settings related to CCC are disabled, otherwise it will throw an error to the user that their CCC configurations will not work with your theme.

    You can see feature definitions here.

        'ccc' => array(
            'attributes' => array(
                'available' => array(
                    'value' => 'true',
                    /*
                     * accepted attribute value if value doesn't match, prestashop configuration value must have those values
                    */
                    'check_if_not_valid' => array(
                        'PS_CSS_THEME_CACHE' => 0,
                        'PS_JS_THEME_CACHE' => 0,
                        'PS_HTML_THEME_COMPRESSION' => 0,
                        'PS_JS_HTML_THEME_COMPRESSION' => 0,
                    ),
                ),
            ),
            'error' => 'This theme may not correctly use PrestaShop\'s "combine, compress and cache" options.',
            'tab' => 'AdminPerformance',
        )
    

    So if you set in your config.xml <ccc available="false" /> it will check that all four configurations in check_if_not_valid array are set to 0, otherwise it's gonna throw out an error message This theme may not correctly use PrestaShop's "combine, compress and cache" options..

    As for configuring settings on theme install, I don't see a way to do it with xml config without overriding AdminThemesController class but I'm guessing you want to distribute this theme so overriding is not an option.

    What you could do though is install a simple configuration setter module along with the theme that hooks to displayAfterThemeInstallation.

    public function hookDisplayAfterThemeInstallation($params)
    {
        $theme_name = $params['theme_name'];
        if ($theme_name != 'mythemename') {
            return false;
        }
        // Enable Move JS to bottom setting
        Configuration::updateValue('PS_JS_DEFER', 1);
    
        // Optional text or html to display 
        return 'Your settings have been changed';
    }