Jump to content

Trying to use the newOrder hook


wolfib

Recommended Posts

Hello,

 

I'm developping a module for my website and I need to use the newOrder hook. But it doesn't work. Trying to test the hook by sending an email when a new order is done, I've written someting really simple. Here's my code :

 

<?php
class Nicotest extends Module {
function __construct()  {
 $this->name = 'nicotest';
 $this->tab = 'Nico';
 $this->version = 0.1;
 $this->author = 'Nico';
 $this->need_instance = 0;
 parent::__construct();

 $this->displayName = $this->l('Nico test');
 $this->description = $this->l('Description du module à Nico');

 parent::__construct();
}

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($params) {
 Mail::Send(2,'test','Test de mail','Salut','[email protected]','My name');
}

}
?>

 

I never receive any email (it works for standard prestashop emails like orders). I've checked in the position module tab and my module is well known by my prestashop website.

 

Does this hook some special code to work ? Tried to find some help on Google but it seems that it's not the most used hook...

 

Thanks for any help !

 

Wolfib

Link to comment
Share on other sites

the 4th parameter is the template variables which needs to be an array otherwise the Send function will return false

 

   	 if (!is_array($templateVars))
       {
            Tools::dieOrLog(Tools::displayError('Error: parameter "templateVars" is not an array'), $die);
            return false;
       }

  • Like 2
Link to comment
Share on other sites

  • 3 months later...
  • 3 years later...

Hi ! I got a problem on this newOrder hook. It seems to never be executed. Here's the code I use to test the execution of the hook : 

    public function install()
    {
      if (!parent::install() OR
        !$this->alterTable('add') OR         
        !$this->registerHook('footer') OR
        !$this->registerHook('actionCartSave') OR
        !$this->registerHook('newOrder'))         
        return false;
      return true;
    }

    public function hookActionCartSave($params){
      error_log("Cart saved");
    }

    
    public function hookNewOrder($params)
    {
        error_log("Order created");
    }

So if I add a product to the cart, I can see "Cart saved" in my error_log

If I check after an order creation like with Paypal sandbox I never get anything. I check that the IPN is sent and the order is created ... Which should have executed the newOrder hook right ? 

 

Thanks for your help in advance :) 

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