1

I need to get data from core_config_data table in xml nodes, For example I have a value * /5 * * *. I want get this value in xml like following,

    <crontab>
            <jobs>            
            <stock_setcron>
                    <schedule>
                    <cron_expr>*/5 * * * *</cron_expr>
                    </schedule>
                    <run><model>stock/cron::setcron</model></run>
                </stock_setcron>
            </jobs>
     </crontab>

How to do that..Please help me guys ..

  • have you made any configuration to store cron value in magento backend ? – Pradeep Sanku Jun 26 '14 at 18:40
2

You Need to create one small module for this.First of all create a file in app/etc/module folder.lets say file name is yourpackagename_yourmodulename.xml and the following content in this file.

<?xml version="1.0"?>
<config>
    <modules>
        <Yourpackagename_Yourmodulename>
            <active>true</active>
            <codePool>local</codePool>
        </Yourpackagename_Yourmodulename>
    </modules>
</config>

Now create config.xml file in app/code/local/Yourpackagename/Yourmodulename/etc folder and following code in config.xml file.

<?xml version="1.0"?>
<config>
    <modules>
        <Yourpackagename_Yourmodulename>
            <version>0.0.1</version>
        </Yourpackagename_Yourmodulename>
    </modules>
    <global>
        <helpers>
            <yourmodulename>
                <class>Yourpackagename_Yourmodulename_Helper</class>
            </yourmodulename>
        </helpers>
    </global>
    <adminhtml>
        <acl>
            <resources>
                <admin>
                    <children>
                        <system>
                            <children>
                                <config>
                                    <children>
                                        <yourmodulename_options>
                                            <title>some text</title>
                                        </yourmodulename_options>
                                    </children>
                                </config>
                            </children>
                        </system>
                    </children>
                </admin>
            </resources>
        </acl>
    </adminhtml>
</config>

Now create system.xml file in app/code/local/Yourpackagename/Yourmodulename/etc folder and following code in config.xml file.

<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <tabs>
        <yourmodulename translate="label" module="yourmodulename">
            <label>some text</label>
            <sort_order>999</sort_order>
        </yourmodulename>
    </tabs>
    <sections>
        <yourmodulename_options translate="label" module="yourmodulename">
            <label>some text</label>
            <tab>yourmodulename</tab>
            <frontend_type>text</frontend_type>
            <sort_order>1000</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store> 
            <groups>
                <yourmodulename_links translate="label">
                    <label>Cron</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>1</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <cronexpr>
                            <label>cronexpr</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>                    
                        </cronexpr>
                    </fields>
                </yourmodulename_links>
            </groups>
        </yourmodulename_options>
    </sections>
</config>

Now create Helper folder in app/code/local/Yourpackagename/Yourmodulename/Helper and in this folder create Data.php with following content

<?php
class Yourpackagename_Yourmodulename_Helper_Data extends Mage_Core_Helper_Abstract
{

}
?>

now refresh site and clear cache and go to admin you will see new config created and put your cron value their and use the saved value with the foloowing code wherver you need.

<crontab>
    <jobs>            
        <stock_setcron>
            <schedule>
                <cron_expr>yourmodulename_options/yourmodulename_links/cronexpr</cron_expr>
            </schedule>
            <run><model>stock/cron::setcron</model></run>
        </stock_setcron>
    </jobs>
</crontab>
  • check my edited answer – Pradeep Sanku Jun 26 '14 at 19:10
  • Thanks for yr help pradeep..But I got it by another way, <config_path>sectionname/groupname/fieldname></config_path>. But you gave me a nice information ..Thanks again .. – Elavarasan Jun 26 '14 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.