I'm trying to implement a Gift Card extension in Magento. It is this extension: https://www.webtexsoftware.com/gift-cards-magento-extension
The problem that I'm having is that I've enabled the Email Delivery Date field, but what happens is that when that date comes, it won't stop sending emails. It sends 1 email every minute!
I do have a cronjob that runs every minute to look for gift certs that have to be sent, but that should not be causing this issue, to my knowledge.
I've tried everything I can think of to ensure that this doesn't run twice on the same gift card, but it somehow does. Any ideas? I do want this to run every minute to make sure I'm getting every GC sent out as quickly as possible, but what I don't want is to re-send every GC every minute.
This is the PHP file that my cronjob calls every minute:
<?php
ini_set('memory_limit', '128M');
define('MAGENTO_ROOT', getcwd());
// exit;
$time = time();
$time2 = $time - 0;
$to = date('Y-m-d H:i:s', $time2);
$lastTime = $time - 120; //3600; // Orders from the past half hour
$from = date('Y-m-d H:i:s', $lastTime);
$mageFilename = ''; //removed for security
require_once $mageFilename;
Mage::app();
$order_collection = Mage::getResourceModel('sales/order_collection');
// $order_collection->addFieldToFilter('status', 'pending')
$order_collection->addAttributeToSelect('*')->addAttributeToFilter('updated_at', array(
'from' => $from,
'to' => $to
))
// ->addAttributeToFilter('updated_at', array('from' => $from, 'to' => $to))
->getSelect();
print count($order_collection);
foreach($order_collection->getItems() as $order) {
$cards = Mage::getModel('giftcards/giftcards')->getCollection()->addFieldToFilter('order_id', $order->getId());
print count($cards);
foreach($cards as $card) {
if (($card->getCardStatus() == 0) && ($curDate == $card->getMailDeliveryDate())) {
$card->setCardStatus(1)->save();
if ((($card->getMailDeliveryDate() == null) || ($curDate == $card->getMailDeliveryDate())) && $card->getCardType() != 'offline') {
$card->send();
}
}
}
}
?>