
MAGENTO 1.X – HOW TO CREATE AND CHANGE CUSTOM VARIABLES PROGRAMATTICALLY
Magento manage two differents values per custom variable: HTML and PLAIN, those, are filled like the example below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$variable = Mage::getModel('core/variable')->loadByCode('variable-code'); if(is_null($variable)){ Mage::getModel('core/variable') ->setCode('variable-code') ->setName('Name of your variable') ->setPlainValue("YOUR PLAIN VALUE") ->setHtmlValue("YOUR HTML VALUE") ->save(); }else{ $variable->setPlainValue("YOUR PLAIN VALUE") ->setHtmlValue("YOUR HTML VALUE") ->save(); } |
Then, you can get those values as follows:
1 2 3 |
echo Mage::getModel('core/variable')->loadByCode('variable-code') ->getValue('text'); echo Mage::getModel('core/variable')->loadByCode('variable-code') ->getValue('html'); |
Also, you can manage this kind of variables on your Magento backend, going to system > custom variables.