0

We bought and installed a gift card module from Magestore and when I was testing it on our staging website I noticed that it kept sending emails every two hours for the gift card.

How can I stop these emails? I have read that if I run this mysql command truncate table cron_schedule; it will stop the emails from being sent, but won't that stop every email from being sent?

Also, any tips on how I can go about debugging this issue? I checked the modules code and they have some cron jobs configured...

<crontab>
    <jobs>
        <giftvoucher>
            <schedule>
                <cron_expr>0 0 * * *</cron_expr>
            </schedule>
            <run>
                <model>giftvoucher/observer::autoSendMail</model>
            </run>
        </giftvoucher>
        <giftvoucherschedule>
            <schedule>
                <cron_expr>15 */2 * * *</cron_expr>
            </schedule>
            <run>
                <model>giftvoucher/observer::sendScheduleEmail</model>
            </run>
        </giftvoucherschedule>
        <giftvoucherautodeleteimage>
            <schedule>
                <cron_expr>30 0 * * *</cron_expr>
            </schedule>
            <run>
                <model>giftvoucher/observer::autoDeleteImage</model>
            </run>
        </giftvoucherautodeleteimage>
        <giftvoucherautodeleteimage1>
            <schedule>
                <cron_expr>45 0 1 * *</cron_expr>
            </schedule>
            <run>
                <model>giftvoucher/observer::autoDeleteImage1</model>
            </run>
        </giftvoucherautodeleteimage1>
    </jobs>
</crontab> 

And when I check the Magestore_Giftvoucher_Model_Observer class I see the below functions:

/**
 * Send scheduled email
 */
public function autoSendMail()
{
    if (Mage::helper('giftvoucher')->getEmailConfig('autosend')) {
        $giftVouchers = Mage::getModel('giftvoucher/giftvoucher')->getCollection()
            ->addFieldToFilter('status', array('neq' => Magestore_Giftvoucher_Model_Status::STATUS_DELETED))
            ->addExpireAfterDaysFilter(Mage::helper('giftvoucher')->getEmailConfig('daybefore'));
        foreach ($giftVouchers as $giftVoucher) {
            $giftVoucher->sendEmail();
        }
    }
}

/**
 * Send scheduled email for friend
 */
public function sendScheduleEmail()
{
    $collection = Mage::getResourceModel('giftvoucher/giftvoucher_collection');
    $timeSite = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time()));
    $collection->addFieldToFilter('is_sent', array('neq' => 1))
        ->addFieldToFilter('day_store', array('notnull' => true))
        ->addFieldToFilter('day_store', array('to' => $timeSite));
    if (count($collection)) {
        $translate = Mage::getSingleton('core/translate');
        $translate->setTranslateInline(false);
        foreach ($collection as $giftCard) {
            $giftCard->save();
            if ($giftCard->sendEmailToRecipient()) {
                if ($giftCard->getNotifySuccess()) {
                    $giftCard->sendEmailSuccess();
                }
            }
        }
        $translate->setTranslateInline(true);
    }
}

And in the giftvoucher table their is a field called is_sent, which has a value of 2 for the email address it keeps sending it to.

Do I just need to change the value on is_sent in the database?

1 Answer 1

1

As you might have expected the following cron calls the sendScheduleEmail function every 2 hours.

    <giftvoucherschedule>
        <schedule>
            <cron_expr>15 */2 * * *</cron_expr>
        </schedule>
        <run>
            <model>giftvoucher/observer::sendScheduleEmail</model>
        </run>
    </giftvoucherschedule>

You can change it to not send email so often and remove the current jobs in the cron_schedule table with jobcode giftvoucherschedule.

If you only want the e-mail to be sent once to an e-mailaddress then you need to change a function to update the is_sent value to 1 instead of 2 as soon as the e-mail is sent. However the module should do that by default.

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.