Jump to content

Send Mail after 30 days from purchase


Epizefiri

Recommended Posts

Hi there,

i'm a LAMP developer with no experience with prestashop.

 

I've just read a lot of documentation and topics on this forum but i need some help about email template.

 

I just want to create a module "ready to install" for prestashop, where after 30 days from purchase i send a specific mail template to the customer.

 

Can anyone direct me to the proper documentation?

 

thanks

Link to comment
Share on other sites

Here are two parts, not necessarily dependent on each other. You say you want to send an email 30 days after purchase date. I would make this a cronjob, where you daily run a script that checks purchase dates, and when found one that is 30 days old, send an Email. Google for how to connect the php script to the database (google PrestaShop cron script open and close shop or so for some examples) and then use SQL - SELECT to query the database.

 

 

 

If you like to make a module, I suggest the following path:

 

I suggest to first of all make yourself comfortable with php (search for some online tutorials / manuals etc) and smarty.

 

Then look at the PrestaShop developers guide. here you can find info on how PrestaShop is generally working, coding guidelines, on how to set up a new module, build a configuration page etc.

 

 

If yo want to know more on how from within PrestaShop you send an Email, I suggest to have a look at the blocknewsletter module source code, where you can see how an Email is sent, using for example this function:

 

protected function sendConfirmationEmail($email)
{
  return Mail::Send($this->context->language->id, 'newsletter_conf', Mail::l('Newsletter confirmation', $this->context->language->id), array(), pSQL($email), null, null, null, null, null, dirname(__FILE__).'/mails/', false, $this->context->shop->id);
}
 
 
When starting from zero, maybe first play with building some simple module that displays something on the page, and from there continue towards your goal. Success!
 
 
My 2 cents,
pascal.
Link to comment
Share on other sites

 

Here are two parts, not necessarily dependent on each other. You say you want to send an email 30 days after purchase date. I would make this a cronjob, where you daily run a script that checks purchase dates, and when found one that is 30 days old, send an Email. Google for how to connect the php script to the database (google PrestaShop cron script open and close shop or so for some examples) and then use SQL - SELECT to query the database.

 

 

 

If you like to make a module, I suggest the following path:

 

I suggest to first of all make yourself comfortable with php (search for some online tutorials / manuals etc) and smarty.

 

Then look at the PrestaShop developers guide. here you can find info on how PrestaShop is generally working, coding guidelines, on how to set up a new module, build a configuration page etc.

 

 

If yo want to know more on how from within PrestaShop you send an Email, I suggest to have a look at the blocknewsletter module source code, where you can see how an Email is sent, using for example this function:

 

protected function sendConfirmationEmail($email)
{
  return Mail::Send($this->context->language->id, 'newsletter_conf', Mail::l('Newsletter confirmation', $this->context->language->id), array(), pSQL($email), null, null, null, null, null, dirname(__FILE__).'/mails/', false, $this->context->shop->id);
}
 
 
When starting from zero, maybe first play with building some simple module that displays something on the page, and from there continue towards your goal. Success!
 
 
My 2 cents,
pascal.

 

 

Hi Pascal,

your advice was very helpful!

 
Reviewing briefly the architecture of what I'm doing I can waive the 30-day delay on sending the email.
 
I then created a module that sends an e-mail just completed a new order.
 
You can take a look at my code? What do you think?
 
 
<?php   
if (!defined('_PS_VERSION_'))
  exit;
  
class projectx extends Module
{
  public function __construct()
  {
    $this->name = 'projectx';
    $this->tab = 'emailing';
    $this->version = '0.0.1';
    $this->author = 'Intraweb Srl';
    $this->need_instance = 0;
    $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); 
    $this->bootstrap = true;
 
    parent::__construct();
 
    $this->displayName = $this->l('projectx');
    $this->description = $this->l('Modulo necessario per ricevere ed inviare coupon projectx..');
 
    $this->confirmUninstall = $this->l('Argh! Se mi disinstalli il cielo cadrà, le cavallette distruggeranno i raccolti, tutto il vino diverrà aceto e.. ok, ok, in realtà non è così tragico ma vuoi veramente non inviare Coupon projectx ai tuoi clienti?');
 
    if (!Configuration::get('projectx_NAME'))      
      $this->warning = $this->l('No name provided');
  }

function install()  {
  if ( parent::install() == false OR
  !$this->registerHook( 'newOrder' ) )
   return false;
  return true;
}

public function uninstall()   {
	if (!parent::uninstall())
	 return false;
  }
  
/* Test newOrder hook*/
function hookNewOrder($email) {
  Mail::Send($this->context->language->id,'test','Test mail','coupon','[email protected]','My name');
}

}
 
You have the documentation about the variables of "Mail :: Send"?
Edited by Epizefiri (see edit history)
Link to comment
Share on other sites

  • 1 year later...
The code that you have written to send mail on a new order is correct.

 

To send the email after 30 days you can simply create a function in a front controller of your module to send emails in bulk and then calling the function through a cron.

 

File cron.php at /module/YOUR_MODULE_NAME/controllers/front/cron.php path should be something like this.

 




class {YOUR_MODULE_NAME}CronModuleFrontController extends ModuleFrontController
{
public function initContent()
{
             parent::initContent();
        }


        pubic function sendMailAfterThirtyDays()
        {
               --------------- Code to send bulk emails -----------------------
        }
}


Edited by Knowband Plugins (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...