diff --git a/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/form.tpl b/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/form.tpl
index 6be15349d..de063bb64 100644
--- a/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/form.tpl
+++ b/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/form.tpl
@@ -27,32 +27,58 @@
{block name="field"}
{if $input.name == 'zones'}
-
+
diff --git a/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/view/view.tpl b/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/view/view.tpl
index 77dc0a6bb..3212627c1 100644
--- a/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/view/view.tpl
+++ b/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/view/view.tpl
@@ -32,6 +32,7 @@
var labelDelete = '{l s="Delete" js=1}';
var labelValidate = '{l s="Validate" js=1}';
var validate_url = '{$validate_url}'
+ var nbr_steps = {$wizard_steps.steps|count};
diff --git a/admin-dev/themes/default/template/controllers/carrier_wizard/summary.tpl b/admin-dev/themes/default/template/controllers/carrier_wizard/summary.tpl
new file mode 100644
index 000000000..ca877ac0f
--- /dev/null
+++ b/admin-dev/themes/default/template/controllers/carrier_wizard/summary.tpl
@@ -0,0 +1,30 @@
+{*
+* 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
+*}
+
+
\ No newline at end of file
diff --git a/classes/helper/HelperForm.php b/classes/helper/HelperForm.php
index 28437d244..39fe0154c 100644
--- a/classes/helper/HelperForm.php
+++ b/classes/helper/HelperForm.php
@@ -167,7 +167,7 @@ class HelperFormCore extends Helper
'module_dir' => _MODULE_DIR_,
'contains_states' => (isset($this->fields_value['id_country']) && isset($this->fields_value['id_state'])) ? Country::containsStates($this->fields_value['id_country']) : null,
));
- p($this->fields_value);
+
return parent::generate();
}
diff --git a/controllers/admin/AdminCarrierWizardController.php b/controllers/admin/AdminCarrierWizardController.php
index 583d48abd..b8e824c18 100644
--- a/controllers/admin/AdminCarrierWizardController.php
+++ b/controllers/admin/AdminCarrierWizardController.php
@@ -26,15 +26,23 @@
class AdminCarrierWizardControllerCore extends AdminController
{
+
+
public function __construct()
{
$this->display = 'view';
$this->table = 'carrier';
+ $this->identifier = 'id_carrier';
$this->className = 'Carrier';
$this->lang = false;
$this->deleted = true;
$this->step_number = 0;
-
+
+ $this->fieldImageSettings = array(
+ 'name' => 'logo',
+ 'dir' => 's'
+ );
+
parent::__construct();
}
@@ -97,13 +105,14 @@ class AdminCarrierWizardControllerCore extends AdminController
'contents' => array(
0 => $this->renderStepOne($carrier),
1 => $this->renderStepThree($carrier),
- 2 => $this->renderStepFour($carrier)
+ 2 => $this->renderStepFour($carrier),
+ 3 => $this->renderStepFive(),
)),
'labels' => array('next' => $this->l('Next'), 'previous' => $this->l('Previous'), 'finish' => $this->l('Finish'))
);
if (Shop::isFeatureActive())
- array_splice($this->$this->tpl_view_vars['wizard_contents']['contents'], 1, 0, array(0 => $this->renderStepTow($carrier)));
+ array_splice($this->tpl_view_vars['wizard_contents']['contents'], 1, 0, array(0 => $this->renderStepTow($carrier)));
return parent::renderView();
}
@@ -119,7 +128,13 @@ class AdminCarrierWizardControllerCore extends AdminController
$this->toolbar_title = $bread_extended;
}
-
+
+ public function initToolbar()
+ {
+ parent::initToolbar();
+ $this->toolbar_btn['back']['href'] = $this->context->link->getAdminLink('AdminCarriers');
+ }
+
public function renderStepOne($carrier)
{
$this->fields_form = array(
@@ -290,8 +305,7 @@ class AdminCarrierWizardControllerCore extends AdminController
),
array(
'type' => 'zone',
- 'name' => 'zones',
- 'value' => array()
+ 'name' => 'zones'
)
)
));
@@ -300,6 +314,33 @@ class AdminCarrierWizardControllerCore extends AdminController
$tpl_vars['zones'] = Zone::getZones(false);
$fields_value = $this->getStepThreeFieldsValues($carrier);
+ // Added values of object Zone
+ $carrier_zones = $carrier->getZones();
+ $carrier_zones_ids = array();
+ if (is_array($carrier_zones))
+ foreach ($carrier_zones as $carrier_zone)
+ $carrier_zones_ids[] = $carrier_zone['id_zone'];
+
+ $zones = Zone::getZones(false);
+ foreach ($zones as $zone)
+ $fields_value['zones'][$zone['id_zone']] = Tools::getValue('zone_'.$zone['id_zone'], (in_array($zone['id_zone'], $carrier_zones_ids)));
+
+ $shipping_method = $carrier->getShippingMethod();
+ $range_table = $carrier->getRangeTable();
+ $range_obj = $carrier->getRangeObject();
+
+ $price_by_range = Carrier::getDeliveryPriceByRanges($range_table, (int)$carrier->id);
+
+ foreach ($price_by_range as $price)
+ $tpl_vars['price_by_range'][$price['id_'.$range_table]][$price['id_zone']] = $price['price'];
+
+ $tmp_range = $range_obj->getRanges((int)$carrier->id);
+ $tpl_vars['ranges'] = array();
+ foreach ($tmp_range as $id => $range)
+ {
+ $tpl_vars['ranges'][$range['id_'.$range_table]] = $range;
+ $tpl_vars['ranges'][$range['id_'.$range_table]]['id_range'] = $range['id_'.$range_table];
+ }
return $this->renderGenericForm(array('form' => $this->fields_form), $fields_value, $tpl_vars);
}
@@ -374,16 +415,37 @@ class AdminCarrierWizardControllerCore extends AdminController
)
));
$fields_value = $this->getStepFourFieldsValues($carrier);
+
+
+ // Added values of object Group
+ $carrier_groups = $carrier->getGroups();
+ $carrier_groups_ids = array();
+ if (is_array($carrier_groups))
+ foreach ($carrier_groups as $carrier_group)
+ $carrier_groups_ids[] = $carrier_group['id_group'];
+
+ $groups = Group::getGroups($this->context->language->id);
+
+ foreach ($groups as $group)
+ $fields_value['groupBox_'.$group['id_group']] = Tools::getValue('groupBox_'.$group['id_group'], (in_array($group['id_group'], $carrier_groups_ids) || empty($carrier_groups_ids) && !$carrier->id));
+
return $this->renderGenericForm(array('form' => $this->fields_form), $fields_value);
}
+
+ public function renderStepFive()
+ {
+ return $this->context->smarty->fetch('controllers/carrier_wizard/summary.tpl');
+ }
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;
+ $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 = Tools::getValue('id_carrier');
+ $helper->identifier = $this->identifier;
$helper->tpl_vars = array_merge(array(
'fields_value' => $fields_value,
'languages' => $this->getLanguages(),
@@ -397,6 +459,7 @@ class AdminCarrierWizardControllerCore extends AdminController
public function getStepOneFieldsValues($carrier)
{
return array(
+ 'id_carrier' => $this->getFieldValue($carrier, 'id_carrier'),
'name' => $this->getFieldValue($carrier, 'name'),
'delay' => $this->getFieldValue($carrier, 'delay'),
'grade' => $this->getFieldValue($carrier, 'grade'),
@@ -419,8 +482,8 @@ class AdminCarrierWizardControllerCore extends AdminController
'shipping_handling' => $this->getFieldValue($carrier, 'shipping_handling'),
'shipping_method' => $this->getFieldValue($carrier, 'shipping_method'),
'range_behavior' => $this->getFieldValue($carrier, 'range_behavior'),
+ 'zones' => $this->getFieldValue($carrier, 'zones'),
);
-
}
public function getStepFourFieldsValues($carrier)
@@ -432,7 +495,7 @@ class AdminCarrierWizardControllerCore extends AdminController
'max_depth' => $this->getFieldValue($carrier, 'max_depth'),
'max_weight' => $this->getFieldValue($carrier, 'max_weight'),
'group' => $this->getFieldValue($carrier, 'group'),
- );
+ );
}
public function ajaxProcessValidateStep()
@@ -450,8 +513,8 @@ class AdminCarrierWizardControllerCore extends AdminController
}
else if ((!Shop::isFeatureActive() && $step_number == 2) || (Shop::isFeatureActive() && $step_number == 3))
{
- d($_POST);
-
+
+
}
else
$this->validateRules('AdminCarrierWizardControllerCore');
@@ -465,6 +528,147 @@ class AdminCarrierWizardControllerCore extends AdminController
die(Tools::jsonEncode($return));
}
+ public function processRange()
+ {
+ //getRangeObject
+
+ $range_inf = Tools::getValue('range_inf');
+ $range_sup = Tools::getValue('range_sup');
+ $range_type = Tools::getValue('shipping_method');
+
+ if ($range_type != Carrier::SHIPPING_METHOD_FREE)
+ {
+ foreach ($range_inf as $key => $range)
+ {
+ if ($range_type == Carrier::SHIPPING_METHOD_DEFAULT)
+ {
+ if (!Configuration::get('PS_SHIPPING_METHOD'))
+ $range_type = Carrier::SHIPPING_METHOD_PRICE;
+ else
+ $range_type = Carrier::SHIPPING_METHOD_WEIGHT;
+ }
+
+ if ($range_type == Carrier::SHIPPING_METHOD_WEIGHT)
+ $new_range = new RangeWeight();
+
+ if ($range_type == Carrier::SHIPPING_METHOD_PRICE)
+ $new_range = new RangePrice();
+
+
+ /* $this-> */
+
+
+ }
+ }
+ }
+
+ public function ajaxProcessFinishStep()
+ {
+ $return = array('has_error' => false);
+
+ //TODO : check permission
+
+ if ($id_carrier = Tools::getValue('id_carrier'))
+ {
+ $current_carrier = new Carrier((int)$id_carrier);
+ // if update we duplicate current Carrier
+ $carrier = $current_carrier->duplicateObject();
+ if (Validate::isLoadedObject($carrier))
+ {
+ // Set flag deteled to true for historization
+ $current_carrier->deleted = true;
+ $current_carrier->update();
+
+ // Fill the new carrier object
+ $this->copyFromPost($carrier, $this->table);
+ $carrier->position = $current_carrier->position;
+ $carrier->update();
+ }
+ }
+ else
+ {
+ $carrier = new Carrier();
+ $this->copyFromPost($carrier, $this->table);
+ if (!$carrier->add())
+ {
+ $return['has_error'] = true;
+ $return['errors'][] = $this->l('An error occurred while saving this carrier.');
+ }
+ }
+
+ if(Validate::isLoadedObject($carrier))
+ {
+ if (!$this->changeGroups((int)$carrier->id))
+ {
+ $return['has_error'] = true;
+ $return['errors'][] = $this->l('An error occurred while saving carrier groups.');
+ }
+
+ if (!$this->changeZones((int)$carrier->id))
+ {
+ $return['has_error'] = true;
+ $return['errors'][] = $this->l('An error occurred while saving carrier zones.');
+ }
+
+ if (Shop::isFeatureActive() && !$this->updateAssoShop((int)$carrier->id))
+ {
+ $return['has_error'] = true;
+ $return['errors'][] = $this->l('An error occurred while saving associations of shops.');
+ }
+
+ if (!$carrier->setTaxRulesGroup((int)Tools::getValue('id_tax_rules_group')))
+ {
+ $return['has_error'] = true;
+ $return['errors'][] = $this->l('An error occurred while saving the tax rules group.');
+ }
+
+ if (!$this->postImage((int)$carrier->id))
+ {
+ $return['has_error'] = true;
+ $return['errors'][] = $this->l('An error occurred while saving carrier logo.');
+ }
+ $return['id_carrier'] = $carrier->id;
+ }
+ die(Tools::jsonEncode($return));
+ }
+
+ protected function updateCarrierAsso($id_carrier)
+ {
+
+ }
+
+ protected function changeGroups($id_carrier, $delete = true)
+ {
+ if ($delete)
+ Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'carrier_group WHERE id_carrier = '.(int)$id_carrier);
+ $groups = Db::getInstance()->executeS('SELECT id_group FROM `'._DB_PREFIX_.'group`');
+ foreach ($groups as $group)
+ if (Tools::getIsset('groupBox') && in_array($group['id_group'], Tools::getValue('groupBox')))
+ return Db::getInstance()->execute('
+ INSERT INTO '._DB_PREFIX_.'carrier_group (id_group, id_carrier)
+ VALUES('.(int)$group['id_group'].','.(int)$id_carrier.')
+ ');
+ }
+
+ public function changeZones($id)
+ {
+ $return = true;
+ $carrier = new Carrier($id);
+ if (!Validate::isLoadedObject($carrier))
+ die (Tools::displayError('The object cannot be loaded.'));
+ $zones = Zone::getZones(false);
+ foreach ($zones as $zone)
+ if (count($carrier->getZone($zone['id_zone'])))
+ {
+ if (!isset($_POST['zone_'.$zone['id_zone']]) || !$_POST['zone_'.$zone['id_zone']])
+ $return &= $carrier->deleteZone($zone['id_zone']);
+ }
+ else
+ if (isset($_POST['zone_'.$zone['id_zone']]) && $_POST['zone_'.$zone['id_zone']])
+ $return &= $carrier->addZone($zone['id_zone']);
+ return $return;
+ }
+
public static function getValidationRules()
{
$step_number = Tools::getValue('step_number');
@@ -481,35 +685,26 @@ class AdminCarrierWizardControllerCore extends AdminController
}
$rules = array();
- switch ($step_number)
- {
- case 1:
- $rules = Carrier::getValidationRules('Carrier');
- break;
- case 2:
- $rules = Carrier::getValidationRules('Carrier');
- break;
- case 3:
- $rules = Carrier::getValidationRules('Carrier');
- break;
- }
+
+ if ($step_number == 1)
+ $rules = Carrier::getValidationRules('Carrier');
foreach ($rules as $key_r => $rule)
foreach ($rule as $key_f => $field)
{
- if (in_array($key_r, array('required', 'requiredLang')) && !array_key_exists($key_f, $step_fields[$step_number]))
- unset($rules[$key_r][$key_f]);
- else
+ if (in_array($key_r, array('required', 'requiredLang')))
+ {
+ if(!in_array($field, $step_fields[$step_number]))
+ unset($rules[$key_r][$key_f]);
+ }
+ else if(!in_array($key_f, $step_fields[$step_number]))
unset($rules[$key_r][$key_f]);
}
-
return $rules;
-
}
public static function displayFieldName($field)
{
return $field;
}
-
}
\ No newline at end of file
diff --git a/controllers/admin/AdminCarriersController.php b/controllers/admin/AdminCarriersController.php
index 84a51b04d..7d749588d 100644
--- a/controllers/admin/AdminCarriersController.php
+++ b/controllers/admin/AdminCarriersController.php
@@ -155,7 +155,15 @@ class AdminCarriersControllerCore extends AdminController
parent::__construct();
}
-
+
+ public function initToolbar()
+ {
+ parent::initToolbar();
+
+ if (isset($this->toolbar_btn['new']))
+ $this->toolbar_btn['new']['href'] = $this->context->link->getAdminLink('AdminCarrierWizard');
+ }
+
public function renderList()
{
$this->displayInformation(
@@ -695,6 +703,11 @@ class AdminCarriersControllerCore extends AdminController
}
}
}
+
+ public function displayEditLink($token = null, $id, $name = null)
+ {
+ return '
';
+ }
}
diff --git a/css/admin.css b/css/admin.css
index beabbb163..84b711417 100644
--- a/css/admin.css
+++ b/css/admin.css
@@ -2510,4 +2510,6 @@ margin-bottom:7px;
#carrier_wizard input.field_error {border : solid 1px red; background-color:#FFCCCC}
#carrier_wizard table td.center {text-align: center}
.new_range {float: left;margin: 20px 0 0 10px;}
-#carrier_wizard tr.fees_all { background: #CCCCCC}
\ No newline at end of file
+#carrier_wizard tr.fees_all { background: #CCCCCC}
+
+#carrier_wizard #zones_table input[type=text] {width: 45px;}
\ No newline at end of file
diff --git a/js/admin_carrier_wizard.js b/js/admin_carrier_wizard.js
index 7ea4db96e..60ed8e86b 100644
--- a/js/admin_carrier_wizard.js
+++ b/js/admin_carrier_wizard.js
@@ -24,11 +24,9 @@
*/
-$(document).ready(function() {
-
+$(document).ready(function() {
bind_inputs();
initCarrierWizard();
-
});
function initCarrierWizard()
@@ -39,7 +37,9 @@ function initCarrierWizard()
'labelFinish' : labelFinish,
'fixHeight' : 1,
'onShowStep' : onShowStepCallback,
- 'onLeaveStep' : leaveStepCallback,
+ 'onLeaveStep' : onLeaveStepCallback,
+ 'onFinish' : onFinishCallback,
+ 'transitionEffect' : 'slideleft'
});
}
@@ -51,11 +51,41 @@ function onShowStepCallback()
resizeWizard();
}
-function leaveStepCallback(obj, context)
+function onFinishCallback(obj, context)
{
+ $('.wizard_error').remove();
+ $.ajax({
+ type:"POST",
+ url : validate_url,
+ async: false,
+ dataType: 'json',
+ data : $('#carrier_wizard .stepContainer .content form').serialize()+'&action=finish_step&ajax=1',
+ success : function(datas)
+ {
+ if (datas.has_error)
+ {
+ displayError(datas.errors, context.fromStep);
+ resizeWizard();
+ }
+ else
+ alert('YEAAAAAAH !!!');
+ }
+ });
+}
+
+function onLeaveStepCallback(obj, context)
+{
+ if (context.toStep == nbr_steps)
+ displaySummary();
+
return validateSteps(context.fromStep); // return false to stay on step and true to continue navigation
}
+function displaySummary()
+{
+
+}
+
function validateSteps(step_number)
{
$('.wizard_error').remove();
@@ -76,15 +106,7 @@ function validateSteps(step_number)
$('input').focus( function () {
$(this).removeClass('field_error');
});
-
- str_error = '
';
- for (var error in datas.errors)
- {
- $('#carrier_wizard').smartWizard('setError',{stepnum:step_number,iserror:true});
- $('input[name="'+error+'"]').addClass('field_error');
- str_error += '- '+datas.errors[error]+'
';
- }
- $('#step-'+step_number).prepend(str_error+'
');
+ displayError(datas.errors, step_number);
resizeWizard();
}
}
@@ -92,6 +114,19 @@ function validateSteps(step_number)
return is_ok;
}
+function displayError(errors, step_number)
+{
+ $('.wizard_error').remove();
+ str_error = '
';
+ for (var error in errors)
+ {
+ $('#carrier_wizard').smartWizard('setError',{stepnum:step_number,iserror:true});
+ $('input[name="'+error+'"]').addClass('field_error');
+ str_error += '- '+errors[error]+'
';
+ }
+ $('#step-'+step_number).prepend(str_error+'
');
+}
+
function resizeWizard()
{
resizeInterval = setInterval(function (){$("#carrier_wizard").smartWizard('fixHeight'); clearInterval(resizeInterval)}, 100);
@@ -252,6 +287,7 @@ function add_new_range()
resizeWizard();
bind_inputs();
+
return false;
}
@@ -261,8 +297,10 @@ function delete_new_range()
return false;
}
-function setInputRangeId()
+function is_freeChange()
{
-
-
+ if ($('input[name=is_free]:checked').val())
+ $('').hide();
+ else
+ $('').show();
}
\ No newline at end of file