//
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user