I need help or an explanation to send an email once, to people who do not pay bank transfer or bank check (status pending) after 7 days.
Example: A customer orders today by bank transfer. If after 7 days I still have not received the transfer, I send one and only one email to the customer to restart the payment.
How can I do this?
I create a custom module with cron job and observer and helper: This is my cronjob :
<crontab>
<jobs>
<custom_standbypayement>
<schedule>
<cron_expr>*/1 * * * *</cron_expr>
</schedule>
<run>
<model>custom_standbypayement/observer::checks</model>
</run>
</custom_standbypayement>
</jobs>
</crontab>
My Observer :
public function checks() {
// $arrayEmail = Mage::helper('standbypayement/data')->cancelPendingOrders();
$arrayEmailEmpty = Mage::helper('standbypayement/data')->cancelPendingOrders();
}
this is my helper who gets all order with state pending and sends email transactional
public function getPayementBankTransfertStandBy(){
$olderThan = 7; //7 days
$date = date('Y-m-d', mktime(0,0,0, date('m'), date('d') + $olderThan, date('Y')));
var_dump($date) .'</br>';
//get orders with no update in the last 7 days
$collection = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('status', 'pending')
->addFieldToFilter('updated_at', array('lt'=>$date));
return $collection;
}
public function cancelPendingOrders() {
$arrayEmail = array();
foreach ($this->getPayementBankTransfertStandBy() as $order) {
echo $order->getIncrementId() .' - '. $order->getCreatedAt() .'</br>';
$arrayEmail[] = $order;
$this->StandByPayement($order);
}
return $arrayEmail;
}
public function StandByPayement($order) {
$storeId = Mage::app()->getStore()->getId();
$email = $order->getCustomerEmail();
$senderName = Mage::getStoreConfig('trans_email/ident_support/name');
$senderEmail = Mage::getStoreConfig('trans_email/ident_support/email');
$sender = array('name' => $senderName,
'email' => $senderEmail);
$paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment())
->setIsSecureMode(true);
$paymentBlock->getMethod()->setStore($storeId);
$paymentBlockHtml = $paymentBlock->toHtml();
$vars = array(
'order' => $order,
'billing' => $order->getBillingAddress(),
'payment_html' => $paymentBlockHtml
);
//var_dump($vars);
//die();
$templateIdEn = 55;
$templateIdDeutsch = 56;
$translate = Mage::getModel('core/email_template');
$translate->sendTransactional($templateIdEn, $sender, $email,'', $vars, $storeId);
}
Can you help me? I want to send just once email if the status of payment is always pending after the day of purchase
Thank you