[*] BO : #PSFV-94 - added AdminShippingController

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9727 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
tDidierjean
2011-10-28 15:46:01 +00:00
parent 4e0a3102a3
commit bb01a8debc
6 changed files with 331 additions and 324 deletions
-310
View File
@@ -1,310 +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: 6844 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminShipping extends AdminTab
{
private $_fieldsHandling;
public function __construct()
{
$this->context = Context::getContext();
$this->table = 'delivery';
$this->_fieldsHandling = array(
'PS_SHIPPING_HANDLING' => array('title' => $this->l('Handling charges'), 'suffix' => $this->context->currency, 'validation' => 'isPrice', 'cast' => 'floatval'),
'PS_SHIPPING_FREE_PRICE' => array('title' => $this->l('Free shipping starts at'), 'suffix' => $this->context->currency, 'validation' => 'isPrice', 'cast' => 'floatval'),
'PS_SHIPPING_FREE_WEIGHT' => array('title' => $this->l('Free shipping starts at'), 'suffix' => Configuration::get('PS_WEIGHT_UNIT'), 'validation' => 'isUnsignedFloat', 'cast' => 'floatval'),
'PS_SHIPPING_METHOD' => array('title' => $this->l('Billing'), 'validation' => 'isBool', 'cast' => 'intval'));
parent::__construct();
}
public function postProcess()
{
/* Handling settings */
if (Tools::isSubmit('submitHandling'.$this->table))
{
if ($this->tabAccess['edit'] === '1')
{
/* Check required fields */
foreach ($this->_fieldsHandling AS $field => $values)
if (($value = Tools::getValue($field)) == false AND (string)$value != '0')
$this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is required.');
/* Check field validity */
foreach ($this->_fieldsHandling AS $field => $values)
if (Tools::getValue($field))
{
$function = $values['validation'];
if (!Validate::$function(Tools::getValue($field)))
$this->_errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is invalid.');
}
/* Update configuration values */
if (!sizeof($this->_errors))
{
foreach ($this->_fieldsHandling AS $field => $values)
{
$function = $values['cast'];
Configuration::updateValue($field, call_user_func($function, Tools::getValue($field)));
}
Tools::redirectAdmin(self::$currentIndex.'&conf=6'.'&token='.$this->token);
}
}
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
/* Shipping fees */
elseif (Tools::isSubmit('submitFees'.$this->table))
{
if ($this->tabAccess['edit'] === '1')
{
if (($id_carrier = (int)(Tools::getValue('id_carrier'))) AND $id_carrier == ($id_carrier2 = (int)(Tools::getValue('id_carrier2'))))
{
$carrier = new Carrier($id_carrier);
if (Validate::isLoadedObject($carrier))
{
/* Get configuration values */
$shipping_method = $carrier->getShippingMethod();
$rangeTable = $carrier->getRangeTable();
$carrier->deleteDeliveryPrice($rangeTable);
$currentList = Carrier::getDeliveryPriceByRanges($rangeTable, $id_carrier);
/* Build prices list */
$priceList = array();
foreach ($_POST AS $key => $value)
if (strstr($key, 'fees_'))
{
$tmpArray = explode('_', $key);
$price = number_format(abs(str_replace(',', '.', $value)), 6, '.', '');
$current = 0;
foreach ($currentList as $item)
if ($item['id_zone'] == $tmpArray[1] && $item['id_'.$rangeTable] == $tmpArray[2])
$current = $item;
if ($current && $price == $current['price'])
continue;
$priceList[] = array(
'id_range_price' => ($shipping_method == Carrier::SHIPPING_METHOD_PRICE) ? (int)$tmpArray[2] : null,
'id_range_weight' => ($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT) ? (int)$tmpArray[2] : null,
'id_carrier' => (int)$carrier->id,
'id_zone' => (int)$tmpArray[1],
'price' => $price,
);
}
/* Update delivery prices */
$carrier->addDeliveryPrice($priceList);
Tools::redirectAdmin(self::$currentIndex.'&conf=6&id_carrier='.$carrier->id.'&token='.$this->token);
}
else
$this->_errors[] = Tools::displayError('An error occurred while updating fees (cannot load carrier object).');
}
elseif (isset($id_carrier2))
{
$_POST['id_carrier'] = $id_carrier2;
}
else
$this->_errors[] = Tools::displayError('An error occurred while updating fees (cannot load carrier object).');
}
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
}
public function display()
{
$this->displayFormHandling();
$this->displayFormFees();
}
public function displayFormHandling()
{
$confKeys = $this->_fieldsHandling;
foreach ($confKeys AS $key => $confKey)
$getConf[] = $key;
$confValues = Configuration::getMultiple($getConf);
unset($confKeys['PS_SHIPPING_METHOD']);
echo '
<form action="'.self::$currentIndex.'&submitHandling'.$this->table.'=1&token='.$this->token.'" method="post">
<fieldset>
<legend><img src="../img/admin/delivery.gif" />'.$this->l('Handling').'</legend>';
foreach ($confKeys AS $key => $confKey)
{
$postValue = Tools::getValue($key);
$sign_left = (is_object($confKey['suffix']) ? $confKey['suffix']->getSign('left') : '');
$sign_right = (is_object($confKey['suffix']) ? $confKey['suffix']->getSign('right') : (is_string($confKey['suffix']) ? '&nbsp;'.$confKey['suffix'] : ''));
echo '
<label class="clear">'.$confKey['title'].':</label>
<div class="margin-form">';
echo $sign_left;
echo '<input size="6" type="text" name="'.$key.'" value="'.(($postValue != false OR (string)$postValue == '0') ? $postValue : $confValues[$key]).'" />';
echo $sign_right.' '.($key == 'PS_SHIPPING_HANDLING' ? $this->l('(tax excl.)') : '');
echo '</div>';
}
echo '
<div class="margin-form" style="margin-top: 20px;">
<input type="submit" value="'.$this->l(' Save ').'" name="submitHandling'.$this->table.'" class="button" />
</div>
<p style="font-weight: bold; font-size: 11px;">'.$this->l('Tips:').'</p>
<ul style="list-style-type: disc; font-size: 11px; color:#7F7F7F; margin-left: 30px; line-height: 20px;">
<li>'.$this->l('If you set these parameters to 0, they will be disabled').'</li>
<li>'.$this->l('Coupons are not taken into account when calculating free shipping').'</li>
</ul>
</fieldset>
<br />
<fieldset>
<legend><img src="../img/admin/money.gif" />'.$this->l('Billing').'</legend>
<label class="clear">'.$this->l('Choice of range:').' </label>
<div class="margin-form">
<input type="radio" name="PS_SHIPPING_METHOD" value="0" id="total_price"
'.((isset($confValues['PS_SHIPPING_METHOD']) AND $confValues['PS_SHIPPING_METHOD'] == 0) ? 'checked="checked"' : '').'/>
<label class="t" for="total_price"> '.$this->l('According to total price').'</label><br />
<input type="radio" name="PS_SHIPPING_METHOD" value="1" id="total_weight"
'.((!isset($confValues['PS_SHIPPING_METHOD']) OR $confValues['PS_SHIPPING_METHOD'] == 1) ? 'checked="checked"' : '').'/>
<label class="t" for="total_weight"> '.$this->l('According to total weight').'</label>
</div>
<div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitHandling'.$this->table.'" class="button" />
</div>
</fieldset>
</form>';
}
public function displayFormFees()
{
$carrierArray = array();
$id_carrier = Tools::getValue('id_carrier');
$carriers = Carrier::getCarriers(Configuration::get('PS_LANG_DEFAULT'), true , false,false, NULL, Carrier::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
foreach ($carriers AS $carrier)
if (!$carrier['is_free'])
$carrierArray[] = array(
'id' => $carrier['id_carrier'],
'display' => '<option value="'.(int)($carrier['id_carrier']).'"'.(($carrier['id_carrier'] == $id_carrier) ? ' selected="selected"' : '').'>'.$carrier['name'].'</option>'
);
if (count($carrierArray))
{
if (!$id_carrier)
$id_carrier = (int)$carrierArray[0]['id'];
$carrierSelected = new Carrier($id_carrier);
}
echo '<br /><br />
<h2>'.$this->l('Fees by carrier, geographical zone, and ranges').'</h2>
<form action="'.self::$currentIndex.'&token='.$this->token.'" id="fees" name="fees" method="post">
<fieldset>
<legend><img src="../img/admin/delivery.gif" />'.$this->l('Fees').'</legend>';
if (!count($carrierArray))
echo $this->l('You only have free carriers, there is no need to configure your delivery prices.');
else
{
echo '<b>'.$this->l('Carrier:').' </b>
<select name="id_carrier2" onchange="$(\'#fees\').attr(\'action\', $(\'#fees\').attr(\'action\')+\'&id_carrier=\'+$(this).attr(\'value\')); $(\'#fees\').submit();">';
foreach ($carrierArray AS $carrierOption)
echo $carrierOption['display'];
echo '
</select><br />
<table class="table space" cellpadding="0" cellspacing="0">
<tr>
<th>'.$this->l('Zone / Range').'</th>';
$currency = $this->context->currency;
$rangeObj = $carrierSelected->getRangeObject();
$rangeTable = $carrierSelected->getRangeTable();
$suffix = $carrierSelected->getRangeSuffix();
$rangeIdentifier = 'id_'.$rangeTable;
$ranges = $rangeObj->getRanges($id_carrier);
$delivery = Carrier::getDeliveryPriceByRanges($rangeTable, $id_carrier);
foreach ($delivery AS $deliv)
$deliveryArray[$deliv['id_zone']][$deliv['id_carrier']][$deliv[$rangeIdentifier]] = $deliv['price'];
if (!$carrierSelected->is_free)
foreach ($ranges AS $range)
echo '<th style="font-size: 11px;">'.(float)($range['delimiter1']).$suffix.' '.$this->l('to').' '.(float)($range['delimiter2']).$suffix.'</th>';
echo '</tr>';
$zones = $carrierSelected->getZones();
if (sizeof($ranges) && !$carrierSelected->is_free)
{
if(sizeof($zones) > 1)
{
echo '
<tr>
<th style="height: 30px;">'.$this->l('All').'</th>';
foreach ($ranges AS $range)
echo '<td class="center">'.$currency->getSign('left').'<input type="text" id="fees_all_'.$range[$rangeIdentifier].'" onchange="this.value = this.value.replace(/,/g, \'.\');" onkeyup="if ((event.keyCode||event.which) != 9){ spreadFees('.$range[$rangeIdentifier].') }" style="width: 45px;" />'.$currency->getSign('right').'</td>';
echo '</tr>';
}
foreach ($zones AS $zone)
{
echo '
<tr>
<th style="height: 30px;">'.$zone['name'].'</th>';
foreach ($ranges AS $range)
{
if (isset($deliveryArray[$zone['id_zone']][$id_carrier][$range[$rangeIdentifier]]))
$price = $deliveryArray[$zone['id_zone']][$id_carrier][$range[$rangeIdentifier]];
else
$price = '0.00';
echo '<td class="center">'.$currency->getSign('left').'<input type="text" class="fees_'.$range[$rangeIdentifier].'" onchange="this.value = this.value.replace(/,/g, \'.\');" name="fees_'.$zone['id_zone'].'_'.$range[$rangeIdentifier].'" onkeyup="clearAllFees('.$range[$rangeIdentifier].')" value="'.$price.'" style="width: 45px;" />'.$currency->getSign('right').'</td>';
}
echo '
</tr>';
}
}
echo '<tr>
<td colspan="'.(sizeof($ranges) + 1).'" class="center" style="border-bottom: none; height: 40px;">
<input type="hidden" name="submitFees'.$this->table.'" value="1" />';
if (sizeof($ranges) && !$carrierSelected->is_free)
echo ' <input type="submit" value="'.$this->l(' Save ').'" class="button" />';
else if($carrierSelected->is_free)
echo $this->l('This is a free carrier');
else
echo $this->l('No ranges set for this carrier');
echo '
</td>
</tr>';
echo '
</table>
<p>'.$this->l('Prices do not include tax.').'</p>';
}
echo '
</fieldset>
<input type="hidden" name="id_carrier" value="'.$id_carrier.'" />
</form>';
}
}
@@ -26,7 +26,11 @@
<script type="text/javascript">
id_language = Number({$current_id_lang});
</script>
<form action="{$current}&submitOptions{$table}=1&token={$token}" method="post" enctype="multipart/form-data">
<form action="{$current}&submitOptions{$table}=1&token={$token}"
{if isset($categoryData['name'])} name={$categoryData['name']}{/if}
{if isset($categoryData['id'])} id={$categoryData['id']} {/if}
method="post"
enctype="multipart/form-data">
{foreach $option_list AS $category => $categoryData}
{if isset($categoryData['top'])}{$categoryData['top']}{/if}
<fieldset {if isset($categoryData['class'])}class="{$categoryData['class']}"{/if}>
@@ -38,7 +42,7 @@
{* Category description *}
{if (isset($categoryData['description']) && $categoryData['description'])}
<p class="optionsDescription">{$categoryData['description']}</p>
<div class="optionsDescription">{$categoryData['description']}</div>
{/if}
{* Category info *}
{if (isset($categoryData['info']) && $categoryData['info'])}
@@ -62,11 +66,15 @@
<div class="margin-form">
{/block}
{if $field['type'] == 'select'}
<select name="{$key}"{if isset($field['js'])} onchange="{$field['js']}"{/if} id="{$key}">
{foreach $field['list'] AS $k => $option}
<option value="{$option[$field['identifier']]}"{if $field['value'] == $option[$field['identifier']]} selected="selected"{/if}>{$option['name']}</option>
{/foreach}
</select>
{if $field['list']}
<select name="{$key}"{if isset($field['js'])} onchange="{$field['js']}"{/if} id="{$key}">
{foreach $field['list'] AS $k => $option}
<option value="{$option[$field['identifier']]}"{if $field['value'] == $option[$field['identifier']]} selected="selected"{/if}>{$option['name']}</option>
{/foreach}
</select>
{else if isset($input.empty_message)}
{$input.empty_message}
{/if}
{elseif $field['type'] == 'bool'}
<label class="t" for="{$key}_on"><img src="../img/admin/enabled.gif" alt="{l s='Yes'}" title="{l s='Yes'}" /></label>
<input type="radio" name="{$key}" id="{$key}_on" value="1" {if $field['value']} checked="checked"{/if}{if isset($field['js']['on'])} {$field['js']['on']}{/if}/>
@@ -89,10 +97,10 @@
*}
{elseif $field['type'] == 'text'}
<input type="{$field['type']}"{if isset($field['id'])} id="{$field['id']}"{/if} size="{if isset($field['size'])}{$field['size']|intval}{else}5{/if}" name="{$key}" value="{$field['value']|escape:'htmlall':'UTF-8'}" />
{if isset($field['next'])}&nbsp;{$field['next']|strval}{/if}
{if isset($field['suffix'])}&nbsp;{$field['suffix']|strval}{/if}
{elseif $field['type'] == 'password'}
<input type="{$field['type']}"{if isset($field['id'])} id="{$field['id']}"{/if} size="{if isset($field['size'])}{$field['size']|intval}{else}5{/if}" name="{$key}" value="" />
{if isset($field['next'])}&nbsp;{$field['next']|strval}{/if}
{if isset($field['suffix'])}&nbsp;{$field['suffix']|strval}{/if}
{elseif $field['type'] == 'textarea'}
<textarea name={$key} cols="{$field['cols']}" rows="{$field['rows']}">{$field['value']|escape:'htmlall':'UTF-8'}</textarea>
{elseif $field['type'] == 'file'}
@@ -0,0 +1,107 @@
{*
* 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$
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
{$content}
<br /><br />
<h2>{l s='Fees by carrier, geographical zone, and ranges'}</h2>
<form action="{$action_fees}" id="fees" name="fees" method="post">
<fieldset>
<legend><img src="../img/admin/delivery.gif" />{l s='Fees'}</legend>
{if empty($carriers)}
{l s='You only have free carriers, there is no need to configure your delivery prices.'}
{else}
<b>{l s='Carrier:'} </b>
<select name="id_carrier2" onchange="$('#fees').attr('action', $('#fees').attr('action')+'&id_carrier='+$(this).attr('value')); $('#fees').submit();">
{foreach $carriers AS $carrier}
<option value="{$carrier['id_carrier']|intval}" {if $carrier['id_carrier'] == $id_carrier} selected="selected"{/if}>{$carrier['name']}</option>
{/foreach}
</select><br />
<table class="table space" cellpadding="0" cellspacing="0">
<tr>
<th>{l s='Zone / Range'}</th>
{if !$carrierSelected->is_free}
{foreach $ranges AS $range}
<th style="font-size: 11px;">{$range['delimiter1']|floatval}{$suffix} {l s='to'} {$range['delimiter2']|floatval}{$suffix}</th>
{/foreach}
{/if}
</tr>
{if sizeof($ranges) && !$carrierSelected->is_free}
{if sizeof($zones) > 1}
<tr>
<th style="height: 30px;">{l s='All'}</th>
{foreach $ranges AS $range}
<td class="center">
{$currency->getSign('left')}
<input type="text" id="fees_all_{$range[$rangeIdentifier]}" onchange="this.value = this.value.replace(/,/g, \'.\');" onkeyup="if ((event.keyCode||event.which) != 9){ spreadFees('.$range[$rangeIdentifier].') }" style="width: 45px;" />
{$currency->getSign('right')}
</td>
{/foreach}
</tr>
{/if}
{foreach $zones AS $zone}
<tr>
<th style="height: 30px;">{$zone['name']}</th>
{foreach $ranges AS $range}
{if isset($deliveryArray[$zone['id_zone']][$id_carrier][$range[$rangeIdentifier]])}
{$price = $deliveryArray[$zone['id_zone']][$id_carrier][$range[$rangeIdentifier]]}
{else}
{$price = '0.00'}
{/if}
<td class="center">
{$currency->getSign('left')}
<input
type="text"
class="fees_{$range[$rangeIdentifier]}"
onchange="this.value = this.value.replace(/,/g, \'.\');" name="fees_{$zone['id_zone']}_{$range[$rangeIdentifier]}" onkeyup="clearAllFees({$range[$rangeIdentifier]})"
value="{$price}"
style="width: 45px;"
/>
{$currency->getSign('right')}
</td>
{/foreach}
</tr>
{/foreach}
{/if}
<tr>
<td colspan="{$ranges|sizeof + 1}" class="center" style="border-bottom: none; height: 40px;">
<input type="hidden" name="submitFees{$table}" value="1" />
{if sizeof($ranges) && !$carrierSelected->is_free}
<input type="submit" value="{l s=' Save '}" class="button" />
{else if $carrierSelected->is_free}
{l s='This is a free carrier'}
{else}
{l s='No ranges set for this carrier'}
{/if}
</td>
</tr>
</table>
<p>{l s='Prices do not include tax.'}</p>
{/if}
<input type="hidden" name="id_carrier" value="{$id_carrier}" />
</fieldset>
</form>
+3 -3
View File
@@ -37,7 +37,7 @@
{* Category description *}
{if (isset($categoryData['description']) && $categoryData['description'])}
<p class="optionsDescription">{$categoryData['description']}</p>
<div class="optionsDescription">{$categoryData['description']}</div>
{/if}
{foreach $categoryData['fields'] AS $key => $field}
@@ -79,10 +79,10 @@
*}
{elseif $field['type'] == 'text'}
<input type="{$field['type']}"{if isset($field['id'])} id="{$field['id']}"{/if} size="{if isset($field['size'])}{$field['size']|intval}{else}5{/if}" name="{$key}" value="{$field['value']|escape:'htmlall':'UTF-8'}" />
{if isset($field['next'])}&nbsp;{$field['next']|strval}{/if}
{if isset($field['suffix'])}&nbsp;{$field['suffix']|strval}{/if}
{elseif $field['type'] == 'password'}
<input type="{$field['type']}"{if isset($field['id'])} id="{$field['id']}"{/if} size="{if isset($field['size'])}{$field['size']|intval}{else}5{/if}" name="{$key}" value="" />
{if isset($field['next'])}&nbsp;{$field['next']|strval}{/if}
{if isset($field['suffix'])}&nbsp;{$field['suffix']|strval}{/if}
{elseif $field['type'] == 'textarea'}
<textarea name={$key} cols="{$field['cols']}" rows="{$field['rows']}">{$field['value']|escape:'htmlall':'UTF-8'}</textarea>
{elseif $field['type'] == 'file'}
+3 -2
View File
@@ -244,6 +244,8 @@ class AdminControllerCore extends Controller
// Get the name of the folder containing the custom tpl files
$this->tpl_folder = strtolower($controller[5]).substr($controller, 6);
$this->tpl_folder = Tools::toUnderscoreCase($this->tpl_folder).'/';
$this->context->currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
}
/**
@@ -726,7 +728,7 @@ class AdminControllerCore extends Controller
break;
default: // list
$this->toolbar_btn['new'] = array(
'href' => self::$currentIndex.'&amp;add'.$this->table.'&amp;token='.$this->token,
'href' => self::$currentIndex.'&amp;add'.$this->table.'&amp;token='.$this->token,
'desc' => $this->l('Add new')
);
}
@@ -1329,7 +1331,6 @@ class AdminControllerCore extends Controller
$this->display_footer = false;
$this->content_only = true;
}
$this->context->currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
// Change shop context ?
if (Shop::isFeatureActive() && Tools::getValue('setShopContext') !== false)
@@ -0,0 +1,201 @@
<?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: 6844 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminShippingControllerCore extends AdminController
{
private $_fieldsHandling;
public function __construct()
{
parent::__construct();
$this->table = 'delivery';
$carriers = Carrier::getCarriers($this->context->language->id, true , false, false, NULL, Carrier::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
foreach ($carriers AS $key => $carrier)
if ($carrier['is_free'])
unset($carriers[$key]);
$this->options = array(
'handling' => array(
'title' => $this->l('Handling'),
'icon' => 'delivery',
'fields' => array(
'PS_SHIPPING_HANDLING' => array(
'title' => $this->l('Handling charges'),
'suffix' => $this->context->currency->getSign().' '.$this->l('(tax excl.)'),
'cast' => 'floatval',
'type' => 'text',
'validation' => 'isPrice'),
'PS_SHIPPING_FREE_PRICE' => array(
'title' => $this->l('Free shipping starts at'),
'suffix' => $this->context->currency->getSign(),
'cast' => 'floatval',
'type' => 'text',
'validation' => 'isPrice'),
'PS_SHIPPING_FREE_WEIGHT' => array(
'title' => $this->l('Free shipping starts at'),
'suffix' => Configuration::get('PS_WEIGHT_UNIT'),
'cast' => 'floatval',
'type' => 'text',
'validation' => 'isUnsignedFloat'),
),
'description' =>
'<ul style="font-size: 11px; color:#7F7F7F; line-height: 20px;">
<li style="list-style-type: disc;">'.$this->l('If you set these parameters to 0, they will be disabled').'</li>
<li style="list-style-type: disc;">'.$this->l('Coupons are not taken into account when calculating free shipping').'</li>
</ul>',
'submit' => array()
),
'billing' => array(
'title' => $this->l('Billing'),
'icon' => 'money',
'fields' => array(
'PS_SHIPPING_METHOD' => array(
'title' => $this->l('Billing'),
'cast' => 'intval',
'type' => 'radio',
'choices' => array(
0 => $this->l('According to total price'),
1 => $this->l('According to total weight')
),
'validation' => 'isBool'
),
),
'submit' => array()
),
);
}
public function initContent()
{
$carriers = Carrier::getCarriers($this->context->language->id, true , false, false, NULL, Carrier::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
foreach ($carriers AS $key => $carrier)
if ($carrier['is_free'])
unset($carriers[$key]);
$id_carrier = Tools::getValue('id_carrier');
if (count($carriers))
{
if (!$id_carrier)
$id_carrier = (int)$carriers[0]['id_carrier'];
$carrierSelected = new Carrier($id_carrier);
}
$currency = $this->context->currency;
$rangeObj = $carrierSelected->getRangeObject();
$rangeTable = $carrierSelected->getRangeTable();
$suffix = $carrierSelected->getRangeSuffix();
$rangeIdentifier = 'id_'.$rangeTable;
$ranges = $rangeObj->getRanges($id_carrier);
$delivery = Carrier::getDeliveryPriceByRanges($rangeTable, $id_carrier);
$deliveryArray = array();
foreach ($delivery AS $deliv)
$deliveryArray[$deliv['id_zone']][$deliv['id_carrier']][$deliv[$rangeIdentifier]] = $deliv['price'];
$this->context->smarty->assign(array(
'zones' => $carrierSelected->getZones(),
'carriers' => $carriers,
'ranges' => $ranges,
'currency' => $currency,
'deliveryArray' => $deliveryArray,
'carrierSelected' => $carrierSelected,
'id_carrier' => $id_carrier,
'suffix' => $suffix,
'rangeIdentifier' => $rangeIdentifier,
'action_fees' => self::$currentIndex.'&token='.$this->token
));
parent::initContent();
}
public function postProcess()
{
/* Shipping fees */
if (Tools::isSubmit('submitFees'.$this->table))
{
if ($this->tabAccess['edit'] === '1')
{
if (($id_carrier = (int)(Tools::getValue('id_carrier'))) AND $id_carrier == ($id_carrier2 = (int)(Tools::getValue('id_carrier2'))))
{
$carrier = new Carrier($id_carrier);
if (Validate::isLoadedObject($carrier))
{
/* Get configuration values */
$shipping_method = $carrier->getShippingMethod();
$rangeTable = $carrier->getRangeTable();
$carrier->deleteDeliveryPrice($rangeTable);
$currentList = Carrier::getDeliveryPriceByRanges($rangeTable, $id_carrier);
/* Build prices list */
$priceList = array();
foreach ($_POST AS $key => $value)
if (strstr($key, 'fees_'))
{
$tmpArray = explode('_', $key);
$price = number_format(abs(str_replace(',', '.', $value)), 6, '.', '');
$current = 0;
foreach ($currentList as $item)
if ($item['id_zone'] == $tmpArray[1] && $item['id_'.$rangeTable] == $tmpArray[2])
$current = $item;
if ($current && $price == $current['price'])
continue;
$priceList[] = array(
'id_range_price' => ($shipping_method == Carrier::SHIPPING_METHOD_PRICE) ? (int)$tmpArray[2] : null,
'id_range_weight' => ($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT) ? (int)$tmpArray[2] : null,
'id_carrier' => (int)$carrier->id,
'id_zone' => (int)$tmpArray[1],
'price' => $price,
);
}
/* Update delivery prices */
$carrier->addDeliveryPrice($priceList);
Tools::redirectAdmin(self::$currentIndex.'&conf=6&id_carrier='.$carrier->id.'&token='.$this->token);
}
else
$this->_errors[] = Tools::displayError('An error occurred while updating fees (cannot load carrier object).');
}
elseif (isset($id_carrier2))
{
$_POST['id_carrier'] = $id_carrier2;
}
else
$this->_errors[] = Tools::displayError('An error occurred while updating fees (cannot load carrier object).');
}
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
else
parent::postProcess();
}
}