added form settings

This commit is contained in:
minic studio committed 2013-04-10 17:05:28 +03:00
1 parent 28bda72ccf
commit fc508f8443
2 files changed
+92 -23

No files matched your search

+74 -17
View File
@@ -135,6 +135,7 @@ class MinicMailchimp extends Module
'context' => (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') == 0) ? 1 : ($this->context->shop->getTotalShops() != 1) ? $this->context->shop->getContext() : 1, '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, 'form_action' => 'index.php?tab=AdminModules&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&tab_module='. $this->tab .'&module_name='.$this->name,
'hooks' => array('Top', 'LeftColumn', 'RightColumn', 'Footer', 'Home', 'LeftColumnProduct', 'RightColumProduct', 'FooterProduct')
); );
// Mailchimp lists // Mailchimp lists
@@ -154,6 +155,10 @@ class MinicMailchimp extends Module
// Handling Import // Handling Import
if(Tools::isSubmit('submitImport')) if(Tools::isSubmit('submitImport'))
$this->importCustomers(); $this->importCustomers();
// Handling Form
if(Tools::isSubmit('submitForm'))
$this->saveSubscriberForm();
// Smarty for admin // Smarty for admin
$smarty_array['mailchimp'] = $settings; $smarty_array['mailchimp'] = $settings;
@@ -167,6 +172,38 @@ class MinicMailchimp extends Module
return $this->display(__FILE__, 'views/templates/admin/minicmailchimp.tpl'); return $this->display(__FILE__, 'views/templates/admin/minicmailchimp.tpl');
} }
/**
* Save the subscriber form details
*/
public function saveSubscriberForm()
{
$form_settings = unserialize(Configuration::get('MINIC_MAILCHIMP_FORM'));
$hooks = array(
'old' => $form_setting['hooks'],
'new' => (Tools::isSubmit('hooks')) ? Tools::getValue('hooks') : false,
);
$form = ( Tools::isSubmit('form')) ? Tools::getValue('form') : false;
if(!$hooks['new']){
$this->message = array('text' => $this->l('At least a hook is required to show the form.'), 'type' => 'error');
return;
}
if(!$form){
$this->message = array('text' => $this->l('The form code is required!'), 'type' => 'error');
return;
}
foreach ($hooks['old'] as $hook) {
$this->unregisterHook($hook);
}
foreach ($hooks['new'] as $hook) {
$this->registerHook($hook);
}
Configuration::updateValue('MINIC_MAILCHIMP_FORM', serialize(array('form' => $form, 'hooks' => $hooks)));
}
/** /**
* Import customers into the selected Mailchimp list * Import customers into the selected Mailchimp list
*/ */
@@ -195,16 +232,20 @@ class MinicMailchimp extends Module
// populate customer array // populate customer array
if($all_customers){ if($all_customers){
$list[$customer_key]['EMAIL'] = $customer_details->email; $list[$customer_key]['EMAIL'] = $customer_details->email;
foreach ($fields[$list_id] as $key => $field) { if(isset($fields[$list_id])){
// mailchimp tag = customer field foreach ($fields[$list_id] as $key => $field) {
$list[$customer_key][$key] = $customer_details->$field; // mailchimp tag = customer field
} $list[$customer_key][$key] = $customer_details->$field;
}
}
}else if(!$all_customers && $customer_details->newsletter){ }else if(!$all_customers && $customer_details->newsletter){
$list[$customer_key]['EMAIL'] = $customer_details->email; $list[$customer_key]['EMAIL'] = $customer_details->email;
foreach ($fields[$list_id] as $key => $field) { if(isset($fields[$list_id])){
// mailchimp tag = customer field foreach ($fields[$list_id] as $key => $field) {
$list[$customer_key][$key] = $customer_details->$field; // mailchimp tag = customer field
} $list[$customer_key][$key] = $customer_details->$field;
}
}
} }
} }
@@ -343,15 +384,7 @@ class MinicMailchimp extends Module
*/ */
public function hookDisplayHome($params) public function hookDisplayHome($params)
{ {
$this->context->smarty->assign('MinicMailchimp', array( $this->samrty->assign('mailchimp_form', unserialize(Configuration::get('MINIC_MAILCHIMP_SETTINGS')));
'some_smarty_var' => 'some_data',
'some_smarty_array' => array(
'some_smarty_var' => 'some_data',
'some_smarty_var' => 'some_data'
),
'some_smarty_var' => 'some_data'
));
return $this->display(__FILE__, 'views/tempaltes/hooks/home.tpl'); return $this->display(__FILE__, 'views/tempaltes/hooks/home.tpl');
} }
@@ -378,6 +411,30 @@ class MinicMailchimp extends Module
{ {
return $this->hookDisplayHome($params); return $this->hookDisplayHome($params);
} }
/**
*
*/
public function hookDisplayLeftColumnProduct($params)
{
return $this->hookDisplayHome($params);
}
/**
*
*/
public function hookDisplayRightColumProduct($params)
{
return $this->hookDisplayHome($params);
}
/**
*
*/
public function hookDisplayFooterProduct($params)
{
return $this->hookDisplayHome($params);
}
} }
?> ?>
+18 -6
View File
@@ -7,17 +7,29 @@
<a href="#form" class="minic-close">x</a> <a href="#form" class="minic-close">x</a>
</div> </div>
<div class="minic-content"> <div class="minic-content">
<div class="input-holder"> <div class="input-holder">
<label>{l s='Choose the list to import' mod='minicmailchimp'}:</label> <label>{l s='Choose where to show the form' mod='minicmailchimp'}:</label>
<select name="list"> <select multiple name="hooks[]" id="">
{foreach from=$mailchimp_list.data item=list} {foreach from=$minic.hooks item=hook}
<option value="{$list.id}">{$list.name}</option> <option value="display{$hook}">{$hook}</option>
{/foreach} {/foreach}
</select> </select>
<p>{l s='Hold down the CTRL to select multiple.' mod='minicmailchimp'}</p>
</div>
<div class="input-holder">
<label>{l s='Insert the form code here' mod='minicmailchimp'}:</label>
<textarea name="form"></textarea>
</div>
<div class="minic-comments">
<h3>{l s='How to get the form code' mod='minicmailchimp'}</h3>
<ol style="list-style: decimal;">
<li>{l s='Log in into' mod='minicmailchimp'} <a href="https://login.mailchimp.com/" target="_blank">Mailchimp</a></li>
<li>step 2.</li>
</ol>
</div> </div>
</div> </div>
<div class="minic-bottom"> <div class="minic-bottom">
<input type="submit" name="submitImport" class="button-large green" value="{l s='Save' mod='minicmailchimp'}" /> <input type="submit" name="submitForm" class="button-large green" value="{l s='Save' mod='minicmailchimp'}" />
<a href="#form" class="minic-close button-large lgrey">{l s='Close' mod='minicmailchimp'}</a> <a href="#form" class="minic-close button-large lgrey">{l s='Close' mod='minicmailchimp'}</a>
</div> </div>
</form> </form>