Jump to content

Build small custom module


Recommended Posts

Hi there.. :D

 

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 by clarkk (see edit history)
Link to comment
Share on other sites

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

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 :D

 

<?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 by clarkk (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...