This commit is contained in:
minic studio
2013-04-08 15:05:25 +03:00
parent ffb3a1ae01
commit c16ea7e57d
4 changed files with 94 additions and 3 deletions

View File

@@ -20,11 +20,15 @@
if (!defined('_PS_VERSION_')) if (!defined('_PS_VERSION_'))
exit; exit;
require_once 'MCAPI.class.php';
class MinicMailchimp extends Module class MinicMailchimp extends Module
{ {
// DB file // DB file
const INSTALL_SQL_FILE = 'install.sql'; const INSTALL_SQL_FILE = 'install.sql';
private $api_key;
private $ssl;
private $module_path; private $module_path;
private $admin_tpl_path; private $admin_tpl_path;
private $front_tpl_path; private $front_tpl_path;
@@ -96,7 +100,7 @@ class MinicMailchimp extends Module
*/ */
public function uninstall() public function uninstall()
{ {
if (!parent::uninstall()) if (!parent::uninstall() || !Configuration::deleteByName('MINIC_MAILCHIMP_SETTINGS'))
return false; return false;
return true; return true;
} }
@@ -106,9 +110,14 @@ class MinicMailchimp extends Module
*/ */
public function getContent() public function getContent()
{ {
if(!$this->getMailchimpLists())
$error = true;
if(Tools::isSubmit('submitSettings')) if(Tools::isSubmit('submitSettings'))
$this->saveSettings(); $this->saveSettings();
if(Tools::isSubmit('submitImport'))
$this->importCustomers();
// Smarty for admin // Smarty for admin
@@ -148,6 +157,39 @@ class MinicMailchimp extends Module
return $this->display(__FILE__, 'views/templates/admin/minicmailchimp.tpl'); 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 * Save settings into PS Configuration
*/ */
@@ -163,9 +205,14 @@ class MinicMailchimp extends Module
$this->message = array('text' => $this->l('SSL save failed!'), 'type' => 'error'); $this->message = array('text' => $this->l('SSL save failed!'), 'type' => 'error');
return; 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['apikey'] = Tools::getValue('apikey');
$settings['ssl'] = (int)Tools::getValue('ssl'); $settings['ssl'] = (int)Tools::getValue('ssl');
$settings['registration'] = (int)Tools::getValue('registration');
Configuration::updateValue('MINIC_MAILCHIMP_SETTINGS', serialize($settings)); Configuration::updateValue('MINIC_MAILCHIMP_SETTINGS', serialize($settings));

View 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>

View File

@@ -20,12 +20,19 @@
<div id="banner"></div> <div id="banner"></div>
<div id="navigation"> <div id="navigation">
<a href="#settings" class="minic-open">{l s='Settings' mod='minicmailchimp'}</a> <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>
</div> </div>
<!-- Messages --> <!-- Messages -->
{include file="{$minic.admin_tpl_path}messages.tpl" id="global" text=$minic.message.text class=$minic.message.type} {include file="{$minic.admin_tpl_path}messages.tpl" id="global" text=$minic.message.text class=$minic.message.type}
<!-- Settings --> <!-- Settings -->
{include file="{$minic.admin_tpl_path}settings.tpl"} {include file="{$minic.admin_tpl_path}settings.tpl"}
{if $minic.settings.apikey}
<!-- Import -->
{include file="{$minic.admin_tpl_path}import.tpl"}
{/if}
<!-- feedback --> <!-- feedback -->
{include file="{$minic.admin_tpl_path}feedback.tpl"} {include file="{$minic.admin_tpl_path}feedback.tpl"}
<!-- bug report --> <!-- bug report -->

View File

@@ -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}"> <form id="form-feed" class="" method="post" action="{$minic.form_action}">
<div class="minic-top"> <div class="minic-top">
<h3>{l s='Settings' mod='minicmailchimp'} <h3>{l s='Settings' mod='minicmailchimp'}
@@ -14,7 +14,13 @@
<div class="switch-holder inline"> <div class="switch-holder inline">
<label>{l s='Use SSL'}: </label> <label>{l s='Use SSL'}: </label>
<div class="switch small {if isset($minic.settings.ssl) && $minic.settings.ssl}active{else}inactive{/if}"> <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> </div>
<div class="minic-comments"> <div class="minic-comments">