* @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
*/
class AdminCarrierWizardControllerCore extends AdminController
{
protected $wizard_access;
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();
$this->tabAccess = Profile::getProfileAccess($this->context->employee->id_profile, Tab::getIdFromClassName('AdminCarriers'));
}
public function setMedia()
{
parent::setMedia();
$this->addJqueryPlugin('smartWizard');
$this->addJqueryPlugin('typewatch');
$this->addJs(_PS_JS_DIR_.'admin_carrier_wizard.js');
}
public function initWizard()
{
$this->wizard_steps = array(
'name' => 'carrier_wizard',
'steps' => array(
array(
'title' => $this->l('General settings'),
),
array(
'title' => $this->l('Shipping locations and costs'),
),
array(
'title' => $this->l('Size, weight, and group access'),
),
array(
'title' => $this->l('Summary'),
),
));
if (Shop::isFeatureActive())
{
$multistore_step = array(
array(
'title' => $this->l('MultiStore'),
'desc' => $this->l('MultiStore'),
)
);
array_splice($this->wizard_steps['steps'], 1, 0, $multistore_step);
}
}
public function renderView()
{
$this->initWizard();
if (Tools::getValue('id_carrier') && $this->tabAccess['edit'])
$carrier = $this->loadObject();
elseif ($this->tabAccess['add'])
$carrier = new Carrier();
if ((!$this->tabAccess['edit'] && Tools::getValue('id_carrier')) || (!$this->tabAccess['add'] && !Tools::getValue('id_carrier')))
{
$this->errors[] = Tools::displayError('You do not have permission to use this wizard.');
return ;
}
$currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
$this->tpl_view_vars = array(
'currency_sign' => $currency->sign,
'PS_WEIGHT_UNIT' => Configuration::get('PS_WEIGHT_UNIT'),
'enableAllSteps' => Validate::isLoadedObject($carrier),
'wizard_steps' => $this->wizard_steps,
'validate_url' => $this->context->link->getAdminLink('AdminCarrierWizard'),
'carrierlist_url' => $this->context->link->getAdminLink('AdminCarriers').'&conf='.((int)Validate::isLoadedObject($carrier) ? 4 : 3),
'wizard_contents' => array(
'contents' => array(
0 => $this->renderStepOne($carrier),
1 => $this->renderStepThree($carrier),
2 => $this->renderStepFour($carrier),
3 => $this->renderStepFive($carrier),
)),
'labels' => array('next' => $this->l('Next'), 'previous' => $this->l('Previous'), 'finish' => $this->l('Finish'))
);
if (Shop::isFeatureActive())
array_splice($this->tpl_view_vars['wizard_contents']['contents'], 1, 0, array(0 => $this->renderStepTwo($carrier)));
$this->context->smarty->assign(array(
'carrier_logo' => (Validate::isLoadedObject($carrier) && file_exists(_PS_SHIP_IMG_DIR_.$carrier->id.'.jpg') ? _THEME_SHIP_DIR_.$carrier->id.'.jpg' : false)
));
$this->content .= $this->createTemplate('logo.tpl')->fetch();
$this->addjQueryPlugin(array('ajaxfileupload'));
return parent::renderView();
}
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 initToolbar()
{
parent::initToolbar();
$this->toolbar_btn['back']['href'] = $this->context->link->getAdminLink('AdminCarriers');
}
public function renderStepOne($carrier)
{
$this->fields_form = array(
'form' => array(
'id_form' => 'step_carrier_general',
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Carrier name:'),
'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' => 'logo',
'label' => $this->l('Logo:'),
'name' => 'logo',
),
array(
'type' => 'text',
'label' => $this->l('Tracking 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.')
),
)),
);
$tpl_vars = array('max_image_size' => (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE') / 1024 / 1024);
$fields_value = $this->getStepOneFieldsValues($carrier);
return $this->renderGenericForm(array('form' => $this->fields_form), $fields_value, $tpl_vars);
}
public function renderStepTwo($carrier)
{
$this->fields_form = array(
'form' => array(
'id_form' => 'step_carrier_shops',
'input' => array(
array(
'type' => 'shop',
'label' => $this->l('Shop association:'),
'name' => 'checkBoxShopAsso',
),
))
);
$fields_value = $this->getStepTwoFieldsValues($carrier);
return $this->renderGenericForm(array('form' => $this->fields_form), $fields_value);
}
public function renderStepThree($carrier)
{
$this->fields_form = array(
'form' => array(
'id_form' => 'step_carrier_ranges',
'input' => array(
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('Apply shipping cost:'),
'name' => 'is_free',
'required' => false,
'class' => 't',
'values' => array(
array(
'id' => 'is_free_off',
'value' => 0,
'label' => '
'
),
array(
'id' => 'is_free_on',
'value' => 1,
'label' => '
'
)
),
'desc' => $this->l('Apply both regular shipping cost and product-specific shipping costs.')
),
array(
'type' => 'radio',
'label' => $this->l('Billing:'),
'name' => 'shipping_method',
'required' => false,
'class' => 't',
'br' => true,
'values' => array(
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'
),
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 no defined range matches the customer\'s cart (e.g. when the weight of the cart is greater than the highest weight limit defined by the weight ranges)')
)
),
));
$tpl_vars = array();
$tpl_vars['PS_WEIGHT_UNIT'] = Configuration::get('PS_WEIGHT_UNIT');
$currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
$tpl_vars['currency_sign'] = $currency->sign;
$fields_value = $this->getStepThreeFieldsValues($carrier);
$this->getTplRangesVarsAndValues($carrier, $tpl_vars, $fields_value);
return $this->renderGenericForm(array('form' => $this->fields_form), $fields_value, $tpl_vars);
}
public function renderStepFour($carrier)
{
$this->fields_form = array(
'form' => array(
'id_form' => 'step_carrier_conf',
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Maximium package height ('.Configuration::get('PS_DIMENSION_UNIT').'):'),
'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.').' '.$this->l('The value must be an integer
.')
),
array(
'type' => 'text',
'label' => $this->l('Maximium package width ('.Configuration::get('PS_DIMENSION_UNIT').'):'),
'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.').' '.$this->l('The value must be an integer
.')
),
array(
'type' => 'text',
'label' => $this->l('Maximium package depth ('.Configuration::get('PS_DIMENSION_UNIT').'):'),
'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.').' '.$this->l('The value must be an integer
.')
),
array(
'type' => 'text',
'label' => $this->l('Maximium package weight ('.Configuration::get('PS_WEIGHT_UNIT').'):'),
'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.')
),
array(
'type' => 'group',
'label' => $this->l('Group access:'),
'name' => 'groupBox',
'values' => Group::getGroups(Context::getContext()->language->id),
'desc' => $this->l('Mark the groups that are allowed access to this carrier.')
)
)
));
$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($carrier)
{
$this->fields_form = array(
'form' => array(
'id_form' => 'step_carrier_summary',
'input' => array(
array(
'type' => 'radio',
'label' => $this->l('Status:'),
'name' => 'active',
'required' => false,
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
'desc' => $this->l('Enable the carrier in the Front Office')
)
)
));
$template = $this->createTemplate('controllers/carrier_wizard/summary.tpl');
$fields_value = $this->getStepFiveFieldsValues($carrier);
$active_form = $this->renderGenericForm(array('form' => $this->fields_form), $fields_value);
$active_form = str_replace(array('