/**
* @property Carrier $object
*/
class AdminCarrierWizardControllerCore extends AdminController
{
protected $wizard_access;
public function __construct()
{
$this->bootstrap = true;
$this->display = 'view';
$this->table = 'carrier';
$this->identifier = 'id_carrier';
$this->className = 'Carrier';
$this->lang = false;
$this->deleted = true;
$this->step_number = 0;
$this->type_context = Shop::getContext();
$this->old_context = Context::getContext();
$this->multishop_context = Shop::CONTEXT_ALL;
$this->context = Context::getContext();
$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'),
)
);
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 = $this->getActualCurrency();
$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),
'multistore_enable' => Shop::isFeatureActive(),
'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->context->smarty->assign(array(
'logo_content' => $this->createTemplate('logo.tpl')->fetch()
));
$this->addjQueryPlugin(array('ajaxfileupload'));
return parent::renderView();
}
public function initBreadcrumbs($tab_id = null, $tabs = null)
{
if (Tools::getValue('id_carrier')) {
$this->display = 'edit';
} else {
$this->display = 'add';
}
parent::initBreadcrumbs((int)Tab::getIdFromClassName('AdminCarriers'));
$this->display = 'view';
}
public function initPageHeaderToolbar()
{
parent::initPageHeaderToolbar();
$this->page_header_toolbar_btn['cancel'] = array(
'href' => $this->context->link->getAdminLink('AdminCarriers'),
'desc' => $this->l('Cancel', null, null, false)
);
}
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',
'required' => true,
'hint' => array(
sprintf($this->l('Allowed characters: letters, spaces and "%s".'), '().-'),
$this->l('The carrier\'s name will be 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,
'maxlength' => 128,
'hint' => $this->l('The estimated delivery time will be displayed during checkout.')
),
array(
'type' => 'text',
'label' => $this->l('Speed grade'),
'name' => 'grade',
'required' => false,
'size' => 1,
'hint' => $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',
'hint' => $this->l('Delivery tracking URL: Type \'@\' where the tracking number should appear. It will be automatically replaced by the tracking number.'),
'desc' => $this->l('For example: \'http://example.com/track.php?num=@\' with \'@\' where the tracking number should appear.')
)
)
)
);
$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',
'force' => true,
'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(
'shipping_handling' => array(
'type' => 'switch',
'label' => $this->l('Add handling costs'),
'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')
)
),
'hint' => $this->l('Include the handling costs (as set in Shipping > Preferences) in the final carrier price.')
),
'is_free' => array(
'type' => 'switch',
'label' => $this->l('Free shipping'),
'name' => 'is_free',
'required' => false,
'class' => 't',
'values' => array(
array(
'id' => 'is_free_on',
'value' => 1,
'label' => '<img src="../img/admin/disabled.gif" alt="'.$this->l('No').'" title="'.$this->l('No').'" />'
),
array(
'id' => 'is_free_off',
'value' => 0,
'label' => '<img src="../img/admin/enabled.gif" alt="'.$this->l('Yes').'" title="'.$this->l('Yes').'" />'
)
),
),
'shipping_method' => 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.')
)
)
),
'id_tax_rules_group' => array(
'type' => 'select',
}