//carrier wizard field validation
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
{*
|
||||
* 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 <contact@prestashop.com>
|
||||
* @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.name == 'zones'}
|
||||
<table cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td colspan="3" id="range_limit" class="border_bottom border_right" style="height:80px;padding: 5px; min-width: 152px;">
|
||||
<table style="display:none" id="range_table">
|
||||
<tr>
|
||||
<td rowspan="2" style="padding:5px;vertical-align:middle" valign="middle">
|
||||
{l s="Range limits by : "} <span >{l s="weight"}</span> <span style="display:none" id="">{l s="price"}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="new_range_form_placeholder">
|
||||
<td> </td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
<td class="border_bottom" style="padding:5px;">
|
||||
<a href="#" id="add_new_range">
|
||||
{l s="Add new range"}
|
||||
<img src="../img/admin/add.gif"/>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table id="fees_table">
|
||||
<tr style="display:none" id="fees_all_container">
|
||||
<td>{l s="All"}</td>
|
||||
<td><input type="checkbox" name="all_zone"/></td>
|
||||
</tr>
|
||||
{foreach from=$zones item=zone}
|
||||
<tr class="zones">
|
||||
<td class="border_right" style="padding-right:10px">
|
||||
<input type="checkbox" disabled="disabled" name="zone_{$zone.id_zone}"/>
|
||||
{$zone.name}
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
<tr class="zones_delete">
|
||||
<td> </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
<div style="display:none">
|
||||
<table id="new_range_form" cellpadding="0" cellspacing="0" class="border_bottom">
|
||||
<tr>
|
||||
<td class="border_bottom border_left" style="padding: 5px;">>=</td>
|
||||
<td><input type="text"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="border_left" style="padding: 5px;"><</td>
|
||||
<td><input type="text"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{/if}
|
||||
{$smarty.block.parent}
|
||||
{/block}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 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/osl-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 <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../../../../../../../../');
|
||||
exit;
|
||||
@@ -26,26 +26,11 @@
|
||||
{extends file="helpers/view/view.tpl"}
|
||||
{block name="override_tpl"}
|
||||
<script>
|
||||
cleanClasses = function cleanClasses()
|
||||
{
|
||||
$('.anchor li a').each( function () {
|
||||
$(this).parent('li').addClass($(this).attr('class'));
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
$("#carrier_wizard").smartWizard({
|
||||
'labelNext' : '{$labels.next}',
|
||||
'labelPrevious' : '{$labels.previous}',
|
||||
'labelFinish' : '{$labels.finish}',
|
||||
'fixHeight' : true,
|
||||
'onShowStep' : cleanClasses
|
||||
});
|
||||
$("#carrier_wizard").smartWizard('fixHeight');
|
||||
});
|
||||
|
||||
|
||||
|
||||
var labelNext = '{$labels.next}';
|
||||
var labelPrevious = '{$labels.previous}';
|
||||
var labelFinish = '{$labels.finish}';
|
||||
var labelDelete = '{l s="Delete" js=1}';
|
||||
var validate_url = '{$validate_url}'
|
||||
</script>
|
||||
<div id="carrier_wizard" class="swMain">
|
||||
<ul class="nbr_steps_{$wizard_steps.steps|count}">
|
||||
|
||||
@@ -2377,7 +2377,7 @@ class AdminControllerCore extends Controller
|
||||
foreach ($rules['required'] as $field)
|
||||
if (($value = Tools::getValue($field)) == false && (string)$value != '0')
|
||||
if (!Tools::getValue($this->identifier) || ($field != 'passwd' && $field != 'no-picture'))
|
||||
$this->errors[] = sprintf(
|
||||
$this->errors[$field] = sprintf(
|
||||
Tools::displayError('The %s field is required.'),
|
||||
call_user_func(array($class_name, 'displayFieldName'), $field, $class_name)
|
||||
);
|
||||
@@ -2386,7 +2386,7 @@ class AdminControllerCore extends Controller
|
||||
if (isset($rules['requiredLang']) && is_array($rules['requiredLang']))
|
||||
foreach ($rules['requiredLang'] as $field_lang)
|
||||
if (($empty = Tools::getValue($field_lang.'_'.$default_language->id)) === false || $empty !== '0' && empty($empty))
|
||||
$this->errors[] = sprintf(
|
||||
$this->errors[$field_lang.'_'.$default_language->id] = sprintf(
|
||||
Tools::displayError('The field %1$s is required at least in %2$s.'),
|
||||
call_user_func(array($class_name, 'displayFieldName'), $field_lang, $class_name),
|
||||
$default_language->name
|
||||
@@ -2396,7 +2396,7 @@ class AdminControllerCore extends Controller
|
||||
if (isset($rules['size']) && is_array($rules['size']))
|
||||
foreach ($rules['size'] as $field => $max_length)
|
||||
if (Tools::getValue($field) !== false && Tools::strlen(Tools::getValue($field)) > $max_length)
|
||||
$this->errors[] = sprintf(
|
||||
$this->errors[$field] = sprintf(
|
||||
Tools::displayError('The %1$s field is too long (%2$d chars max).'),
|
||||
call_user_func(array($class_name, 'displayFieldName'), $field, $class_name),
|
||||
$max_length
|
||||
@@ -2409,7 +2409,7 @@ class AdminControllerCore extends Controller
|
||||
{
|
||||
$field_lang_value = Tools::getValue($field_lang.'_'.$language['id_lang']);
|
||||
if ($field_lang_value !== false && Tools::strlen($field_lang_value) > $max_length)
|
||||
$this->errors[] = sprintf(
|
||||
$this->errors[$field_lang.'_'.$language['id_lang']] = sprintf(
|
||||
Tools::displayError('The field %1$s (%2$s) is too long (%3$d chars max, html chars including).'),
|
||||
call_user_func(array($class_name, 'displayFieldName'), $field_lang, $class_name),
|
||||
$language['name'],
|
||||
@@ -2424,7 +2424,7 @@ class AdminControllerCore extends Controller
|
||||
foreach ($rules['validate'] as $field => $function)
|
||||
if (($value = Tools::getValue($field)) !== false && ($field != 'passwd'))
|
||||
if (!Validate::$function($value) && !empty($value))
|
||||
$this->errors[] = sprintf(
|
||||
$this->errors[$field] = sprintf(
|
||||
Tools::displayError('The %s field is invalid.'),
|
||||
call_user_func(array($class_name, 'displayFieldName'), $field, $class_name)
|
||||
);
|
||||
@@ -2433,12 +2433,12 @@ class AdminControllerCore extends Controller
|
||||
if (($value = Tools::getValue('passwd')) != false)
|
||||
{
|
||||
if ($class_name == 'Employee' && !Validate::isPasswdAdmin($value))
|
||||
$this->errors[] = sprintf(
|
||||
$this->errors['passwd'] = sprintf(
|
||||
Tools::displayError('The %s field is invalid.'),
|
||||
call_user_func(array($class_name, 'displayFieldName'), 'passwd', $class_name)
|
||||
);
|
||||
elseif ($class_name == 'Customer' && !Validate::isPasswd($value))
|
||||
$this->errors[] = sprintf(
|
||||
$this->errors[$field] = sprintf(
|
||||
Tools::displayError('The %s field is invalid.'),
|
||||
call_user_func(array($class_name, 'displayFieldName'), 'passwd', $class_name)
|
||||
);
|
||||
@@ -2450,7 +2450,7 @@ class AdminControllerCore extends Controller
|
||||
foreach ($languages as $language)
|
||||
if (($value = Tools::getValue($field_lang.'_'.$language['id_lang'])) !== false && !empty($value))
|
||||
if (!Validate::$function($value))
|
||||
$this->errors[] = sprintf(
|
||||
$this->errors[$field_lang.'_'.$language['id_lang']] = sprintf(
|
||||
Tools::displayError('The %1$s field (%2$s) is invalid.'),
|
||||
call_user_func(array($class_name, 'displayFieldName'), $field_lang, $class_name),
|
||||
$language['name']
|
||||
|
||||
@@ -27,17 +27,26 @@
|
||||
class AdminCarrierWizardControllerCore extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
{
|
||||
$this->display = 'view';
|
||||
$this->table = 'carrier';
|
||||
$this->className = 'Carrier';
|
||||
$this->lang = false;
|
||||
$this->deleted = true;
|
||||
$this->step_number = 0;
|
||||
|
||||
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
public function setMedia()
|
||||
{
|
||||
parent::setMedia();
|
||||
$this->addJqueryPlugin('smartWizard');
|
||||
$this->addJs(_PS_JS_DIR_.'admin_carrier_wizard.js');
|
||||
}
|
||||
|
||||
|
||||
public function initWizard()
|
||||
{
|
||||
$this->wizard_steps = array(
|
||||
@@ -46,26 +55,22 @@ class AdminCarrierWizardControllerCore extends AdminController
|
||||
array(
|
||||
'title' => $this->l('General'),
|
||||
'desc' => $this->l('General'),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'title' => $this->l('Where and how much ?'),
|
||||
'desc' => $this->l('Where and how much ?'),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'title' => $this->l('What and to who ?'),
|
||||
'desc' => $this->l('What and to who ?'),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'title' => $this->l('Resume'),
|
||||
'desc' => $this->l('Resume'),
|
||||
),
|
||||
|
||||
));
|
||||
|
||||
/* $this->wizard_steps */
|
||||
|
||||
|
||||
|
||||
),
|
||||
|
||||
));
|
||||
|
||||
if (Shop::isFeatureActive())
|
||||
{
|
||||
$multistore_step = array(
|
||||
@@ -77,115 +82,402 @@ class AdminCarrierWizardControllerCore extends AdminController
|
||||
array_splice($this->wizard_steps['steps'], 1, 0, $multistore_step);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function renderView()
|
||||
{
|
||||
$this->initWizard();
|
||||
|
||||
|
||||
|
||||
if (Tools::getValue('id_carrier'))
|
||||
$carrier = $this->loadObject();
|
||||
else
|
||||
$carrier = new Carrier();
|
||||
|
||||
$this->tpl_view_vars = array(
|
||||
'wizard_steps' => $this->wizard_steps,
|
||||
'validate_url' => $this->context->link->getAdminLink('AdminCarrierWizard'),
|
||||
'wizard_contents' => array(
|
||||
'contents' => array(
|
||||
0 => $this->renderStepOne(),
|
||||
0 => $this->renderStepOne($carrier),
|
||||
1 => $this->renderStepTow($carrier),
|
||||
2 => $this->renderStepThree($carrier),
|
||||
3 => $this->renderStepFour($carrier)
|
||||
)),
|
||||
'labels' => array('next' => $this->l('Next'), 'previous' => $this->l('Previous'), 'finish' => $this->l('Finish'))
|
||||
);
|
||||
|
||||
);
|
||||
|
||||
return parent::renderView();
|
||||
}
|
||||
|
||||
public function renderStepOne()
|
||||
|
||||
public function initToolbarTitle()
|
||||
{
|
||||
$bread_extended = array_unique($this->breadcrumbs);
|
||||
|
||||
if (Tools::getValue('id_carrier'))
|
||||
$bread_extended[1] = $this->l('Edit');
|
||||
else
|
||||
$bread_extended[1] = $this->l('Add new');
|
||||
|
||||
$this->toolbar_title = $bread_extended;
|
||||
}
|
||||
|
||||
public function renderStepOne($carrier)
|
||||
{
|
||||
$this->fields_form = array(
|
||||
'form' => array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Carriers:'),
|
||||
'image' => '../img/admin/delivery.gif'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Company:'),
|
||||
'name' => 'name',
|
||||
'size' => 25,
|
||||
'required' => true,
|
||||
'hint' => sprintf($this->l('Allowed characters: letters, spaces and %s'), '().-'),
|
||||
'desc' => array(
|
||||
$this->l('Carrier name displayed during checkout'),
|
||||
$this->l('For in-store pickup, enter 0 to replace the carrier name with your shop name.')
|
||||
)
|
||||
'legend' => array(
|
||||
'title' => $this->l('Carriers:'),
|
||||
'image' => '../img/admin/delivery.gif'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Transit time:'),
|
||||
'name' => 'delay',
|
||||
'lang' => true,
|
||||
'required' => true,
|
||||
'size' => 41,
|
||||
'maxlength' => 128,
|
||||
'desc' => $this->l('Estimated delivery time will be displayed during checkout.')
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Speed Grade:'),
|
||||
'name' => 'grade',
|
||||
'required' => false,
|
||||
'size' => 1,
|
||||
'desc' => $this->l('Enter "0" for a longest shipping delay, or "9" for the shortest shipping delay.')
|
||||
),
|
||||
array(
|
||||
'type' => 'file',
|
||||
'label' => $this->l('Logo:'),
|
||||
'name' => 'logo',
|
||||
'desc' => $this->l('Upload a logo from your computer.').' (.gif, .jpg, .jpeg '.$this->l('or').' .png)'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('URL:'),
|
||||
'name' => 'url',
|
||||
'size' => 40,
|
||||
'desc' => $this->l('Delivery tracking URL: Type \'@\' where the tracking number should appear. It will then be automatically replaced by the tracking number.')
|
||||
),
|
||||
)),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Company:'),
|
||||
'name' => 'name',
|
||||
'size' => 25,
|
||||
'required' => true,
|
||||
'hint' => sprintf($this->l('Allowed characters: letters, spaces and %s'), '().-'),
|
||||
'desc' => array(
|
||||
$this->l('Carrier name displayed during checkout'),
|
||||
$this->l('For in-store pickup, enter 0 to replace the carrier name with your shop name.')
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Transit time:'),
|
||||
'name' => 'delay',
|
||||
'lang' => true,
|
||||
'required' => true,
|
||||
'size' => 41,
|
||||
'maxlength' => 128,
|
||||
'desc' => $this->l('Estimated delivery time will be displayed during checkout.')
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Speed Grade:'),
|
||||
'name' => 'grade',
|
||||
'required' => false,
|
||||
'size' => 1,
|
||||
'desc' => $this->l('Enter "0" for a longest shipping delay, or "9" for the shortest shipping delay.')
|
||||
),
|
||||
array(
|
||||
'type' => 'file',
|
||||
'label' => $this->l('Logo:'),
|
||||
'name' => 'logo',
|
||||
'desc' => $this->l('Upload a logo from your computer.').' (.gif, .jpg, .jpeg '.$this->l('or').' .png)'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('URL:'),
|
||||
'name' => 'url',
|
||||
'size' => 40,
|
||||
'desc' => $this->l('Delivery tracking URL: Type \'@\' where the tracking number should appear. It will then be automatically replaced by the tracking number.')
|
||||
),
|
||||
)),
|
||||
);
|
||||
|
||||
$carrier = new Carrier(1);
|
||||
$fields_value = $this->getStep1FieldsValues($carrier);
|
||||
return $this->renderGenericForm($this->fields_form, $fields_value);
|
||||
|
||||
$fields_value = $this->getStepOneFieldsValues($carrier);
|
||||
return $this->renderGenericForm(array('form' => $this->fields_form), $fields_value);
|
||||
}
|
||||
|
||||
public function renderStepTow($fields_form)
|
||||
|
||||
public function renderStepTow($carrier)
|
||||
{
|
||||
|
||||
|
||||
|
||||
$this->fields_form = array(
|
||||
'form' => array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Carriers:'),
|
||||
'image' => '../img/admin/delivery.gif'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'shop',
|
||||
'label' => $this->l('Shop association:'),
|
||||
'name' => 'checkBoxShopAsso',
|
||||
),
|
||||
))
|
||||
);
|
||||
$fields_value = $this->getStepTowFieldsValues($carrier);
|
||||
return $this->renderGenericForm(array('form' => $this->fields_form), $fields_value);
|
||||
}
|
||||
|
||||
public function renderGenericForm($fields_form, $fields_value)
|
||||
|
||||
public function renderStepThree($carrier)
|
||||
{
|
||||
$this->fields_form = array(
|
||||
'form' => array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Carriers:'),
|
||||
'image' => '../img/admin/delivery.gif'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'radio',
|
||||
'label' => $this->l('Apply shipping cost:'),
|
||||
'name' => 'is_free',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'is_free_on',
|
||||
'value' => 0,
|
||||
'label' => '<img src="../img/admin/enabled.gif" alt="'.$this->l('Yes').'" title="'.$this->l('Yes').'" />'
|
||||
),
|
||||
array(
|
||||
'id' => 'is_free_off',
|
||||
'value' => 1,
|
||||
'label' => '<img src="../img/admin/disabled.gif" alt="'.$this->l('No').'" title="'.$this->l('No').'" />'
|
||||
)
|
||||
),
|
||||
'desc' => $this->l('Apply both regular shipping cost and product-specific shipping costs.')
|
||||
),
|
||||
array(
|
||||
'type' => 'radio',
|
||||
'label' => $this->l('Shipping and handling:'),
|
||||
'name' => 'shipping_handling',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'shipping_handling_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'shipping_handling_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
),
|
||||
'desc' => $this->l('Include the shipping and handling costs in the carrier price.')
|
||||
),
|
||||
array(
|
||||
'type' => 'radio',
|
||||
'label' => $this->l('Billing:'),
|
||||
'name' => 'shipping_method',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'br' => true,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'billing_default',
|
||||
'value' => Carrier::SHIPPING_METHOD_DEFAULT,
|
||||
'label' => $this->l('Default behavior')
|
||||
),
|
||||
array(
|
||||
'id' => 'billing_price',
|
||||
'value' => Carrier::SHIPPING_METHOD_PRICE,
|
||||
'label' => $this->l('According to total price')
|
||||
),
|
||||
array(
|
||||
'id' => 'billing_weight',
|
||||
'value' => Carrier::SHIPPING_METHOD_WEIGHT,
|
||||
'label' => $this->l('According to total weight')
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Tax:'),
|
||||
'name' => 'id_tax_rules_group',
|
||||
'options' => array(
|
||||
'query' => TaxRulesGroup::getTaxRulesGroups(true),
|
||||
'id' => 'id_tax_rules_group',
|
||||
'name' => 'name',
|
||||
'default' => array(
|
||||
'label' => $this->l('No Tax'),
|
||||
'value' => 0
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'zone',
|
||||
'name' => 'zones',
|
||||
'value' => array()
|
||||
)
|
||||
)
|
||||
));
|
||||
|
||||
$tpl_vars = array();
|
||||
$tpl_vars['zones'] = Zone::getZones(false);
|
||||
|
||||
$fields_value = $this->getStepThreeFieldsValues($carrier);
|
||||
return $this->renderGenericForm(array('form' => $this->fields_form), $fields_value, $tpl_vars);
|
||||
}
|
||||
|
||||
public function renderStepFour($carrier)
|
||||
{
|
||||
$this->fields_form = array(
|
||||
'form' => array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Carriers:'),
|
||||
'image' => '../img/admin/delivery.gif'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Out-of-range behavior:'),
|
||||
'name' => 'range_behavior',
|
||||
'options' => array(
|
||||
'query' => array(
|
||||
array(
|
||||
'id' => 0,
|
||||
'name' => $this->l('Apply the cost of the highest defined range')
|
||||
),
|
||||
array(
|
||||
'id' => 1,
|
||||
'name' => $this->l('Disable carrier')
|
||||
)
|
||||
),
|
||||
'id' => 'id',
|
||||
'name' => 'name'
|
||||
),
|
||||
'desc' => $this->l('Out-of-range behavior occurs when none is defined (e.g. when a customer\'s cart weight is greater than the highest range limit)')
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Maximium package height:'),
|
||||
'name' => 'max_height',
|
||||
'required' => false,
|
||||
'size' => 10,
|
||||
'desc' => $this->l('Maximum height managed by this carrier. Set the value to "0," or leave this field blank to ignore.')
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Maximium package width:'),
|
||||
'name' => 'max_width',
|
||||
'required' => false,
|
||||
'size' => 10,
|
||||
'desc' => $this->l('Maximum width managed by this carrier. Set the value to "0," or leave this field blank to ignore.')
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Maximium package depth:'),
|
||||
'name' => 'max_depth',
|
||||
'required' => false,
|
||||
'size' => 10,
|
||||
'desc' => $this->l('Maximum depth managed by this carrier. Set the value to "0," or leave this field blank to ignore.')
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Maximium package weight:'),
|
||||
'name' => 'max_weight',
|
||||
'required' => false,
|
||||
'size' => 10,
|
||||
'desc' => $this->l('Maximum weight managed by this carrier. Set the value to "0," or leave this field blank to ignore.')
|
||||
),
|
||||
)
|
||||
));
|
||||
$fields_value = $this->getStepFourFieldsValues($carrier);
|
||||
return $this->renderGenericForm(array('form' => $this->fields_form), $fields_value);
|
||||
}
|
||||
|
||||
public function renderGenericForm($fields_form, $fields_value, $tpl_vars = array())
|
||||
{
|
||||
$helper = new HelperForm();
|
||||
$helper->show_toolbar = false;
|
||||
$helper->default_form_language = $this->context->language->id;
|
||||
$helper->allow_employee_form_lang = 1;
|
||||
$this->fields_form = array();
|
||||
$helper->tpl_vars = array(
|
||||
$helper->tpl_vars = array_merge(array(
|
||||
'fields_value' => $fields_value,
|
||||
'languages' => $this->getLanguages(),
|
||||
'id_language' => 1
|
||||
);
|
||||
return $helper->generateForm(array('form' => $fields_form));
|
||||
}
|
||||
|
||||
public function getStep1FieldsValues($carrier)
|
||||
'id_language' => $this->context->language->id
|
||||
), $tpl_vars);
|
||||
$helper->override_folder = 'carrier_wizard/';
|
||||
|
||||
return $helper->generateForm($fields_form);
|
||||
}
|
||||
|
||||
public function getStepOneFieldsValues($carrier)
|
||||
{
|
||||
return array(
|
||||
'name' => $this->getFieldsValue($carrier, 'name'),
|
||||
'delay' => $this->getFieldsValue($carrier, 'delay'),
|
||||
'grade' => $this->getFieldsValue($carrier, 'grade'),
|
||||
'name' => $this->getFieldValue($carrier, 'name'),
|
||||
'delay' => $this->getFieldValue($carrier, 'delay'),
|
||||
'grade' => $this->getFieldValue($carrier, 'grade'),
|
||||
'logo' => '',
|
||||
'url' => $this->getFieldsValue($carrier, 'url'),
|
||||
'url' => $this->getFieldValue($carrier, 'url'),
|
||||
);
|
||||
}
|
||||
|
||||
public function getStepTowFieldsValues($carrier)
|
||||
{
|
||||
return array('shop' => $this->getFieldValue($carrier, 'shop'));
|
||||
|
||||
}
|
||||
|
||||
public function getStepThreeFieldsValues($carrier)
|
||||
{
|
||||
return array(
|
||||
'is_free' => $this->getFieldValue($carrier, 'is_free'),
|
||||
'id_tax_rules_group' => $this->getFieldValue($carrier, 'id_tax_rules_group'),
|
||||
'shipping_handling' => $this->getFieldValue($carrier, 'shipping_handling'),
|
||||
'shipping_method' => $this->getFieldValue($carrier, 'shipping_method'),
|
||||
'range_behavior' => $this->getFieldValue($carrier, 'range_behavior'),
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function getStepFourFieldsValues($carrier)
|
||||
{
|
||||
return array(
|
||||
'range_behavior' => $this->getFieldValue($carrier, 'shop'),
|
||||
'max_height' => $this->getFieldValue($carrier, 'max_height'),
|
||||
'max_width' => $this->getFieldValue($carrier, 'max_width'),
|
||||
'max_depth' => $this->getFieldValue($carrier, 'max_depth'),
|
||||
'max_weight' => $this->getFieldValue($carrier, 'max_weight'),
|
||||
);
|
||||
}
|
||||
|
||||
public function ajaxProcessValidateStep()
|
||||
{
|
||||
$step_number = (int)Tools::getValue('step_number');
|
||||
|
||||
$this->validateRules('AdminCarrierWizardControllerCore');
|
||||
|
||||
$return = array('has_error' => false);
|
||||
|
||||
if (count($this->errors))
|
||||
{
|
||||
$return['has_error'] = true;
|
||||
$return['errors'] = $this->errors;
|
||||
}
|
||||
die(Tools::jsonEncode($return));
|
||||
}
|
||||
|
||||
public static function getValidationRules()
|
||||
{
|
||||
$step_number = Tools::getValue('step_number');
|
||||
$step_fields = array(
|
||||
1 => array('name', 'delay', 'grade', 'url'),
|
||||
2 => array('is_free', 'id_tax_rules_group', 'shipping_handling', 'shipping_method', 'range_behavior'),
|
||||
3 => array('range_behavior', 'max_height', 'max_width', 'max_depth', 'max_weight'),
|
||||
);
|
||||
|
||||
switch ($step_number)
|
||||
{
|
||||
case 1:
|
||||
$rules = Carrier::getValidationRules('Carrier');
|
||||
break;
|
||||
case 2:
|
||||
$rules = Carrier::getValidationRules('Carrier');
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($rules as $key_r => $rule)
|
||||
foreach ($rule as $key_f => $field)
|
||||
if (!in_array($field, $step_fields[$step_number]))
|
||||
unset($rules[$key_r][$key_f]);
|
||||
return $rules;
|
||||
/*
|
||||
'carrier' => Carrier::getValidationRules('Carrier'),
|
||||
'range_price' => RangePrice::getValidationRules('RangePrice'),
|
||||
'range_weight' => RangeWeight::getValidationRules('RangeWeight'),
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
public static function displayFieldName($field)
|
||||
{
|
||||
return $field;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2493,3 +2493,8 @@ margin-bottom:7px;
|
||||
|
||||
#carrier_wizard.swMain .stepContainer div.content{width:99%}
|
||||
#carrier_wizard.swMain div.actionBar{width:99.5%}
|
||||
|
||||
.border_top {border-top:solid 1px #C0C0C0;}
|
||||
.border_bottom {border-bottom:solid 1px #C0C0C0;}
|
||||
.border_left {border-left:solid 1px #C0C0C0;}
|
||||
.border_right {border-right:solid 1px #C0C0C0;}
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* 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 <contact@prestashop.com>
|
||||
* @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
|
||||
*/
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
bind_inputs();
|
||||
initCarrierWizard();
|
||||
|
||||
});
|
||||
|
||||
function initCarrierWizard()
|
||||
{
|
||||
$("#carrier_wizard").smartWizard({
|
||||
'labelNext' : labelNext,
|
||||
'labelPrevious' : labelPrevious,
|
||||
'labelFinish' : labelFinish,
|
||||
'fixHeight' : 1,
|
||||
'onShowStep' : onShowStepCallback,
|
||||
'onLeaveStep' : leaveStepCallback,
|
||||
});
|
||||
}
|
||||
|
||||
function onShowStepCallback()
|
||||
{
|
||||
$('.anchor li a').each( function () {
|
||||
$(this).parent('li').addClass($(this).attr('class'));
|
||||
});
|
||||
resizeWizard();
|
||||
}
|
||||
|
||||
function leaveStepCallback(obj, context)
|
||||
{
|
||||
return validateSteps(context.fromStep); // return false to stay on step and true to continue navigation
|
||||
}
|
||||
|
||||
function validateSteps(step_number){
|
||||
var step_valid = true;
|
||||
|
||||
form = $('#carrier_wizard #step-'+step_number+' form');
|
||||
|
||||
/*
|
||||
switch(step_number)
|
||||
{
|
||||
case 1:
|
||||
|
||||
break;
|
||||
case 2:
|
||||
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
$.ajax({
|
||||
type:"POST",
|
||||
url : validate_url,
|
||||
async: true,
|
||||
dataType: 'json',
|
||||
data : form.serialize()+'&step_number='+step_number+'&action=validate_step&ajax=1',
|
||||
success : function(datas)
|
||||
{
|
||||
if (datas.has_error)
|
||||
{
|
||||
for (var error in datas.errors)
|
||||
{
|
||||
$('#carrier_wizard').smartWizard('setError',{stepnum:step_number,iserror:true});
|
||||
$('input[name="'+error+'"]').css({'border' : 'solid 1px red', 'background-color' : '#FFCCCC'});
|
||||
$("#carrier_wizard")
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
function resizeWizard()
|
||||
{
|
||||
resizeInterval = setInterval(function (){$("#carrier_wizard").smartWizard('fixHeight'); clearInterval(resizeInterval)}, 100);
|
||||
}
|
||||
|
||||
function bind_inputs()
|
||||
{
|
||||
$('a#add_new_range').bind('click', function () {
|
||||
add_new_range();
|
||||
});
|
||||
|
||||
$('tr.zones_delete td button').each( function () {
|
||||
$(this).bind('click', function () {
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function add_new_range()
|
||||
{
|
||||
$('.zones td input:checkbox').removeAttr('disabled');
|
||||
$('td#range_limit').children('table').show();
|
||||
$('tr#new_range_form_placeholder').children('td:last').after('<td><table cellpadding="0" cellspacing="0">'+$('#new_range_form').html()+'</table></td>');
|
||||
$('tr.zones').each( function () {
|
||||
$(this).children('td:eq(1)').removeClass('border_right');
|
||||
$(this).children('td:last').after('<td class="border_right" style="width:173px;text-align:center"><input type="text" disabled="disabled"/></td>');
|
||||
});
|
||||
$('tr.zones_delete:last').children('td:last').after('<td class="border_right" style="width:173px;text-align:center"><button class="button">'+labelDelete+'</button></td>');
|
||||
resizeWizard();
|
||||
bind_inputs();
|
||||
return false;
|
||||
}
|
||||
|
||||
function delete_new_range()
|
||||
{
|
||||
if ($('#new_range_form_placeholder').children('td').length = 1)
|
||||
return false;
|
||||
}
|
||||
|
||||
function setInputRangeId()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user