示例#1
0
 public function __construct()
 {
     //$this->getAdminFullUrl();
     // Default module variable
     $this->name = 'mailjet';
     $this->displayName = 'Mailjet';
     $this->description = $this->l('Create contact lists and client segment groups, drag-n-drop newsletters, define client re-engagement triggers, follow and analyze all email user interaction, minimize negative user engagement events (blocked, unsubs and spam) and optimise deliverability and revenue generation. Get started today with 6000 free emails per month.');
     $this->author = 'PrestaShop';
     $this->version = '3.2.5';
     $this->module_key = '59cce32ad9a4b86c46e41ac95f298076';
     $this->tab = 'advertising_marketing';
     // Parent constructor
     parent::__construct();
     // Backward compatibility
     if (version_compare(_PS_VERSION_, '1.5', '<')) {
         require _PS_MODULE_DIR_ . $this->name . '/backward_compatibility/backward.php';
     }
     if ($this->active) {
         $this->module_access['uri'] = __PS_BASE_URI__ . 'modules/' . $this->name . '/';
         $this->module_access['dir'] = _PS_MODULE_DIR_ . $this->name . '/';
         $this->initAccountSettings();
         MailJetLog::init();
         $this->initTriggers();
     }
     $this->initContext();
 }
    require_once realpath(dirname(__FILE__) . '/../../init.php');
}
if (Tools::getIsset('data')) {
    $data = (object) Tools::getValue('data');
} else {
    if (Tools::getIsset('mailjet')) {
        $mailjet = Tools::jsonDecode(Tools::getValue('mailjet'));
        $data = $mailjet->data;
    } else {
        $data = new stdClass();
    }
}
require_once _PS_MODULE_DIR_ . 'mailjet/mailjet.php';
require_once _PS_MODULE_DIR_ . 'mailjet/classes/MailJetLog.php';
$mj = new Mailjet();
MailJetLog::init();
if (Tools::getIsset('response')) {
    $response = (object) Tools::getValue('response');
}
if ($data->next_step_url) {
    if (!empty($response) && ($response->message == 'last change of campaigns parameters' || $response->message == 'send details saved successfully')) {
        $mj_data = new Mailjet_Api($mj->getAccountSettingsKey('API_KEY'), $mj->getAccountSettingsKey('SECRET_KEY'));
        $campaignId = (int) $data->campaign_id;
        $html = $mj_data->data('newsletter', $campaignId, 'HTML', 'text/html', null, 'GET', 'LAST')->getResponse();
        /* On enregistre la campagne en BDD et on génère un token */
        $sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'mj_campaign WHERE campaign_id = ' . $campaignId;
        $res_campaign = Db::getInstance()->GetRow($sql);
        if (empty($res_campaign)) {
            $token_presta = md5(uniqid('mj', true));
            $sql = 'INSERT INTO ' . _DB_PREFIX_ . 'mj_campaign (campaign_id, token_presta, date_add)
			VALUES (' . $campaignId . ', \'' . $token_presta . '\', NOW())';