1

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();
                }
            }
        }
    }
?>
James
  • 529
  • 1
  • 7
  • 16
  • 1
    Are you able to make a "sent" column in the table as a boolean, when sent, mark the row as sent so it doesn't send again. Just check if the card is sent before actually sending it. – GrumpyCrouton Oct 16 '17 at 20:45

0 Answers0