diff --git a/modules/referralprogram/referralprogram.php b/modules/referralprogram/referralprogram.php
index 4786772ed..2600fc788 100644
--- a/modules/referralprogram/referralprogram.php
+++ b/modules/referralprogram/referralprogram.php
@@ -152,7 +152,9 @@ class ReferralProgram extends Module
Configuration::updateValue('REFERRAL_DISCOUNT_TYPE', (int)(Tools::getValue('discount_type')));
Configuration::updateValue('REFERRAL_NB_FRIENDS', (int)(Tools::getValue('nb_friends')));
Configuration::updateValue('REFERRAL_PERCENTAGE', (int)(Tools::getValue('discount_value_percentage')));
- Configuration::updateValue('REFERRAL_DISCOUNT_DESCRIPTION', Tools::getValue('discount_description'));
+ foreach (Language::getLanguages(false) as $lang)
+ Configuration::updateValue('REFERRAL_DISCOUNT_DESCRIPTION', array($lang['id_lang'] => Tools::getValue('discount_description_'.(int)$lang['id_lang'])));
+
$this->_html .= $this->displayConfirmation($this->l('Configuration updated.'));
}
@@ -185,9 +187,12 @@ class ReferralProgram extends Module
$newXml .= ''."\n";
$newXml .= "\t".'';
// Making body data
- foreach ($_POST AS $key => $field)
- if ($line = $this->putContent($newXml, $key, $field, $forbiddenKey, 'body'))
+ foreach (Language::getLanguages(false) as $lang)
+ {
+ if ($line = $this->putContent($newXml, 'body_paragraph_'.(int)$lang['id_lang'], Tools::getValue('body_paragraph_'.(int)$lang['id_lang']), $forbiddenKey, 'body'))
$newXml .= $line;
+ }
+
$newXml .= "\n\t".''."\n";
$newXml .= ''."\n";
@@ -226,166 +231,16 @@ class ReferralProgram extends Module
$this->_postProcess();
else
foreach ($this->_errors AS $err)
- $this->_html .= '
'.$err.'
';
+ $this->_html .= $err;
}
elseif (Tools::isSubmit('submitText'))
- {
- foreach ($_POST AS $key => $value)
- if (!is_array(Tools::getValue($key)) && !Validate::isString(Tools::getValue($key)))
- {
- $this->_html .= $this->displayError($this->l('Invalid html field, javascript is forbidden'));
- $this->_displayForm();
- return $this->_html;
- }
$this->_writeXml();
- }
- $this->_html .= ''.$this->displayName.'
';
- $this->_displayForm();
- $this->_displayFormRules();
+ $this->_html .= $this->renderForm();
+
return $this->_html;
}
- private function _displayForm()
- {
- $divLangName = 'cpara¤dd';
- $currencies = Currency::getCurrencies();
-
- $this->_html .= '
-
';
- }
-
- private function _displayFormRules()
- {
- // Languages preliminaries
- $languages = Language::getLanguages(false);
- $iso = $this->context->language->iso_code;
- $divLangName = 'cpara¤dd';
-
- // xml loading
- $xml = false;
- if (file_exists($this->_xmlFile))
- if (!$xml = @simplexml_load_file($this->_xmlFile))
- $this->_html .= $this->displayError($this->l('Your text is empty.'));
-
- // TinyMCE
- if (version_compare(_PS_VERSION_, '1.4.0.0') >= 0)
- $this->_html .= '
-
-
-
- ';
- else
- {
- $this->_html .= '
-
- ';
- }
- $this->_html .= '';
- }
-
-
/**
* Hook call when cart created and updated
* Display the discount name if the sponsor friend have one
@@ -657,7 +512,8 @@ class ReferralProgram extends Module
}
public function renderForm()
- {
+ {
+
$fields_form_1 = array(
'form' => array(
'legend' => array(
@@ -667,16 +523,51 @@ class ReferralProgram extends Module
'input' => array(
array(
'type' => 'text',
- 'name' => '',
- 'class' => 'fixed-width-md',
- 'label' => $this->l('Minimum number of orders a sponsored friend must place to get their voucher:'),
+ 'label' => $this->l('Minimum number of orders a sponsored friend must place to get their voucher'),
+ 'name' => 'order_quantity',
),
- ),
+ array(
+ 'type' => 'text',
+ 'label' => $this->l('Number of friends in the referral program invitation form (customer account, referral program section):'),
+ 'name' => 'nb_friends',
+ ),
+ array(
+ 'type' => 'radio',
+ 'label' => $this->l('Voucher type :'),
+ 'name' => 'discount_type',
+ 'values' => array(
+ array(
+ 'id' => 'discount_type1',
+ 'value' => 1,
+ 'label' => $this->l('Voucher offering a percentage')),
+ array(
+ 'id' => 'discount_type2',
+ 'value' => 2,
+ 'label' => $this->l('Voucher offering a fixed amount (by currency)')),
+ ),
+ ),
+ array(
+ 'type' => 'text',
+ 'label' => $this->l('Percentage'),
+ 'name' => 'discount_value_percentage',
+ 'suffix' => '%'
+ ),
+ array(
+ 'type' => 'discount_value',
+ 'label' => $this->l('Voucher amount'),
+ 'name' => 'discount_value',
+ ),
+ array(
+ 'type' => 'text',
+ 'label' => $this->l('Voucher description'),
+ 'name' => 'discount_description',
+ 'lang' => true,
+ )
+ ),
'submit' => array(
- 'title' => $this->l('Delete catalog'),
+ 'title' => $this->l('Save'),
'class' => 'btn btn-primary',
- 'name' => 'submitTruncateCatalog',
- 'id' => 'submitTruncateCatalog',
+ 'name' => 'submitReferralProgram',
)
),
);
@@ -684,29 +575,22 @@ class ReferralProgram extends Module
$fields_form_2 = array(
'form' => array(
'legend' => array(
- 'title' => $this->l('Orders and customers'),
+ 'title' => $this->l('Conditions of the referral program'),
'icon' => 'icon-cogs'
),
- 'description' => $this->l('I understand that all the orders and customers will be removed without possible rollback: customers, carts, orders, connections, guests, messages, stats...'),
- 'submit' => array(
- 'title' => $this->l('Delete orders & customers'),
- 'class' => 'btn btn-primary',
- 'name' => 'submitTruncateSales',
- 'id' => 'submitTruncateSales',
+ 'input' => array(
+ array(
+ 'type' => 'textarea',
+ 'autoload_rte' => true,
+ 'label' => $this->l('Text'),
+ 'name' => 'body_paragraph',
+ 'lang' => true,
)
- ),
- );
-
- $fields_form_3 = array(
- 'form' => array(
- 'legend' => array(
- 'title' => $this->l('Functional integrity constraints'),
- 'icon' => 'icon-cogs'
),
- 'submit' => array(
- 'title' => $this->l('Check & fix'),
- 'class' => 'btn btn-primary',
- 'name' => 'submitCheckAndFix',
+ 'submit' => array(
+ 'title' => $this->l('Save'),
+ 'class' => 'btn btn-primary',
+ 'name' => 'submitText',
)
),
);
@@ -717,23 +601,76 @@ class ReferralProgram extends Module
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
- $this->fields_form = array();
- $helper->id = (int)Tools::getValue('id_carrier');
$helper->identifier = $this->identifier;
- $helper->submit_action = 'btnSubmit';
+ $helper->submit_action = 'submitModule';
+ $helper->module = $this;
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
+ 'currencies' => Currency::getCurrencies(),
'fields_value' => $this->getConfigFieldsValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
-
- return $helper->generateForm(array($fields_form_1, $fields_form_2, $fields_form_3));
+
+ $helper->override_folder = '/';
+
+ return $this->renderJs().$helper->generateForm(array($fields_form_1, $fields_form_2));
}
public function getConfigFieldsValues()
+ {
+ $fields_values = array(
+ 'order_quantity' => Tools::getValue('order_quantity', Configuration::get('REFERRAL_ORDER_QUANTITY')),
+ 'discount_type' => Tools::getValue('discount_type', Configuration::get('REFERRAL_DISCOUNT_TYPE')),
+ 'nb_friends' => Tools::getValue('nb_friends', Configuration::get('REFERRAL_NB_FRIENDS')),
+ 'discount_value_percentage' => Tools::getValue('discount_value_percentage', Configuration::get('REFERRAL_PERCENTAGE')),
+ );
+
+ $languages = Language::getLanguages(false);
+ foreach ($languages as $lang)
+ $fields_values['discount_description'][$lang['id_lang']] = Tools::getValue('discount_description_'.(int)$lang['id_lang'], Configuration::get('REFERRAL_DISCOUNT_DESCRIPTION', (int)$lang['id_lang']));
+
+ $currencies = Currency::getCurrencies();
+ foreach ($currencies as $currency)
+ $fields_values['discount_value'][$currency['id_currency']] = Tools::getValue('discount_value['.(int)$currency['id_currency'].']', Configuration::get('REFERRAL_DISCOUNT_VALUE_'.(int)$currency['id_currency']));
+
+ // xml loading
+ $xml = false;
+ if (file_exists($this->_xmlFile))
+ if ($xml = @simplexml_load_file($this->_xmlFile))
+ foreach ($languages as $lang)
+ {
+ $key = 'paragraph_'.$lang['id_lang'];
+ $fields_values['body_paragraph'][$lang['id_lang']] = Tools::getValue('body_paragraph_'.(int)$lang['id_lang'] ,(string)$xml->body->$key);
+ }
+
+ return $fields_values;
+ }
+
+ public function renderJs()
{
- return array('value' => '');
+ return "
+
+ ";
}
}
diff --git a/modules/referralprogram/views/templates/admin/_configure/helpers/form/form.tpl b/modules/referralprogram/views/templates/admin/_configure/helpers/form/form.tpl
new file mode 100644
index 000000000..d78eb9777
--- /dev/null
+++ b/modules/referralprogram/views/templates/admin/_configure/helpers/form/form.tpl
@@ -0,0 +1,54 @@
+{*
+* 2007-2013 PrestaShop
+*
+* NOTICE OF LICENSE
+*
+* This source file is subject to the Academic Free License (AFL 3.0)
+* that is bundled with this package in the file LICENSE.txt.
+* It is also available through the world-wide-web at this URL:
+* http://opensource.org/licenses/afl-3.0.php
+* If you did not receive a copy of the license and are unable to
+* obtain it through the world-wide-web, please send an email
+* to license@prestashop.com so we can send you a copy immediately.
+*
+* DISCLAIMER
+*
+* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
+* versions in the future. If you wish to customize PrestaShop for your
+* needs please refer to http://www.prestashop.com for more information.
+*
+* @author PrestaShop SA
+* @copyright 2007-2013 PrestaShop SA
+* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
+* International Registered Trademark & Property of PrestaShop SA
+*}
+
+{extends file="helpers/form/form.tpl"}
+{block name="field"}
+ {if $input.type == 'discount_value'}
+
+ {/if}
+ {$smarty.block.parent}
+{/block}
\ No newline at end of file