[*] BO #PSFV-94 : Added AdminCarrierController

This commit is contained in:
lLefevre
2011-10-19 14:34:37 +00:00
parent aae577f91b
commit a9cbb3fdcd
13 changed files with 530 additions and 440 deletions
-417
View File
@@ -1,417 +0,0 @@
<?php
/*
* 2007-2011 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-2011 PrestaShop SA
* @version Release: $Revision: 7321 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
include_once(_PS_ADMIN_DIR_.'/../classes/AdminTab.php');
class AdminCarriers extends AdminTab
{
public function __construct()
{
$this->table = 'carrier';
$this->className = 'Carrier';
$this->lang = true;
$this->edit = true;
$this->delete = true;
$this->deleted = true;
$this->fieldImageSettings = array('name' => 'logo', 'dir' => 's');
$this->fieldsDisplay = array(
'id_carrier' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'name' => array('title' => $this->l('Name'), 'width' => 100),
'logo' => array('title' => $this->l('Logo'), 'align' => 'center', 'image' => 's', 'orderby' => false, 'search' => false),
'delay' => array('title' => $this->l('Delay'), 'width' => 300, 'orderby' => false),
'active' => array('title' => $this->l('Status'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false),
'is_free' => array('title' => $this->l('Is Free'), 'align' => 'center', 'icon' => array(0 => 'disabled.gif', 1 => 'enabled.gif', 'default' => 'disabled.gif'), 'type' => 'bool', 'orderby' => false),
'position' => array('title' => $this->l('Position'), 'width' => 40,'filter_key' => 'cp!position', 'align' => 'center', 'position' => 'position')
);
$carrier_default_sort = array(
array('value' => Carrier::SORT_BY_PRICE, 'name' => $this->l('Price')),
array('value' => Carrier::SORT_BY_POSITION, 'name' => $this->l('Position'))
);
$this->optionsList = array(
'general' => array(
'title' => $this->l('Carrier options'),
'fields' => array(
'PS_CARRIER_DEFAULT' => array('title' => $this->l('Default carrier:'), 'desc' => $this->l('The default carrier used in shop'), 'cast' => 'intval', 'type' => 'select',
'identifier' => 'id_carrier', 'list' => Carrier::getCarriers((int)Configuration::get('PS_LANG_DEFAULT'), true, false, false, null, Carrier::ALL_CARRIERS)),
'PS_CARRIER_DEFAULT_SORT' => array('title' => $this->l('Carrier default sort:'), 'desc' => $this->l('This default sort will be available only on front-office'), 'cast' => 'intval', 'type' => 'select',
'identifier' => 'value', 'list' => $carrier_default_sort),
),
),
);
parent::__construct();
}
public function displayTop()
{
echo '
<div class="hint clear" style="display:block;">'.
'&nbsp;<b>'.$this->l('How to create a new carrier?').'</b>'.
'<br />'.
'<ul>'.'
<li>'.$this->l('Click "Add new".').'<br />'.'</li>
<li>'.$this->l('Fill in the fields and click "Save".').'</li>
<li>'.$this->l('You need to decide a price range or a weight range for which the new carrier will be available. Under the "Shipping" tab, click either "Price Ranges" or "Weight Ranges".').'</li>
<li>'.$this->l('Click "Add new".').'</li>
<li>'.$this->l('Select the name of the carrier and define the price range or the weight range. For example the carrier can be made available for a weight range between 0 and 5kgs. Another carrier will have a range between 5 and 10kgs.').'</li>
<li>'.$this->l('When you are done, click "Save".').'</li>
<li>'.$this->l('Click on the "Shipping" tab.').'</li>
<li>'.$this->l('You need to choose the fees that will be applied for this carrier. At the bottom on the page, in the "Fees" section, select the name of the carrier.').'</li>
<li>'.$this->l('For each zone, enter a price. Click "Save".').'</li>
<li>'.$this->l('You\'re set! The new carrier will be displayed to your customers.').'</li>
</ul>
</div><br />';
}
public function displayForm($isMainTab = true)
{
parent::displayForm();
if (!($obj = $this->loadObject(true)))
return;
echo '<script type="text/javascript">
$(document).ready(function(){
// At the loading
($("input[name=\'is_free\']:checked").val() == 0) ? $("#shipping_costs_div").show(): $("#shipping_costs_div").hide();
$("input[name=\'is_free\']").live("change", function(){
($("input[name=\'is_free\']:checked").val() == 0) ? $("#shipping_costs_div").show(): $("#shipping_costs_div").hide();
});
});
</script>
<form action="'.self::$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'" method="post" enctype="multipart/form-data">
'.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
<fieldset><legend><img src="../img/admin/delivery.gif" />'.$this->l('Carriers').'</legend>
<label>'.$this->l('Company:').' </label>
<div class="margin-form">
<input type="text" size="25" name="name" value="'.htmlentities($this->getFieldValue($obj, 'name'), ENT_COMPAT, 'UTF-8').'" /> <sup>*</sup>
<span class="hint" name="help_box">'.$this->l('Allowed characters: letters, spaces and').' ().-<span class="hint-pointer">&nbsp;</span></span>
<p class="clear">'.$this->l('Carrier name displayed during checkout').'<br />'.$this->l('With a value of 0, the carrier name will be replaced by the shop name').'</p>
</div>
<label>'.$this->l('Logo:').' </label>
<div class="margin-form">
<input type="file" name="logo" />
<p>'.$this->l('Upload logo from your computer').' (.gif, .jpg, .jpeg '.$this->l('or').' .png)</p>
</div>
<label>'.$this->l('Transit time:').' </label>
<div class="margin-form">';
foreach ($this->_languages as $language)
echo '
<div id="delay_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
<input type="text" size="41" maxlength="128" name="delay_'.$language['id_lang'].'" value="'.htmlentities($this->getFieldValue($obj, 'delay', (int)($language['id_lang'])), ENT_COMPAT, 'UTF-8').'" /> <sup>*</sup>
</div>';
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'delay', 'delay');
echo '
<p style="clear: both">'.$this->l('Time taken for product delivery; displayed during checkout').'</p>
</div>
<label>'.$this->l('URL:').' </label>
<div class="margin-form">
<input type="text" size="40" name="url" value="'.htmlentities($this->getFieldValue($obj, 'url'), ENT_COMPAT, 'UTF-8').'" />
<p class="clear">'.$this->l('URL for the tracking number; type \'@\' where the tracking number will appear').'</p>
</div>
<label>'.$this->l('Zone').'</label>
<div class="margin-form">';
$carrier_zones = $obj->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)
echo '<input type="checkbox" id="zone_'.$zone['id_zone'].'" name="zone_'.$zone['id_zone'].'" value="true" '.
Tools::getValue('zone_'.$zone['id_zone'], (in_array($zone['id_zone'], $carrier_zones_ids) ? ' checked="checked"' : '')).'>
<label class="t" for="zone_'.$zone['id_zone'].'"> <b>'.$zone['name'].'</b></label><br />';
echo '<p>'.$this->l('The zone in which this carrier is to be used').'</p>
</div>
<label>'.$this->l('Group access').'</label>
<div class="margin-form">';
$groups = Group::getGroups(Context::getContext()->language->id);
if (count($groups))
{
echo '
<table cellspacing="0" cellpadding="0" class="table" style="width: 28em;">
<tr>
<th><input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, \'groupBox[]\', this.checked)"'.(!isset($obj->id) ? 'checked="checked" ' : '').' /></th>
<th>'.$this->l('ID').'</th>
<th>'.$this->l('Group name').'</th>
</tr>';
$irow = 0;
foreach ($groups as $group)
echo '
<tr class="'.($irow++ % 2 ? 'alt_row' : '').'">
<td><input type="checkbox" name="groupBox[]" class="groupBox" id="groupBox_'.$group['id_group'].'" value="'.$group['id_group'].'"
'.((Db::getInstance()->getValue('SELECT id_group FROM '._DB_PREFIX_.'carrier_group
WHERE id_carrier='.(int)$obj->id.' AND id_group='.(int)$group['id_group']) || (!isset($obj->id))) ? 'checked="checked" ' : '').'/></td>
<td>'.$group['id_group'].'</td>
<td><label for="groupBox_'.$group['id_group'].'" class="t">'.$group['name'].'</label></td>
</tr>';
echo '
</table>
<p style="padding:0px; margin:10px 0px 10px 0px;">'.$this->l('Mark all groups you want to give access to this carrier').'</p>
';
}
else
echo '<p>'.$this->l('No group created').'</p>';
echo ' </div>
<label>'.$this->l('Status:').' </label>
<div class="margin-form">
<input type="radio" name="active" id="active_on" value="1" '.($this->getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/>
<label class="t" for="active_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
<input type="radio" name="active" id="active_off" value="0" '.(!$this->getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/>
<label class="t" for="active_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
<p>'.$this->l('Include or exclude carrier from list of carriers on Front Office').'</p>
</div>
<label>'.$this->l('Apply shipping cost:').' </label>
<div class="margin-form">
<input type="radio" name="is_free" id="is_free_on" value="0" '.(!$this->getFieldValue($obj, 'is_free') ? 'checked="checked" ' : '').'/>
<label class="t" for="active_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Yes').'" title="'.$this->l('Yes').'" /></label>
<input type="radio" name="is_free" id="is_free_off" value="1" '.($this->getFieldValue($obj, 'is_free') ? 'checked="checked" ' : '').'/>
<label class="t" for="active_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('No').'" title="'.$this->l('No').'" /></label>
<p>'.$this->l('Apply shipping costs and additional shipping costs by products in carrier price').'</p>
</div>
<div id="shipping_costs_div">
<label>'.$this->l('Tax').'</label>
<div class="margin-form">
<select name="id_tax_rules_group" id="id_tax_rules_group" '.(Tax::excludeTaxeOption() ? 'disabled="disabled"' : '' ).'>
<option value="0">'.$this->l('No Tax').'</option>';
foreach (TaxRulesGroup::getTaxRulesGroups(true) as $tax_rules_group)
echo '<option value="'.$tax_rules_group['id_tax_rules_group'].'" '.(($this->getFieldValue($obj, 'id_tax_rules_group') == $tax_rules_group['id_tax_rules_group']) ? ' selected="selected"' : '').'>'.$tax_rules_group['name'].'</option>';
echo '</select>
</div>
<label>'.$this->l('Shipping & handling:').' </label>
<div class="margin-form">
<input type="radio" name="shipping_handling" id="shipping_handling_on" value="1" '.($this->getFieldValue($obj, 'shipping_handling') ? 'checked="checked" ' : '').'/>
<label class="t" for="shipping_handling_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
<input type="radio" name="shipping_handling" id="shipping_handling_off" value="0" '.(!$this->getFieldValue($obj, 'shipping_handling') ? 'checked="checked" ' : '').'/>
<label class="t" for="shipping_handling_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
<p>'.$this->l('Include the shipping & handling costs in carrier price').'</p>
</div>
<label>'.$this->l('Billing:').' </label>
<div class="margin-form">
<input type="radio" name="shipping_method" id="billing_default" value="'.Carrier::SHIPPING_METHOD_DEFAULT.'" '.($this->getFieldValue($obj, 'shipping_method') == Carrier::SHIPPING_METHOD_DEFAULT ? 'checked="checked" ' : '').'/>
<label class="t" for="billing_default">'.$this->l('Default behavior').'</label><br />
<input type="radio" name="shipping_method" id="billing_price" value="'.Carrier::SHIPPING_METHOD_PRICE.'" '.($this->getFieldValue($obj, 'shipping_method') == Carrier::SHIPPING_METHOD_PRICE ? 'checked="checked" ' : '').'/>
<label class="t" for="billing_price">'.$this->l('According to total price').'</label><br />
<input type="radio" name="shipping_method" id="billing_weight" value="'.Carrier::SHIPPING_METHOD_WEIGHT.'" '.($this->getFieldValue($obj, 'shipping_method') == Carrier::SHIPPING_METHOD_WEIGHT ? 'checked="checked" ' : '').'/>
<label class="t" for="billing_weight">'.$this->l('According to total weight').'</label><br />
</div>
<label>'.$this->l('Out-of-range behavior:').' </label>
<div class="margin-form">
<select name="range_behavior">
<option value="0"'.(!$this->getFieldValue($obj, 'range_behavior') ? ' selected="selected"' : '').'>'.$this->l('Apply the cost of the highest defined range').'</option>
<option value="1"'.($this->getFieldValue($obj, 'range_behavior') ? ' selected="selected"' : '').'>'.$this->l('Disable carrier').'</option>
</select>
<p>'.$this->l('Out-of-range behavior when none is defined (e.g., when a customer\'s cart weight is greater than the highest range limit)').'</p>
</div>';
if ($this->getFieldValue($obj, 'is_module'))
{
echo '<label>'.$this->l('Module:').' </label>
<div class="margin-form"><p> - '.
$this->l('This carrier is bound to this module ').' => '.$this->getFieldValue($obj, 'external_module_name').'</p>
<input type="hidden" name="is_module" value="1">
<input type="hidden" name="external_module_name" value="'.$this->getFieldValue($obj, 'external_module_name').'">';
if ($this->getFieldValue($obj, 'shipping_external'))
{
echo '<p> - '.$this->l('The shipping costs are calculated outside of your shop').'</p>
<input type="hidden" name="shipping_external" value="1">';
}
if ($this->getFieldValue($obj, 'need_range'))
{
echo '<p> - '.$this->l('This carrier uses PrestaShop range to calculate shipping costs').'</p>
<input type="hidden" name="need_range" value="1">';
}
echo '</div>';
}
echo '</div>';
if (Shop::isFeatureActive())
{
echo '<label>'.$this->l('Shop association:').'</label><div class="margin-form">';
$this->displayAssoShop();
echo '</div>';
}
echo '
<div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitAdd'.$this->table.'" class="button" />
</div>
<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
</fieldset>
</form>';
}
public function beforeDelete($object)
{
return $object->isUsed();
}
public function afterDelete($object, $oldId)
{
$object->copyCarrierData((int)($oldId));
}
private 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')))
Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'carrier_group (id_group, id_carrier) VALUES('.(int)$group['id_group'].','.(int)$id_carrier.')');
}
public function postProcess()
{
if (Tools::getValue('submitAdd'.$this->table))
{
/* Checking fields validity */
$this->validateRules();
if (!count($this->_errors))
{
$id = (int)Tools::getValue('id_'.$this->table);
/* Object update */
if (isset($id) && !empty($id))
{
if ($this->tabAccess['edit'] === '1')
{
$object = new $this->className($id);
if (Validate::isLoadedObject($object))
{
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'carrier_group WHERE id_carrier = '.(int)$id);
$object->deleted = 1;
$object->update();
$object_new = new $this->className();
$this->copyFromPost($object_new, $this->table);
$object_new->position = $object->position;
$result = $object_new->add();
if (Validate::isLoadedObject($object_new))
{
$this->afterDelete($object_new, $object->id);
Hook::updateCarrier((int)$object->id, $object_new);
}
$this->changeGroups($object_new->id);
if (!$result)
$this->_errors[] = Tools::displayError('An error occurred while updating object.').' <b>'.$this->table.'</b>';
else if ($this->postImage($object_new->id))
{
$this->changeZones($object_new->id);
Tools::redirectAdmin(self::$currentIndex.'&id_'.$this->table.'='.$object->id.'&conf=4&token='.$this->token);
}
}
else
$this->_errors[] = Tools::displayError('An error occurred while updating object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
}
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
/* Object creation */
else
{
if ($this->tabAccess['add'] === '1')
{
$object = new $this->className();
$this->copyFromPost($object, $this->table);
$object->position = Carrier::getHigherPosition() + 1;
if (!$object->add())
$this->_errors[] = Tools::displayError('An error occurred while creating object.').' <b>'.$this->table.'</b>';
else if (($_POST['id_'.$this->table] = $object->id /* voluntary */) && $this->postImage($object->id) && $this->_redirect)
{
$this->changeZones($object->id);
$this->changeGroups($object->id);
Tools::redirectAdmin(self::$currentIndex.'&id_'.$this->table.'='.$object->id.'&conf=3'.'&token='.$this->token);
}
}
else
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
}
}
}
else if ((isset($_GET['status'.$this->table]) || isset($_GET['status'])) && Tools::getValue($this->identifier))
{
if ($this->tabAccess['edit'] === '1')
{
if (Tools::getValue('id_carrier') == Configuration::get('PS_CARRIER_DEFAULT'))
$this->_errors[] = Tools::displayError('You can\'t disable the default carrier, please change your default carrier first.');
else
parent::postProcess();
}
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
else
{
if ((Tools::isSubmit('submitDel'.$this->table) && in_array(Configuration::get('PS_CARRIER_DEFAULT'), Tools::getValue('carrierBox')))
|| (isset($_GET['delete'.$this->table]) && Tools::getValue('id_carrier') == Configuration::get('PS_CARRIER_DEFAULT')))
$this->_errors[] = $this->l('Please set another carrier as default before deleting');
else
parent::postProcess();
}
}
public function changeZones($id)
{
$carrier = new $this->className($id);
if (!Validate::isLoadedObject($carrier))
die (Tools::displayError('Object cannot be loaded'));
$zones = Zone::getZones(true);
foreach ($zones as $zone)
if (count($carrier->getZone($zone['id_zone'])))
{
if (!isset($_POST['zone_'.$zone['id_zone']]) || !$_POST['zone_'.$zone['id_zone']])
$carrier->deleteZone($zone['id_zone']);
}
else
if (isset($_POST['zone_'.$zone['id_zone']]) && $_POST['zone_'.$zone['id_zone']])
$carrier->addZone($zone['id_zone']);
}
public function displayListContent($token = null)
{
foreach ($this->_list as $key => $list)
if ($list['name'] == '0')
$this->_list[$key]['name'] = Configuration::get('PS_SHOP_NAME');
parent::displayListContent($token);
}
/**
* Modifying initial getList method to display position feature (drag and drop)
*/
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
{
$order_by = ($order_by && $this->context->cookie->__get($this->table.'Orderby')) ? $this->context->cookie->__get($this->table.'Orderby'): 'position';
parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
}
}
+295
View File
@@ -0,0 +1,295 @@
{*
* 2007-2011 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-2011 PrestaShop SA
* @version Release: $Revision: 8971 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
{if $firstCall}
<script type="text/javascript">
var vat_number = {$vat_number};
var module_dir = '{$module_dir}';
var id_language = {$defaultFormLanguage};
var languages = new Array();
$(document).ready(function() {ldelim}
{foreach $languages as $k => $language}
languages[{$k}] = {ldelim}
id_lang: {$language.id_lang},
iso_code: '{$language.iso_code}',
name: '{$language.name}'
{rdelim};
{/foreach}
displayFlags(languages, id_language, {$allowEmployeeFormLang});
{if isset($fields_value.id_state)}
if ($('#id_country') && $('#id_state'))
{ldelim}
ajaxStates({$fields_value.id_state});
$('#id_country').change(function() {ldelim}
ajaxStates();
{rdelim});
{rdelim}
{/if}
// At the loading
($("input[name='is_free']:checked").val() == 0) ? $('#shipping_costs_div').show('toggle'): $('#shipping_costs_div').hide();
$("input[name='is_free']").live('change', function() {ldelim}
($("input[name='is_free']:checked").val() == 0) ? $('#shipping_costs_div').show('toggle'): $('#shipping_costs_div').hide();
{rdelim});
{rdelim});
</script>
<script type="text/javascript" src="../js/form.js"></script>
{/if}
<form action="{$current}&submitAdd{$table}=1&token={$token}" method="post" enctype="multipart/form-data">
{if $form_id}
<input type="hidden" name="id_{$table}" value="{$form_id}" />
{/if}
<fieldset>
{foreach $fields as $key => $field}
{if $key == 'legend'}
<legend>
{if isset($field.image)}<img src="{$field.image}" alt="{$field.title}" />{/if}
{$field.title}
</legend>
{elseif $key == 'input'}
{foreach $field as $input}
{if $input.name == 'id_state'}
<div id="contains_states" {if $contains_states}style="display:none;"{/if}>
{/if}
{if $input.name == 'id_tax_rules_group'}<div id="shipping_costs_div">{/if}
{if isset($input.label)}
{if $input.name == 'is_module' && $fields_value['is_module'] == 0}
{else}
<label>{$input.label} </label>
{/if}
{/if}
<div class="margin-form">
{if $input.type == 'text'}
{if isset($input.lang) && isset($input.attributeLang)}
{foreach $languages as $language}
<div id="{$input.name}_{$language.id_lang}" style="display:{if $language.id_lang == $defaultFormLanguage}block{else}none{/if}; float: left;">
<input type="text"
name="{$input.name}_{$language.id_lang}"
value="{$fields_value[$input.name][$language.id_lang]}"
{if isset($input.size)}size="{$input.size}"{/if}
{if isset($input.maxlength)}maxlength="{$input.maxlength}"{/if}
{if isset($input.class)}class="{$input.class}"{/if}
{if isset($input.readonly) && $input.readonly}readonly="readonly"{/if} />
{if isset($input.hint)}<span class="hint" name="help_box">{$input.hint}<span class="hint-pointer">&nbsp;</span></span>{/if}
</div>
{/foreach}
{if count($languages) > 1}
<div class="displayed_flag">
<img src="../img/l/{$defaultFormLanguage}.jpg"
class="pointer"
id="language_current_{$input.name}"
onclick="toggleLanguageFlags(this);" />
</div>
<div id="languages_{$input.name}" class="language_flags">
{l s='Choose language:'}<br /><br />
{foreach $languages as $language}
<img src="../img/l/{$language.id_lang}.jpg"
class="pointer"
alt="{$language.name}"
title="{$language.name}"
onclick="changeLanguage('{$input.name}', '{$input.attributeLang}', {$language.id_lang}, '{$language.iso_code}');" />
{/foreach}
</div>
{/if}
{else}
<input type="text"
name="{$input.name}"
id="{$input.name}"
value="{$fields_value[$input.name]}"
{if isset($input.size)}size="{$input.size}"{/if}
{if isset($input.maxlength)}maxlength="{$input.maxlength}"{/if}
{if isset($input.class)}class="{$input.class}"{/if}
{if isset($input.readonly) && $input.readonly}readonly="readonly"{/if} />
{if isset($input.hint)}<span class="hint" name="help_box">{$input.hint}<span class="hint-pointer">&nbsp;</span></span>{/if}
{/if}
{elseif $input.type == 'hidden'}
{if $input.name == 'is_module'}
{if $fields_value['is_module'] != 0}
<p> - {l s='This carrier is bound to this module '} : {$fields_value['external_module_name']}</p>
<input type="hidden" name="is_module" value="1">
<input type="hidden" name="external_module_name" value="{$fields_value['external_module_name']}">
{if $fields_value['shipping_external'] != 0}
<p> - {l s='The shipping costs are calculated outside of your shop'}</p>
<input type="hidden" name="shipping_external" value="1">
{/if}
{if $fields_value['need_range'] != 0}
<p> - {l s='This carrier uses PrestaShop range to calculate shipping costs'}</p>
<input type="hidden" name="need_range" value="1">
{/if}
{/if}
{else}
<input type="hidden" name="{$input.name}" value="{$fields_value[$input.name]}" />
{/if}
{elseif $input.type == 'select'}
<select name="{$input.name}" id="{$input.name}" {if isset($input.multiple)}multiple="multiple" {/if}{if isset($input.onchange)}onchange="{$input.onchange}"{/if}>
{if isset($input.options.default)}
<option value="{$input.options.default.value}">{$input.options.default.label}</option>
{/if}
{if isset($input.options.optiongroup)}
{foreach $input.options.optiongroup.query AS $optiongroup}
<optgroup label="{$optiongroup[$input.options.optiongroup.label]}">
{foreach $optiongroup[$input.options.options.query] as $option}
<option value="{$option[$input.options.options.id]}"
{if isset($input.multiple)}
{foreach $fields_value[$input.name] as $field_value}
{if $field_value == $option[$input.options.options.id]}selected="selected"{/if}
{/foreach}
{else}
{if $fields_value[$input.name] == $option[$input.options.options.id]}selected="selected"{/if}
{/if}
>{$option[$input.options.options.name]|escape:'htmlall':'UTF-8'}</option>
{/foreach}
</optgroup>
{/foreach}
{else}
{foreach $input.options.query AS $option}
<option value="{$option[$input.options.id]}"
{if isset($input.multiple)}
{foreach $fields_value[$input.name] as $field_value}
{$field_value}
{if $field_value == $option[$input.options.id]}selected="selected"{/if}
{/foreach}
{else}
{if $fields_value[$input.name] == $option[$input.options.id]}selected="selected"{/if}
{/if}
>{$option[$input.options.name]|escape:'htmlall':'UTF-8'}</option>
{/foreach}
{/if}
</select>
{if isset($input.hint)}<span class="hint" name="help_box">{$input.hint}<span class="hint-pointer">&nbsp;</span></span>{/if}
{elseif $input.type == 'radio'}
{foreach $input.values as $value}
<input type="radio"
name="{$input.name}"
id="{$value.id}"
value="{$value.value|escape:'htmlall':'UTF-8'}"
{if $fields_value[$input.name] == $value.value}checked="checked"{/if} />
<label {if isset($input.class)}class="{$input.class}"{/if} for="{$value.id}">
{if isset($input.is_bool) && $input.is_bool == true}
{if $value.value == 1}
<img src="../img/admin/enabled.gif" alt="{$value.label}" title="{$value.label}" />
{else}
<img src="../img/admin/disabled.gif" alt="{$value.label}" title="{$value.label}" />
{/if}
{else}
{$value.label}
{/if}
</label>
{if isset($input.br) && $input.br}<br />{/if}
{/foreach}
{elseif $input.type == 'textarea'}
{if isset($input.lang) && isset($input.attributeLang)}
{foreach $languages as $language}
<div id="{$input.name}_{$language.id_lang}" style="display:{if $language.id_lang == $defaultFormLanguage}block{else}none{/if}; float: left;">
<textarea cols="{$input.cols}" rows="{$input.rows}" name="{$input.name}_{$language.id_lang}">{$fields_value[$input.name][$language.id_lang]}</textarea>
</div>
{/foreach}
{if count($languages) > 1}
<div class="displayed_flag">
<img src="../img/l/{$defaultFormLanguage}.jpg"
class="pointer"
id="language_current_{$input.name}"
onclick="toggleLanguageFlags(this);" />
</div>
<div id="languages_{$input.name}" class="language_flags">
{l s='Choose language:'}<br /><br />
{foreach $languages as $language}
<img src="../img/l/{$language.id_lang}.jpg"
class="pointer"
alt="{$language.name}"
title="{$language.name}"
onclick="changeLanguage('{$input.name}', '{$input.attributeLang}', {$language.id_lang}, '{$language.iso_code}');" />
{/foreach}
</div>
{/if}
{else}
<textarea name="{$input.name}" id="{$input.name}" cols="{$input.cols}" rows="{$input.rows}">{$fields_value[$input.name]}</textarea>
{/if}
{elseif $input.type == 'checkbox'}
{foreach $input.values.query as $value}
{assign var=id_checkbox value=$input.name|cat:'_'|cat:$value[$input.values.id]}
<input type="checkbox" name="{$id_checkbox}" id="{$id_checkbox}" {if $fields_value[$id_checkbox]}checked="checked"{/if} />
<label for="{$id_checkbox}" class="t"><strong>{$value[$input.values.name]}</strong></label><br />
{/foreach}
{elseif $input.type == 'file'}
<input type="file" name="{$input.name}" />
<img src="{$fields_value[$input.name]}" />
{elseif $input.type == 'group'}
{assign var=groups value=$input.values}
{include file='form_group.tpl'}
{elseif $input.type == 'shop' OR $input.type == 'group_shop'}
{include file='form_shop.tpl'}
{elseif $input.type == 'asso_shop' && isset($asso_shop) && $asso_shop}
<label>{l s='Shop association:'}</label>
<div class="margin-form">
{$asso_shop}
</div>
{/if}
{if isset($input.required) && $input.required} <sup>*</sup>{/if}
{if isset($input.p)}
<p class="clear">
{if is_array($input.p)}
{foreach $input.p as $p}
{if is_array($p)}
<span id="{$p.id}">{$p.text}</span><br />
{else}
{$p}<br />
{/if}
{/foreach}
{else}
{$input.p}
{/if}
</p>
{/if}
</div>
{if $input.name == 'range_behavior'}</div>{/if}
{if $input.name == 'id_state'}</div>{/if}
{/foreach}
{elseif $key == 'submit'}
<div class="margin-form">
<input type="submit" value="{$field.title}" name="submitAdd{$table}" {if isset($field.class)}class="{$field.class}"{/if} />
</div>
{/if}
{/foreach}
{if $required_fields}
<div class="small"><sup>*</sup> {l s ='Required field'}</div>
{/if}
</fieldset>
</form>
<br /><br />
{if $firstCall}
{if $back}
<a href="{$back}"><img src="../img/admin/arrow2.gif" />{l s='Back'}</a>
{else}
<a href="{$current}&token={$token}"><img src="../img/admin/arrow2.gif" />{l s='Back to list'}</a>
{/if}
<br />
{/if}
+5
View File
@@ -214,6 +214,11 @@
{elseif $input.type == 'file'}
<input type="file" name="{$input.name}" />
<img src="{$fields_value[$input.name]}" />
{elseif $input.type == 'group'}
{assign var=groups value=$input.values}
{include file='form_group.tpl'}
{elseif $input.type == 'shop' OR $input.type == 'group_shop'}
{include file='form_shop.tpl'}
{elseif $input.type == 'asso_shop' && isset($asso_shop) && $asso_shop}
<label>{l s='Shop association:'}</label>
<div class="margin-form">
+49
View File
@@ -0,0 +1,49 @@
{*
* 2007-2011 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-2011 PrestaShop SA
* @version Release: $Revision: 8971 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
{if count($groups) && isset($groups)}
<table cellspacing="0" cellpadding="0" class="table" style="width:28em;">
<tr>
<th>
<input type="checkbox" name="checkme" id="checkme" class="noborder" onclick="checkDelBoxes(this.form, 'groupBox[]', this.checked)" />
</th>
<th>{l s='ID'}</th>
<th>{l s='Group name'}</th>
</tr>
{foreach $groups as $key => $group}
<tr {if $key %2}class="alt_row"{/if}>
<td>
{assign var=id_checkbox value=groupBox|cat:'_'|cat:$group['id_group']}
<input type="checkbox" name="groupBox[]" class="groupBox" id="{$id_checkbox}" value="{$group['id_group']}" {if $fields_value[$id_checkbox]}checked="checked"{/if} />
</td>
<td>{$group['id_group']}</td>
<td><label for="{$id_checkbox}" class="t">{$group['name']}</label></td>
</tr>
{/foreach}
</table>
{else}
<p>{l s='No group created'}</p>
{/if}
+131
View File
@@ -0,0 +1,131 @@
{*
* 2007-2011 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-2011 PrestaShop SA
* @version Release: $Revision: 8971 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<script type="text/javascript">
$().ready(function() {ldelim}
// Click on "all shop"
$('.input_all_shop').click(function() {ldelim}
var checked = $(this).attr('checked');
$('.input_group_shop').attr('checked', checked);
$('.input_shop').attr('checked', checked);
{rdelim});
// Click on a group shop
$('.input_group_shop').click(function() {ldelim}
$('.input_shop[value='+$(this).val()+']').attr('checked', $(this).attr('checked'));
check_all_shop();
{rdelim});
// Click on a shop
$('.input_shop').click(function() {ldelim}
check_group_shop_status($(this).val());
check_all_shop();
{rdelim});
// Initialize checkbox
$('.input_shop').each(function(k, v) {ldelim}
check_group_shop_status($(v).val());
check_all_shop();
{rdelim});
{rdelim});
function check_group_shop_status(id_group) {ldelim}
var groupChecked = true;
$('.input_shop[value='+id_group+']').each(function(k, v) {ldelim}
if (!$(v).attr('checked'))
groupChecked = false;
{rdelim});
$('.input_group_shop[value='+id_group+']').attr('checked', groupChecked);
{rdelim}
function check_all_shop() {ldelim}
var allChecked = true;
$('.input_group_shop').each(function(k, v) {ldelim}
if (!$(v).attr('checked'))
allChecked = false;
{rdelim});
$('.input_all_shop').attr('checked', allChecked);
{rdelim}
</script>
<div class="assoShop">
<table class="table" cellpadding="0" cellspacing="0" width="100%">
<tr>
<th>{l s='Shop'}</th>
</tr>
<tr {if $input.type == 'group_shop'}class="alt_row"{/if}>
<td>
<label class="t"><input class="input_all_shop" type="checkbox" /> {l s='All shops'}</label>
</td>
</tr>
{foreach $input.values as $groupID => $groupData}
{if ($input.type == 'group_shop' && ((isset($fields_value.shop[$groupID]) && in_array($form_id, $fields_value.shop[$groupID])) || !$form_id))}
{assign var=groupChecked value=true}
{else}
{assign var=groupChecked value=false}
{/if}
<tr {if $input.type == 'shop'}class="alt_row"{/if}>
<td>
<img style="vertical-align:middle;" alt="" src="../img/admin/lv2_b.gif" />
<label class="t">
<input class="input_group_shop"
type="checkbox"
name="checkBoxGroupShopAsso_{$table}_{$form_id}_{$groupID}"
value="{$groupID}"
{if $groupChecked} checked="checked"{/if} />
{$groupData['name']}
</label>
</td>
</tr>
{if $input.type = 'shop'}
{assign var=j value=0}
{foreach $groupData['shops'] as $shopID => $shopData}
{if ((isset($fields_value.shop[$shopID]) && in_array($form_id, $fields_value.shop[$shopID])) || !$form_id)}
{assign var=checked value=true}
{else}
{assign var=checked value=false}
{/if}
<tr>
<td>
<img style="vertical-align:middle;" alt="" src="../img/admin/lv3_{if $j < count($groupData['shops']) - 1}b{else}f{/if}.png" />
<label class="child">
<input class="input_shop"
type="checkbox"
value="{$groupID}"
name="checkBoxShopAsso_{$table}_{$form_id}_{$shopID}"
id="checkedBox_{$shopID}"
{if $checked} checked="checked"{/if} />
{$shopData['name']}
</label>
</td>
</tr>
{assign var=j value=$j+1}
{/foreach}
{/if}
{/foreach}
</table>
</div>
@@ -82,7 +82,8 @@
name="{$input.name}"
id="{$input.name}"
value="{$fields_value[$input.name]}"
{if isset($input.size)}size="{$input.size}"{/if}
{if isset($input.size)}size="{$input.size}"{/if}
{if isset($input.maxlength)}maxlength="{$input.maxlength}"{/if}
{if isset($input.class)}class="{$input.class}"{/if}
{if isset($input.readonly) && $input.readonly}readonly="readonly"{/if} />
{elseif $input.type == 'select'}
+2 -1
View File
@@ -144,7 +144,8 @@
name="{$input.name}"
id="{$input.name}"
value="{$fields_value[$input.name]}"
{if isset($input.size)}size="{$input.size}"{/if}
{if isset($input.size)}size="{$input.size}"{/if}
{if isset($input.maxlength)}maxlength="{$input.maxlength}"{/if}
{if isset($input.class)}class="{$input.class}"{/if}
{if isset($input.readonly) && $input.readonly}readonly="readonly"{/if} />
{elseif $input.type == 'select'}
+6 -4
View File
@@ -83,13 +83,13 @@
{if $input.name == 'latitude'}
<input type="text"
{if isset($input.size)}size="{$input.size}"{/if}
{if isset($input.maxlength)}size="{$input.maxlength}"{/if}
{if isset($input.maxlength)}maxlength="{$input.maxlength}"{/if}
name="latitude"
id="latitude"
value="{$fields_value[$input.name]}" /> /
<input type="text"
{if isset($input.size)}size="{$input.size}"{/if}
{if isset($input.maxlength)}size="{$input.maxlength}"{/if}
{if isset($input.maxlength)}maxlength="{$input.maxlength}"{/if}
name="longitude"
id="longitude"
value="{$fields_value['longitude']}" />
@@ -100,7 +100,8 @@
<input type="text"
name="{$input.name}_{$language.id_lang}"
value="{$fields_value[$input.name][$language.id_lang]}"
{if isset($input.size)}size="{$input.size}"{/if}
{if isset($input.size)}size="{$input.size}"{/if}
{if isset($input.maxlength)}maxlength="{$input.maxlength}"{/if}
{if isset($input.class)}class="{$input.class}"{/if}
{if isset($input.readonly) && $input.readonly}readonly="readonly"{/if} />
{if isset($input.hint)}<span class="hint" name="help_box">{$input.hint}<span class="hint-pointer">&nbsp;</span></span>{/if}
@@ -129,7 +130,8 @@
name="{$input.name}"
id="{$input.name}"
value="{$fields_value[$input.name]}"
{if isset($input.size)}size="{$input.size}"{/if}
{if isset($input.size)}size="{$input.size}"{/if}
{if isset($input.maxlength)}maxlength="{$input.maxlength}"{/if}
{if isset($input.class)}class="{$input.class}"{/if}
{if isset($input.readonly) && $input.readonly}readonly="readonly"{/if} />
{if isset($input.hint)}<span class="hint" name="help_box">{$input.hint}<span class="hint-pointer">&nbsp;</span></span>{/if}
@@ -24,9 +24,6 @@
* International Registered Trademark & Property of PrestaShop SA
*}
<br />
<script type="text/javascript">
id_language = Number({$id_lang});
</script>
<form action="{$current}&submitOptions{$table}=1&token={$token}" method="post" enctype="multipart/form-data">
{foreach $optionsList AS $category => $categoryData}
+22 -8
View File
@@ -1077,6 +1077,7 @@ class AdminControllerCore extends Controller
$helper->table = $this->table;
$helper->_orderBy = $this->_orderBy;
$helper->_orderWay = $this->_orderWay;
$helper->_listTotal = $this->_listTotal;
$helper->shopLink = $this->shopLink;
$helper->shopLinkType = $this->shopLinkType;
$helper->identifier = $this->identifier;
@@ -1088,15 +1089,19 @@ class AdminControllerCore extends Controller
// For each action, try to add the corresponding skip elements list
$helper->list_skip_actions = $this->list_skip_actions;
$this->content .= $helper->generateList($this->_list, $this->fieldsDisplay);
}
else if ($this->display == 'options')
{
// init options declaration
$this->initOptions();
$helper = new HelperOptions();
$this->content .= $helper->generateOptions();
if ($this->options)
{
$helper = new HelperOptions();
$helper->id = $this->id;
$helper->currentIndex = self::$currentIndex;
$this->content .= $helper->generateOptions($this->options);
}
}
}
/**
@@ -1758,7 +1763,13 @@ class AdminControllerCore extends Controller
}
}
protected function updateAssoShop($id_object = false)
/**
* Update the associations of shops
*
* @param int $id_object
* @param int $new_id_object
*/
protected function updateAssoShop($id_object = false, $new_id_object = false)
{
if (!Shop::isFeatureActive())
return;
@@ -1782,9 +1793,10 @@ class AdminControllerCore extends Controller
}
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.$this->table.'_'.$type.($id_object ? ' WHERE `'.$this->identifier.'`='.(int)$id_object : ''));
foreach ($assos as $asso)
Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.$this->table.'_'.$type.' (`'.pSQL($this->identifier).'`, id_'.$type.')
VALUES('.(int)$asso['id_object'].', '.(int)$asso['id_'.$type].')');
VALUES('.($new_id_object ? $new_id_object : (int)$asso['id_object']).', '.(int)$asso['id_'.$type].')');
}
protected function validateField($value, $field)
@@ -1825,6 +1837,8 @@ class AdminControllerCore extends Controller
$languages = Language::getLanguages(false);
// init options declaration
$this->initOptions();
foreach ($this->options as $category => $category_data)
{
$fields = $category_data['fields'];
+13 -2
View File
@@ -546,9 +546,7 @@ class CarrierCore extends ObjectModel
if (Configuration::get('PS_CARRIER_DEFAULT_SORT') == Carrier::SORT_BY_PRICE)
{
foreach ($results_array as $r)
{
$prices[] = $r['price'];
}
array_multisort($prices, SORT_NUMERIC, $results_array);
}
@@ -619,6 +617,19 @@ class CarrierCore extends ObjectModel
AND `id_zone` = '.(int)$id_zone.' LIMIT 1');
}
/**
* Get a specific group
*
* @return array Group
*/
public function getGroups()
{
return Db::getInstance()->executeS('
SELECT id_group
FROM '._DB_PREFIX_.'carrier_group
WHERE id_carrier='.(int)$this->id);
}
/**
* Clean delivery prices (weight/price)
*
+3 -2
View File
@@ -31,7 +31,7 @@ class HelperListCore extends Helper
protected $_list = array();
/** @var integer Number of results in list */
protected $_listTotal = 0;
public $_listTotal = 0;
/** @var array WHERE clause determined by filter fields */
protected $_filter;
@@ -95,7 +95,8 @@ class HelperListCore extends Helper
'id_category' => 'id_category_to_move',
'id_cms_category' => 'id_cms_category_to_move',
'id_cms' => 'id_cms',
'id_attribute' => 'id_attribute'
'id_attribute' => 'id_attribute',
'id_carrier' => 'id_carrier'
);
// @var boolean ask for simple header : no filters, no paginations and no sorting
+2 -2
View File
@@ -112,7 +112,7 @@ class HelperOptionsCore extends Helper
// Is at least one required field present?
if (isset($field['required']) && $field['required'])
$required_fields = true;
$this->required = true;
}
// Assign the modifications back to parent array
$option_list[$category] = $category_data;
@@ -122,7 +122,7 @@ class HelperOptionsCore extends Helper
'current' => $this->currentIndex,
'option_list' => $option_list,
'current_id_lang' => $this->context->language->id,
'required_fields' => $required_fields,
'required_fields' => $this->required,
));
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/'.$this->tpl);
}