DmitryFursNeklo
12/12/2016 - 12:10 PM

Custom CSS as module configuration option

Custom CSS as module configuration option

<additional_css translate="label, comment">
    <label>Additional CSS</label>
    <frontend_type>textarea</frontend_type>
    <sort_order>2</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
    <backend_model>company_module/config_css</backend_model>
</additional_css>
<?php

class Company_Module_Model_Config_Css extends Mage_Core_Model_Config_Data
{
    protected function _afterSave()
    {
        if ($this->isValueChanged()) {
            $skinPath = 'skin' . DS . 'frontend' . DS . 'base' . DS . 'default' . DS . 'company' . DS . 'module' . DS;
            try {
                $ioFile = new Varien_Io_File();
                $ioFile->open(
                    array(
                        'path' => $skinPath,
                    )
                );
                $ioFile->filePutContent(
                    $skinPath . 'additional.css',
                    $this->getValue()
                );
            } catch (Exception $e) {
                // TODO: add error msg
            }
        }
        return parent::_afterSave();
    }
}