1

I want realise a cron job for import product in Magento. The code to insert the product into a php file saved in app/code/local/Test/Import/Model.

I saved config.xml in app/code/local/Test/Import/etc. I added module in app/etc/modules.

config.php contains following code:

<config>
     <modules>
        <Test_Import>
            <version>0.0.1</version>
        </Test_Import>
    </modules>

    <global>
        <models>
            <importcron>
                <class>Test_Import_Model</class>
            </importcron>
        </models>
    </global> 
    <crontab>
        <jobs>
            <importcron>
                <schedule>
                    <cron_expr>*/1 * * * *</cron_expr>
                </schedule>
                <run>
                    <model>importcron/observer::importProduct</model>
                </run>
            </importcron>
        </jobs>
    </crontab>
</config>

The folder app/code/local/Test/Import/controllers is empty.

I tried to run this cron job through url 127.0.0.1/magento/Import but the result is '404 PAGE NOT FOUND'.

In Magento panel control this module is not inserted in modules list in System/Configuration/Advanced.

Can you help me, please? Thank you very much!

2

you cannot run cron jobs directly from browser. You should create controller:

class Test_Import_IndexController extends Mage_Core_Controller_Front_Action
{
     public function indexAction()
     {
           Mage::getModel('importcron/observer')->importProduct();
     }
}

and add router to <config> section of config.xml file

<frontend>
    <routers>
        <testimport>
            <use>standard</use>
            <args>
                <module>Test_Import</module>
                <frontName>testimport</frontName>
            </args>
        </testimport>
    </routers>
</frontend>

Next you can run 127.0.0.1/magento/testimport/index/index from your browser

  • Thank you very much!! Can I ask you why do i have to call the function getModel('importcron/observer')->importProduct() in the controller class? many thanks! – Federica Aug 26 '16 at 14:31
  • Cron jobs are running on schedule. If you do not want to wait scheduled time, and you want to run cron job right now, you have to open specific url in browser ( 127.0.0.1/magento/testimport/index/index for our example ). Corresponding to this url Test_Import_IndexController and indexAction start cron job importcron/observer::importProduct with next syntax Mage::getModel('importcron/observer')->importProduct(); – Neklo.com Sep 9 '16 at 12:34

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.