clarkk Posted December 2, 2012 Share Posted December 2, 2012 (edited) Hi there.. I want to build my own small and very simple module.. The only thing I want it to do is to trigger a script each time an new invoice number is generated. I want to record all sales in an external service.. Could anyone please give me a lead where to look in the code or even better a good tutorial which enlightenings this topic? I'm new to prestashop so please be gentle Edited December 2, 2012 by clarkk (see edit history) Link to comment Share on other sites More sharing options...
musicmaster Posted December 3, 2012 Share Posted December 3, 2012 I don't know enough to have a precise solution. But maybe this is enough for you: What you could do is to change the settings so that when a new order is created automatically a new invoice is generated. You could then change the mailalerts module to do what you want. Link to comment Share on other sites More sharing options...
clarkk Posted December 3, 2012 Author Share Posted December 3, 2012 Is it possible to do it as an install-able module with separate files? Link to comment Share on other sites More sharing options...
musicmaster Posted December 3, 2012 Share Posted December 3, 2012 Sure, it is possible. But it will be a steep learning curve - with which I can't help you. Replacing a file in the module is clean and much less complicated Link to comment Share on other sites More sharing options...
clarkk Posted December 3, 2012 Author Share Posted December 3, 2012 could you then tell me which module I need to replace if I want to trigger some code whenever a new invoice number and a new sale is made? I need to record all sales in an external service (accounting) Link to comment Share on other sites More sharing options...
El Patron Posted December 3, 2012 Share Posted December 3, 2012 use hook http://doc.prestashop.com/display/PS15/Hooks+in+PrestaShop+1.5 Link to comment Share on other sites More sharing options...
clarkk Posted December 4, 2012 Author Share Posted December 4, 2012 Sure, it is possible. But it will be a steep learning curve - with which I can't help you. Replacing a file in the module is clean and much less complicated which module would you choose? the module should only run as a background service Link to comment Share on other sites More sharing options...
clarkk Posted December 4, 2012 Author Share Posted December 4, 2012 (edited) I have tried to write some code here, but it doesn't seem to work.. The module is installed successfully in the backoffice without errors Have added a test hook "actionProductAdd", but nothing is added to the test.log file when adding products to the basket? Help please <?php if(!defined('_PS_VERSION_')) exit; class Test extends Module { public function __construct(){ $this->name = 'test'; $this->tab = 'Test'; $this->version = 1.0; $this->author = 'Test'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Test'); $this->description = $this->l('Test integration'); } public function install(){ if(parent::install() == false || !$this->registerHook('actionProductAdd') ){ return false; } return true; } public function hookActionProductAdd($params){ global $smarty; $this->write_log($params); //return true; } private function write_log($var){ $log_file = 'test.log'; if(is_file($log_file)){ chmod($log_file, 0777); } file_put_contents($log_file, serialize($var)."\n\n", FILE_APPEND); } public function uninstall(){ if(!parent::uninstall()){ Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'dynaccount`'); } parent::uninstall(); } } Edited December 4, 2012 by clarkk (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts