Jump to content

Send An Email On Actionorderstatuspostupdate Hook


Recommended Posts

Hi,

 

I'm new in prestashop development and I'm trying to develop a carrier module. I would like to send me an email through this hook actionOrderStatusPostUpdate but nothing happens.

 

I put the code below :

public function install()
{
  return parent::install() && $this->registerHook('actionCarrierUpdate') && $this->registerHook('actionOrderStatusPostUpdate');
}

public function hookActionOrderStatusPostUpdate($params)
{
  Mail::Send((int)Configuration::get('PS_LANG_DEFAULT'),'testmail', 'test email', array('{customer_firstname}' => 'Manu'), '[email protected]', null, null, null, null, null, dirname(__FILE__).'/mails/');	
}

I create the directory /mails/ and inside /fr/, /en/ with testmail.php and testmail.txt. I put the code below :

Hello {customer_firstname}

I don't know why I don't receive an email when an order is confirmed and paid.

Is it wrong that I use the mail function or use of the hook is not good ?

 

Thks

Manu

 

Link to comment
Share on other sites

I create the directory /mails/ and inside /fr/, /en/ with testmail.php and testmail.txt. I put the code below :

 

it should be testmail.html and testmail.txt

 

Instead of using Mail::send function, try writing something to a log file just to confirm that your hook is being executed.  Once you know the hook is being executed, then troubleshoot the mail

Link to comment
Share on other sites

it should be testmail.html and testmail.txt

 

Instead of using Mail::send function, try writing something to a log file just to confirm that your hook is being executed.  Once you know the hook is being executed, then troubleshoot the mail

 

Hi bellini13,

First of all, thanks for extension of my file.

I tried to write to a log file , but nothing happens. So I think the problem is with my hook however I boot into the install() and I called. I don't know why it isn't executed.

 

Hey Manu,

 

Any Progress  regarding your topic because i m trying to send mail when order status is cancelled to admin and vendor in case more than one vendor.

Thank You.

 

Hey SatishMasani,

For the moment any progress. I have a problem with my hook, it seems that not execute but I do not know why.

Link to comment
Share on other sites

I don't know what this means...

 

The 'actionOrderStatusPostUpdate' hook is executed whenever an order status is changed.  So how are you testing this exactly?

 

Before I have a question : the 'actionOrderStatusPostUpdate' hook is executed with a module which extends 'CarrierModule', because I saw on other module that this hook is called for module which extends 'PaymentModule' ?

 

Otherwise I put this code into my hook :

public function hookActionOrderStatusPostUpdate($params)
{
  if(!empty($params['newOrderStatus'])) {
    if ($params['newOrderStatus']->id == Configuration::get('PS_OS_WS_PAYMENT') || $params['newOrderStatus']->id == Configuration::get('PS_OS_PAYMENT'))
      $this->addLogEvent("payment accepted");
    }
  }
}

function addLogEvent($event)
{
  file_put_contents("fichier.log", $event, FILE_APPEND);
}

But nothing hapens :(.

 

Thanks for your help

Manu

Link to comment
Share on other sites

I'm really not sure what you are trying to accomplish or saying.

 

How are you testing the triggering of the 'actionOrderStatusPostUpdate'.  Did you create an order and then update the order status from the back office?

 

If not, why would this hook be triggered?

Link to comment
Share on other sites

Hi bellini13,

 

I'm really not sure what you are trying to accomplish or saying.

 

How are you testing the triggering of the 'actionOrderStatusPostUpdate'.  Did you create an order and then update the order status from the back office?

 

If not, why would this hook be triggered?

 

For testing I create an order and into my back office I change the status to "payment accepted" but nothing happens. I receive an email with my customer account for my order with the summary statement but not for my carrier (different email).

 

I would like to use this hook to receive an email when the status of an order become "payment accepted" (by the back office and payment directly : credit card, etc), so this hook is the best way for this, isn't it ?

Link to comment
Share on other sites

so this hook is the best way for this, isn't it ?

 

No, since this hook would be called everytime the order status changes, not just for 'payment accepted'.  it is also called after all processing is complete.  so if processing never completes (due to an error perhaps), then the hook would never be called.

 

the better hook is 'actionPaymentConfirmation', which is called when the order status is 'PS_OS_PAYMENT' or 'PS_OS_WS_PAYMENT' (aka 'payment accepted')

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

  • 2 weeks later...

One more thing you can use this hook to send mail when order status is changed but not when new order is created.

 

1.For sending mail when  a new order is placed is done by mail-alert module they use hookActionValidateOrder($params) to check the new order and send mail new_order.

2. So just use hookActionOrderStatusPostUpdate and check the status if payment accepted send mail and use the template which u want. 

 

Go to back office Order-> Statues and check which email statement is used for Payment accepted status.

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...