update
This commit is contained in:
@@ -20,11 +20,15 @@
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
require_once 'MCAPI.class.php';
|
||||
|
||||
class MinicMailchimp extends Module
|
||||
{
|
||||
// DB file
|
||||
const INSTALL_SQL_FILE = 'install.sql';
|
||||
|
||||
private $api_key;
|
||||
private $ssl;
|
||||
private $module_path;
|
||||
private $admin_tpl_path;
|
||||
private $front_tpl_path;
|
||||
@@ -96,7 +100,7 @@ class MinicMailchimp extends Module
|
||||
*/
|
||||
public function uninstall()
|
||||
{
|
||||
if (!parent::uninstall())
|
||||
if (!parent::uninstall() || !Configuration::deleteByName('MINIC_MAILCHIMP_SETTINGS'))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@@ -106,9 +110,14 @@ class MinicMailchimp extends Module
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
if(!$this->getMailchimpLists())
|
||||
$error = true;
|
||||
|
||||
if(Tools::isSubmit('submitSettings'))
|
||||
$this->saveSettings();
|
||||
|
||||
if(Tools::isSubmit('submitImport'))
|
||||
$this->importCustomers();
|
||||
|
||||
|
||||
// Smarty for admin
|
||||
@@ -148,6 +157,39 @@ class MinicMailchimp extends Module
|
||||
return $this->display(__FILE__, 'views/templates/admin/minicmailchimp.tpl');
|
||||
}
|
||||
|
||||
public function importCustomers()
|
||||
{
|
||||
$all_customers = 0;
|
||||
if(!Tools::isSubmit('list') || !Tools::getValue('list')){
|
||||
$this->message = array('text' => $this->l('List is required! Please select one.'), 'type' => 'error');
|
||||
return;
|
||||
}
|
||||
if(!Tools::isSubmit('all-user')){
|
||||
$this->message = array('text' => $this->l('The type of Customers to import is required.'), 'type' => 'error');
|
||||
return;
|
||||
}else{
|
||||
$all_customers = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function getMailchimpLists()
|
||||
{
|
||||
$mailchimp = new MCAPI($this->api_key, $this->ssl);
|
||||
|
||||
$lists = $mailchimp->lists();
|
||||
|
||||
if ($mailchimp->errorCode){
|
||||
$this->message = array('text' => $this->l('Mailchimp error code:').' '.$mailchimp->errorCode.'<br />'.$this->l('Milchimp message:').' '.$mailchimp->errorMessage, 'type' => 'error');
|
||||
return;
|
||||
} else {
|
||||
$this->context->smarty->assign('mailchimp_list', $lists);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings into PS Configuration
|
||||
*/
|
||||
@@ -163,9 +205,14 @@ class MinicMailchimp extends Module
|
||||
$this->message = array('text' => $this->l('SSL save failed!'), 'type' => 'error');
|
||||
return;
|
||||
}
|
||||
if(!Tools::getValue('registration') && Tools::getValue('registration') != 0){
|
||||
$this->message = array('text' => $this->l('Sync new registration save failed!'), 'type' => 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
$settings['apikey'] = Tools::getValue('apikey');
|
||||
$settings['ssl'] = (int)Tools::getValue('ssl');
|
||||
$settings['registration'] = (int)Tools::getValue('registration');
|
||||
|
||||
Configuration::updateValue('MINIC_MAILCHIMP_SETTINGS', serialize($settings));
|
||||
|
||||
|
||||
31
views/templates/admin/import.tpl
Normal file
31
views/templates/admin/import.tpl
Normal file
@@ -0,0 +1,31 @@
|
||||
<div id="import" class="minic-container">
|
||||
<form id="form-feed" class="" method="post" action="{$minic.form_action}">
|
||||
<div class="minic-top">
|
||||
<h3>{l s='Import users' mod='minicmailchimp'}
|
||||
<a href="#" target="_blank" class="help">{l s='help & tips' mod='minicmailchimp'}</a>
|
||||
</h3>
|
||||
<a href="#import" class="minic-close">x</a>
|
||||
</div>
|
||||
<div class="minic-content">
|
||||
<div class="input-holder">
|
||||
<label>{l s='Choose the list to import' mod='minicmailchimp'}:</label>
|
||||
<select name="list">
|
||||
{foreach from=$mailchimp_list.data item=list}
|
||||
<option value="{$list.id}">{$list.name}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
<div class="switch-holder inline">
|
||||
<label for="">{l s='Import all Customers'}:</label>
|
||||
<div class="switch small inactive">
|
||||
<input type="radio" class="" name="all-user" value="0" checked="true" />
|
||||
</div>
|
||||
<p style="clear:both;">{l s='Turn on if you wish to import all of the users, not just the subscribers.' mod='minicmailchimp'}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="minic-bottom">
|
||||
<input type="submit" name="submitImport" class="button-large green" value="{l s='Import' mod='minicmailchimp'}" />
|
||||
<a href="#import" class="minic-close button-large lgrey">{l s='Close' mod='minicmailchimp'}</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -20,12 +20,19 @@
|
||||
<div id="banner"></div>
|
||||
<div id="navigation">
|
||||
<a href="#settings" class="minic-open">{l s='Settings' mod='minicmailchimp'}</a>
|
||||
{if $minic.settings.apikey}
|
||||
<a href="#import" class="minic-open">{l s='Import' mod='minicmailchimp'}</a>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<!-- Messages -->
|
||||
{include file="{$minic.admin_tpl_path}messages.tpl" id="global" text=$minic.message.text class=$minic.message.type}
|
||||
<!-- Settings -->
|
||||
{include file="{$minic.admin_tpl_path}settings.tpl"}
|
||||
{if $minic.settings.apikey}
|
||||
<!-- Import -->
|
||||
{include file="{$minic.admin_tpl_path}import.tpl"}
|
||||
{/if}
|
||||
<!-- feedback -->
|
||||
{include file="{$minic.admin_tpl_path}feedback.tpl"}
|
||||
<!-- bug report -->
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<div id="settings" class="minic-container">{debug}
|
||||
<div id="settings" class="minic-container" {if !$minic.settings.apikey}style="display:block;"{/if}>{debug}
|
||||
<form id="form-feed" class="" method="post" action="{$minic.form_action}">
|
||||
<div class="minic-top">
|
||||
<h3>{l s='Settings' mod='minicmailchimp'}
|
||||
@@ -14,7 +14,13 @@
|
||||
<div class="switch-holder inline">
|
||||
<label>{l s='Use SSL'}: </label>
|
||||
<div class="switch small {if isset($minic.settings.ssl) && $minic.settings.ssl}active{else}inactive{/if}">
|
||||
<input type="radio" id="r-hover" class="" name="ssl" value="{if isset($minic.settings.ssl) && $minic.settings.ssl}1{else}0{/if}" checked="true" />
|
||||
<input type="radio" class="" name="ssl" value="{if isset($minic.settings.ssl) && $minic.settings.ssl}1{else}0{/if}" checked="true" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="switch-holder inline">
|
||||
<label>{l s='Sync new registration'}: </label>
|
||||
<div class="switch small {if isset($minic.settings.registration) && $minic.settings.registration}active{else}inactive{/if}">
|
||||
<input type="radio" class="" name="registration" value="{if isset($minic.settings.registration) && $minic.settings.registration}1{else}0{/if}" checked="true" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="minic-comments">
|
||||
|
||||
Reference in New Issue
Block a user