Skip to content

Instantly share code, notes, and snippets.

@ikwattro
Created September 24, 2012 12:48
Show Gist options
  • Save ikwattro/3775788 to your computer and use it in GitHub Desktop.
Save ikwattro/3775788 to your computer and use it in GitHub Desktop.
Module php file
<?php
require_once _PS_MODULE_DIR_ . 'sfadvancedmailer/models/Client.php';
/**
*
* @author Christophe Willemsen
*/
class SfAdvancedMailer extends Module {
public function __construct() {
$this->name = 'sfadvancedmailer';
$this->tab = 'emailing';
$this->version = 1.0;
$this->author = 'Christophe Willemsen';
$this->displayName = $this->l('Advanced Mailer');
$this->description = $this->l('Advanced mailing module for PrestaShop 1.5');
parent :: __construct();
}
public function install() {
return parent :: install()
&& $this->resetDb()
&& $this->registerHook('authentication')
&& $this->registerHook('actionCustomerAccountAdd')
;
}
private function resetDb() {
$prefix = _DB_PREFIX_;
$engine = _MYSQL_ENGINE_;
$statements = array();
$statements[] = "DROP TABLE IF EXISTS `${prefix}client`";
$statements[] = "CREATE TABLE `${prefix}client` ("
. '`id_client` int(10) unsigned NOT NULL AUTO_INCREMENT,'
. '`id_customer` int(10) unsigned NOT NULL,'
. '`id_lang` int(10) unsigned NOT NULL,'
. 'PRIMARY KEY (`id_client`)'
. ") ENGINE=$engine"
;
foreach ($statements as $statement) {
if (!Db :: getInstance()->Execute($statement)) {
return false;
}
}
return true;
}
public function hookAuthentication($params)
{
$lang = $this->context->language->id;
$customer = $this->context->customer->id;
if(
Db::getInstance()->insert('client', array(
'id_lang' => (int)$lang,
'id_customer' => (int)$customer,
))
){
return true;
}
return false;
}
public function hookActionCustomerAccountAdd($params)
{
$this->hookAuthentication($params);
var_dump($this->context->customer);
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment