0

I have a crontab for giftcards that get sent when a delivery date is selected. It doesn't appear to be running.

This is in my config.xml:

<crontab>
        <jobs>
            <webtex_giftcards_send_email_by_delivery_date>
                <schedule>
                    <cron_expr>0 1 * * *</cron_expr>
                </schedule>
                <run>
                    <model>giftcards/observer::sendEmailByDeliveryDate</model>
                </run>
            </webtex_giftcards_send_email_by_delivery_date>
        </jobs>
    </crontab>

This is the code in Observer that it's supposed to call:

/**
     * Send email based on delivery date specified by customer
     * starts every day at 01.00 am (see config.xml)
     */
    public function sendEmailByDeliveryDate()
    {
        $currentDate = date('Y-m-d');
        $oGiftCards = Mage::getModel('giftcards/giftcards')->getCollection()
            ->addFieldToFilter('mail_delivery_date', array('eq' => $currentDate))
            ->addFieldToFilter('card_status', 1);
        foreach ($oGiftCards as $oGiftCard) {
            $oGiftCard->send();
        }
    }

1 Answer 1

1

First, I would check that your system cron is running. (Are other crons working, like emails being sent after an order is placed, for example?)

Second, I would write a shell script, like:

<?php
require_once('app/Mage.php');
Mage::app();
$model = Mage::getModel('giftcards/observer');
$model->sendEmailByDeliveryDate()

Save it to shell/testgiftcards.php. Then in your root folder, run "php shell/testgiftcards.php". If that works, then you can rule out your observer code as the problem. Check for any errors in system.log and exception.log.

If you are sure your cron is working, and that the observer code is executing successfully, add a log statement in your observer code:

public function sendEmailByDeliveryDate()
{
    Mage::log("Entered sendEmailByDeliveryDate()");

If you're not seeing that in system.log on a daily basis, then it might have something to do with your config xml, or your module might be set up incorrectly. Hopefully, doing the above will point you in the right direction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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