Get Free Audit

How to Set Expressions for Separate Cron Tasks Via Admin Settings in Magento

Jul 2, 2014

1038 Andrei Danilchyk

How to Set Expressions for Separate Cron Tasks Via Admin Settings in Magento

Sometimes you  need to add the ability to change cron expression for separate tasks in the admin panel through module settings. It is important to note that native Magento does not offer such possibility by default, however, it has this mechanism included. Let’s have a look at a default task catalog_product_index_price_reindex_all  in the module Mage_Catalog:

File <magento_root>/app/code/core/Mage/Catalog/etc/config.xml:


As we can see the cron expression is statically defined through xml. The same implementation is typical for all standard cron  jobs in Magento. Let’s check app/code/core/Mage/Cron/Model/Observer.php:

File <magento_root>/app/code/core/Mage/Cron/Model/Observer.php:

Vlad Yunusov
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Vlad


As we can see before using the node  <сrоn_expr>, we first check for the node <соnfig_pаth> and  in case it is verified then we attempt to get the value for the cron expression through Mage::getStoreConfig() by using the values of that very node as the path. As you can see it is pretty easy to set a cron task for using some settings in the admin panel.  Let’s take a simple example:

In the system.xml file of the module we create a cron expression setting:


In the config.xml file we register the cron task:


Now cron expression can be set in the admin settings by using standard cron syntax.

Vlad Yunusov
Partner With Us Looking for a partner that will help you to grow your business? We are the right company to develop your webstore. Feel free to get in touch with us. We will be happy to discuss your business opportunities and provide you with a Free Quote. Talk to Vlad
Tags:

2 Comments

  1. Hi! Thanks for the question. Unfortunately, we need more data to be able to help you. Please, provide us with more details or write to our support department: [email protected]. We’ll be happy to assist.

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *