added import
This commit is contained in:
@@ -58,7 +58,7 @@ class MinicMailchimp extends Module
|
||||
$this->hooks_tpl_path = _PS_MODULE_DIR_.$this->name.'/views/templates/hooks/';
|
||||
|
||||
$this->message = array(
|
||||
'text' => '',
|
||||
'text' => false,
|
||||
'type' => 'conf'
|
||||
);
|
||||
}
|
||||
@@ -110,21 +110,9 @@ 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
|
||||
$this->smarty->assign('minic', array(
|
||||
// smarty for admin
|
||||
$smarty_array = array(
|
||||
'first_start' => Configuration::get(strtoupper($this->name).'_START'),
|
||||
// Settings
|
||||
'settings' => unserialize(Configuration::get('MINIC_MAILCHIMP_SETTINGS')),
|
||||
|
||||
'admin_tpl_path' => $this->admin_tpl_path,
|
||||
'front_tpl_path' => $this->front_tpl_path,
|
||||
@@ -147,8 +135,30 @@ class MinicMailchimp extends Module
|
||||
'context' => (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') == 0) ? 1 : ($this->context->shop->getTotalShops() != 1) ? $this->context->shop->getContext() : 1,
|
||||
),
|
||||
'form_action' => 'index.php?tab=AdminModules&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&tab_module='. $this->tab .'&module_name='.$this->name,
|
||||
'message' => $this->message,
|
||||
));
|
||||
);
|
||||
|
||||
// Mailchimp lists
|
||||
$settings = unserialize(Configuration::get('MINIC_MAILCHIMP_SETTINGS'));
|
||||
if (!$settings){
|
||||
$this->message['text'] = $this->l('Before you start useing this module you need to configure it below!');
|
||||
}else{
|
||||
$this->api_key = $settings['apikey'];
|
||||
$this->ssl = $settings['ssl'];
|
||||
|
||||
$this->getMailchimpLists();
|
||||
}
|
||||
|
||||
// Handling settings
|
||||
if(Tools::isSubmit('submitSettings'))
|
||||
$this->saveSettings();
|
||||
// Handling Import
|
||||
if(Tools::isSubmit('submitImport'))
|
||||
$this->importCustomers();
|
||||
|
||||
// Smarty for admin
|
||||
$smarty_array['mailchimp'] = $settings;
|
||||
$smarty_array['message'] = $this->message;
|
||||
$this->smarty->assign('minic', $smarty_array);
|
||||
|
||||
// Change first start
|
||||
if(Configuration::get(strtoupper($this->name).'_START') == 1)
|
||||
@@ -159,11 +169,15 @@ class MinicMailchimp extends Module
|
||||
|
||||
public function importCustomers()
|
||||
{
|
||||
$all_customers = 0;
|
||||
if(!Tools::isSubmit('list') || !Tools::getValue('list')){
|
||||
// Get List id
|
||||
$list_id = Tools::getValue('list');
|
||||
if(!Tools::isSubmit('list') || !$list_id){
|
||||
$this->message = array('text' => $this->l('List is required! Please select one.'), 'type' => 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
// Get customer to import
|
||||
$all_customers = 0;
|
||||
if(!Tools::isSubmit('all-user')){
|
||||
$this->message = array('text' => $this->l('The type of Customers to import is required.'), 'type' => 'error');
|
||||
return;
|
||||
@@ -171,7 +185,40 @@ class MinicMailchimp extends Module
|
||||
$all_customers = 1;
|
||||
}
|
||||
|
||||
// Get all fields
|
||||
$fields = Tools::getValue('fields');
|
||||
|
||||
// Get Customers list
|
||||
$customers = Customer::getCustomers();
|
||||
|
||||
// Creating import array
|
||||
$list = array();
|
||||
foreach ($customers as $customer_key => $customer) {
|
||||
// Get customer data
|
||||
$customer_details = new Customer($customer['id_customer']);
|
||||
|
||||
// populate array
|
||||
$list[$customer_key]['EMAIL'] = $customer_details->email;
|
||||
foreach ($fields[$list_id] as $key => $field) {
|
||||
// mailchimp tag = customer field
|
||||
$list[$customer_key][$key] = $customer_details->$field;
|
||||
}
|
||||
}
|
||||
|
||||
$optin = false; //yes, send optin emails
|
||||
$up_exist = true; // yes, update currently subscribed users
|
||||
$replace_int = false; // no, add interest, don't replace
|
||||
|
||||
$mailchimp = new MCAPI($this->api_key, $this->ssl);
|
||||
$import = $mailchimp->listBatchSubscribe($list_id, $list, $optin, $up_exist, $replace_int);
|
||||
|
||||
if ($mailchimp->errorCode){
|
||||
echo "Batch Subscribe failed!\n";
|
||||
echo "code:".$mailchimp->errorCode."\n";
|
||||
echo "msg :".$mailchimp->errorMessage."\n";
|
||||
} else {
|
||||
P($import);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -179,15 +226,21 @@ class MinicMailchimp extends Module
|
||||
{
|
||||
$mailchimp = new MCAPI($this->api_key, $this->ssl);
|
||||
|
||||
$lists = $mailchimp->lists();
|
||||
$list_response = $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 {
|
||||
$lists = '';
|
||||
foreach ($list_response['data'] as $key => $value) {
|
||||
$lists[$key] = $value;
|
||||
$lists[$key]['fields'] = $mailchimp->listMergeVars($value['id']);
|
||||
}
|
||||
$this->context->smarty->assign('mailchimp_list', $lists);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,14 +258,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;
|
||||
}
|
||||
// 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');
|
||||
$settings['ssl'] = ((int)Tools::getValue('ssl') == 1) ? true : false;
|
||||
// $settings['registration'] = (int)Tools::getValue('registration');
|
||||
|
||||
Configuration::updateValue('MINIC_MAILCHIMP_SETTINGS', serialize($settings));
|
||||
|
||||
@@ -233,9 +286,11 @@ class MinicMailchimp extends Module
|
||||
// CSS
|
||||
$this->context->controller->addCSS($this->_path.'views/css/elusive-icons/elusive-webfont.css');
|
||||
$this->context->controller->addCSS($this->_path.'views/css/admin.css');
|
||||
$this->context->controller->addCSS($this->_path.'views/css/custom.css');
|
||||
// JS
|
||||
$this->context->controller->addJquery();
|
||||
$this->context->controller->addJS($this->_path.'views/js/admin.js');
|
||||
$this->context->controller->addJS($this->_path.'views/js/admin.js');
|
||||
$this->context->controller->addJS($this->_path.'views/js/custom.js');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
14
views/css/custom.css
Normal file
14
views/css/custom.css
Normal file
@@ -0,0 +1,14 @@
|
||||
#navigation{
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
-webkit-box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
-ms-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.fields-holder{
|
||||
display: none;
|
||||
}
|
||||
.fields-holder.visible-list{
|
||||
display: block;
|
||||
}
|
||||
9
views/js/custom.js
Normal file
9
views/js/custom.js
Normal file
@@ -0,0 +1,9 @@
|
||||
$(document).ready(function(){
|
||||
$('.list-selector').change(function(){
|
||||
var id = $(this).find('option:selected').attr('value');
|
||||
$('.visible-list').hide().removeClass('visible-list');
|
||||
$('#'+id).show().addClass('visible-list');
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
@@ -9,12 +9,36 @@
|
||||
<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}
|
||||
<select id="list-selector-import" name="list" class="list-selector">
|
||||
<option value="0"> - </option>
|
||||
{foreach from=$mailchimp_list item=list}
|
||||
<option value="{$list.id}">{$list.name}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
<div class="input-holder">
|
||||
<label>{l s='Atach fields'}:</label>
|
||||
{foreach from=$mailchimp_list key=k item=list}
|
||||
{if isset($list.fields)}
|
||||
<div id="{$list.id}" class="fields-holder">
|
||||
{foreach from=$list.fields item=field}
|
||||
{if $field.tag != 'EMAIL'}
|
||||
<div style="clear:both;">
|
||||
<span>{$field.name}</span>
|
||||
<select name="fields[{$list.id}][{$field.tag}]">
|
||||
<option value="0"> - </option>
|
||||
<option value="firstname">{l s='First Name' mod='minicmailchimp'}</option>
|
||||
<option value="lastname">{l s='Last Name' mod='minicmailchimp'}</option>
|
||||
</select>
|
||||
{if $field.req}<b>{l s='required' mod='minicmailchimp'}</b>{/if}
|
||||
{if $field.show == false}<b>{l s='hidden' mod='minicmailchimp'}</b>{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{/foreach}
|
||||
</div>
|
||||
{/if}
|
||||
{/foreach}
|
||||
</div>
|
||||
<div class="switch-holder inline">
|
||||
<label for="">{l s='Import all Customers'}:</label>
|
||||
<div class="switch small inactive">
|
||||
|
||||
32
views/templates/admin/mailchimp.tpl
Normal file
32
views/templates/admin/mailchimp.tpl
Normal file
@@ -0,0 +1,32 @@
|
||||
<div id="mailchimp" class="minic-container" {if !$minic.mailchimp.apikey}style="display:block;"{/if}>{debug}
|
||||
<form id="form-feed" class="" method="post" action="{$minic.form_action}">
|
||||
<div class="minic-top">
|
||||
<h3>{l s='Mailchimp configuration' mod='minicmailchimp'}
|
||||
<a href="#" target="_blank" class="help">{l s='help & tips' mod='minicmailchimp'}</a>
|
||||
</h3>
|
||||
<a href="#mailchimp" class="minic-close">x</a>
|
||||
</div>
|
||||
<div class="minic-content">
|
||||
<div class="input-holder">
|
||||
<label>{l s='Mailchimp API Key' mod='minicmailchimp'}:</label>
|
||||
<input id="mailchimp-key" class="apikey" type="text" name="apikey" value="{if $minic.mailchimp.apikey}{$minic.mailchimp.apikey}{/if}" />
|
||||
</div>
|
||||
<div class="switch-holder inline">
|
||||
<label>{l s='Use SSL'}: </label>
|
||||
<div class="switch small {if isset($minic.mailchimp.ssl) && $minic.mailchimp.ssl}active{else}inactive{/if}">
|
||||
<input type="radio" class="" name="ssl" value="{if isset($minic.mailchimp.ssl) && $minic.mailchimp.ssl}1{else}0{/if}" checked="true" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="minic-comments">
|
||||
<h3>{l s='How to get your API key' mod='minicmailchimp'}</h3>
|
||||
<p>{l s='If you alredy have an API key click'} <a href="https://us6.admin.mailchimp.com/account/api-key-popup/" target="_blank">{l s='here' mod='minicmailchimp'}</a>, {l s='otherwise you can get a new one from'} <a href="https://us6.admin.mailchimp.com/account/api/" target="_blank">{l s='here' mod='minicmailchimp'}</a></p>
|
||||
<h3>{l s='Tutorial to get an API key' mod='minicmailchimp'}</h3>
|
||||
<p>{l s='You can find more info'} <a href="http://kb.mailchimp.com/article/where-can-i-find-my-api-key" target="_blank">{l s='here' mod='minicmailchimp'}</a></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="minic-bottom">
|
||||
<input type="submit" name="submitMailchimp" class="button-large green" value="{l s='Save' mod='minicmailchimp'}" />
|
||||
<a href="#mailchimp" class="minic-close button-large lgrey">{l s='Close' mod='minicmailchimp'}</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
Reference in New Issue
Block a user