I would like to send my customers a mail, after a week, when the order has been completed.
Can someone help me? (Magento 1.9.2).
I also found a topic about this issue, but it is not updated for a while.
My code for so far:
Config.xml:
<?xml version="1.0"?>
<config>
<modules>
<Productreviews_Productreview>
<version>0.1.0</version>
</Productreviews_Productreview>
</modules>
<global>
<helpers>
<cronexample>
<class>Productreviews_Productreview_Helper</class>
</cronexample>
</helpers>
<models>
<cronexample>
<class>Productreviews_Productreview_Model</class>
<resourceModel>cronexample_mysql4</resourceModel>
</cronexample>
</models>
</global>
<crontab>
<jobs>
<send_productreview>
<schedule><cron_expr>5 * * * *</cron_expr></schedule>
<run><model>cronexample/cron::cronSendReviewMail</model></run>
</send_productreview>
</jobs>
</crontab>
</config>
Cron.php:
<?php
class Productreviews_Productreview_Model_Cron{
public function cronSendReviewMail(){
Mage::log("Cron Test ".now(),null,"mageCronExample.log");
$time = time();
$to = date('Y-m-d H:i:s', $time);
$lastTime = $time - 604800; // 60*60*7*24
$from = date('Y-m-d H:i:s', $lastTime);
$order_collection = Mage::getModel('sales/order')
->getCollection()
->addAttributeToSelect('*')
->setPageSize(5)
->setOrder('created_at', 'desc')
->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to))
->addAttributeToFilter('status', array('==' => array('complete')));
foreach ($order_collection as $item) {
// echo $item->getId();
$sendtoemail = $item->getShippingAddress()->getEmail();
$idid = $item->getIncrementId();
$order = $item->loadByIncrementId($idid);
$items = $order->getAllVisibleItems();
// EMAIL LAYOUT
$email = 'Email content here';
// EMAIL VERSTUREN
$to = $sendtoemail;
$subject = 'Subject';
$headers = 'From: x@example.com' . "\r\n" .
'Reply-To: x@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to, $subject, $email, $headers);
}
}
}