Skip to content

Instantly share code, notes, and snippets.

@Onasusweb
Forked from ikwattro/sfadvancedmailer.php
Last active August 29, 2015 14:13
Show Gist options
  • Save Onasusweb/f37d7ded1f6f59df87be to your computer and use it in GitHub Desktop.
Save Onasusweb/f37d7ded1f6f59df87be to your computer and use it in GitHub Desktop.

Revisions

  1. @ikwattro ikwattro created this gist Sep 24, 2012.
    81 changes: 81 additions & 0 deletions sfadvancedmailer.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,81 @@
    <?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();
    }

    }