[*] BO : #PSFV-94 - added AdminTaxesController + HelperList improvements
This commit is contained in:
1 parent
5647b43be3
commit
22b223f304
6 files changed
+265
-227
No files matched your search
@@ -1,205 +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: 7060 $
|
|
||||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
|
||||||
* International Registered Trademark & Property of PrestaShop SA
|
|
||||||
*/
|
|
||||||
|
|
||||||
class AdminTaxes extends AdminTab
|
|
||||||
{
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->table = 'tax';
|
|
||||||
$this->className = 'Tax';
|
|
||||||
$this->lang = true;
|
|
||||||
$this->edit = true;
|
|
||||||
$this->delete = true;
|
|
||||||
|
|
||||||
$this->fieldsDisplay = array(
|
|
||||||
'id_tax' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
|
|
||||||
'name' => array('title' => $this->l('Name'), 'width' => 140),
|
|
||||||
'rate' => array('title' => $this->l('Rate'), 'align' => 'center', 'suffix' => '%', 'width' => 50),
|
|
||||||
'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false));
|
|
||||||
|
|
||||||
$ecotax_desc = '';
|
|
||||||
if (Configuration::get('PS_USE_ECOTAX'))
|
|
||||||
$ecotax_desc = $this->l('If you disable the ecotax, the ecotax for all your products will be set to 0');
|
|
||||||
|
|
||||||
$this->optionsList = array(
|
|
||||||
'general' => array(
|
|
||||||
'title' => $this->l('Tax options'),
|
|
||||||
'fields' => array(
|
|
||||||
'PS_TAX' => array('title' => $this->l('Enable tax:'), 'desc' => $this->l('Select whether or not to include tax on purchases'), 'cast' => 'intval', 'type' => 'bool'),
|
|
||||||
'PS_TAX_DISPLAY' => array('title' => $this->l('Display tax in cart:'), 'desc' => $this->l('Select whether or not to display tax on a distinct line in the cart'), 'cast' => 'intval', 'type' => 'bool'),
|
|
||||||
'PS_TAX_ADDRESS_TYPE' => array('title' => $this->l('Base on:'), 'cast' => 'pSQL', 'type' => 'select', 'list' => array(array('name' => $this->l('Invoice Address'), 'id' => 'id_address_invoice'), array('name' => $this->l('Delivery Address'), 'id' => 'id_address_delivery')), 'identifier' => 'id'),
|
|
||||||
'PS_USE_ECOTAX' => array('title' => $this->l('Use ecotax'), 'desc' => $ecotax_desc, 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (Configuration::get('PS_USE_ECOTAX'))
|
|
||||||
$this->optionsList['general']['fields']['PS_ECOTAX_TAX_RULES_GROUP_ID'] = array('title' => $this->l('Ecotax:'), 'desc' => $this->l('The tax to apply on the ecotax (e.g., French ecotax: 19.6%).'),
|
|
||||||
'cast' => 'intval', 'type' => 'select', 'identifier' => 'id_tax', 'identifier' => 'id_tax_rules_group', 'list' => TaxRulesGroup::getTaxRulesGroupsForOptions());
|
|
||||||
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function displayForm($isMainTab = true)
|
|
||||||
{
|
|
||||||
parent::displayForm();
|
|
||||||
|
|
||||||
if (!($obj = $this->loadObject(true)))
|
|
||||||
return;
|
|
||||||
$zones = Zone::getZones(true);
|
|
||||||
$states = State::getStates($this->context->language->id);
|
|
||||||
|
|
||||||
echo '
|
|
||||||
<form action="'.self::$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'" method="post">
|
|
||||||
'.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
|
|
||||||
<fieldset><legend><img src="../img/admin/dollar.gif" />'.$this->l('Taxes').'</legend>
|
|
||||||
<label>'.$this->l('Name:').' </label>
|
|
||||||
<div class="margin-form">';
|
|
||||||
foreach ($this->_languages as $language)
|
|
||||||
echo '
|
|
||||||
<div id="name_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
|
|
||||||
<input size="33" type="text" name="name_'.$language['id_lang'].'" value="'.htmlentities($this->getFieldValue($obj, 'name', (int)($language['id_lang'])), ENT_COMPAT, 'UTF-8').'" /><sup> *</sup>
|
|
||||||
<span class="hint" name="help_box">'.$this->l('Invalid characters:').' <>;=#{}<span class="hint-pointer"> </span></span>
|
|
||||||
</div>';
|
|
||||||
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'name', 'name');
|
|
||||||
echo ' <p class="clear">'.$this->l('Tax name to display in cart and on invoice, e.g., VAT').'</p>
|
|
||||||
</div>
|
|
||||||
<label>'.$this->l('Rate:').' </label>
|
|
||||||
<div class="margin-form">
|
|
||||||
<input type="text" size="4" maxlength="6" name="rate" value="'.htmlentities($this->getFieldValue($obj, 'rate'), ENT_COMPAT, 'UTF-8').'" /> <sup>*</sup>
|
|
||||||
<p class="clear">'.$this->l('Format: XX.XX or XX.XXX (e.g., 19.60 or 13.925)').'</p>
|
|
||||||
</div>
|
|
||||||
<label>'.$this->l('Enable:').' </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>
|
|
||||||
</div>
|
|
||||||
<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 postProcess()
|
|
||||||
{
|
|
||||||
if (Tools::getValue('submitAdd'.$this->table))
|
|
||||||
{
|
|
||||||
/* Checking fields validity */
|
|
||||||
$this->validateRules();
|
|
||||||
if (!sizeof($this->_errors))
|
|
||||||
{
|
|
||||||
$id = (int)(Tools::getValue('id_'.$this->table));
|
|
||||||
|
|
||||||
/* Object update */
|
|
||||||
if (isset($id) AND !empty($id))
|
|
||||||
{
|
|
||||||
if ($this->tabAccess['edit'] === '1')
|
|
||||||
{
|
|
||||||
$object = new $this->className($id);
|
|
||||||
if (Validate::isLoadedObject($object))
|
|
||||||
{
|
|
||||||
$this->copyFromPost($object, $this->table);
|
|
||||||
$result = $object->update(false, false);
|
|
||||||
|
|
||||||
if (!$result)
|
|
||||||
$this->_errors[] = Tools::displayError('An error occurred while updating object.').' <b>'.$this->table.'</b>';
|
|
||||||
elseif ($this->postImage($object->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);
|
|
||||||
if (!$object->add())
|
|
||||||
$this->_errors[] = Tools::displayError('An error occurred while creating object.').' <b>'.$this->table.'</b>';
|
|
||||||
elseif (($_POST['id_'.$this->table] = $object->id /* voluntary */) AND $this->postImage($object->id) AND $this->_redirect)
|
|
||||||
{
|
|
||||||
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
|
|
||||||
parent::postProcess();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function _displayDeleteLink($token = NULL, $id)
|
|
||||||
{
|
|
||||||
$_cacheLang['Delete'] = $this->l('Delete', __CLASS__, TRUE, FALSE);
|
|
||||||
|
|
||||||
$_cacheLang['DeleteItem'] = $this->l('Delete item #', __CLASS__, TRUE, FALSE).$id.' ?)';
|
|
||||||
if (TaxRule::isTaxInUse($id))
|
|
||||||
$_cacheLang['DeleteItem'] = $this->l('This tax is currently in use in a tax rule. Are you sure?');
|
|
||||||
|
|
||||||
echo '
|
|
||||||
<a href="'.self::$currentIndex.'&'.$this->identifier.'='.$id.'&delete'.$this->table.'&token='.($token!=NULL ? $token : $this->token).'" onclick="return confirm(\''.$_cacheLang['DeleteItem'].'\');">
|
|
||||||
<img src="../img/admin/delete.gif" alt="'.$_cacheLang['Delete'].'" title="'.$_cacheLang['Delete'].'" /></a>';
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function _displayEnableLink($token, $id, $value, $active, $id_category = NULL, $id_product = NULL)
|
|
||||||
{
|
|
||||||
$confirm = ($value AND TaxRule::isTaxInUse($id)) ? 'onclick="return confirm(\''. $this->l('This tax is currently in use in a tax rule. If you continue this tax will be removed from the tax rule, are you sure?').'\')"' : '';
|
|
||||||
|
|
||||||
echo '<a href="'.self::$currentIndex.'&'.$this->identifier.'='.$id.'&'.$active.
|
|
||||||
((int)$id_category AND (int)$id_product ? '&id_category='.$id_category : '').'&token='.($token!=NULL ? $token : $this->token).'" '.$confirm.'>
|
|
||||||
<img src="../img/admin/'.($value ? 'enabled.gif' : 'disabled.gif').'"
|
|
||||||
alt="'.($value ? $this->l('Enabled') : $this->l('Disabled')).'" title="'.($value ? $this->l('Enabled') : $this->l('Disabled')).'" /></a>';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updateOptionPsUseEcotax($value)
|
|
||||||
{
|
|
||||||
$old_value = (int)Configuration::get('PS_USE_ECOTAX');
|
|
||||||
|
|
||||||
if ($old_value != $value)
|
|
||||||
{
|
|
||||||
// Reset ecotax
|
|
||||||
if ($value == 0)
|
|
||||||
Product::resetEcoTax();
|
|
||||||
|
|
||||||
Configuration::updateValue('PS_USE_ECOTAX', (int)$value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*}
|
*}
|
||||||
|
|
||||||
{extends file="../options.tpl"}
|
{extends file="helper/options/options.tpl"}
|
||||||
{block name="start_field_block"}
|
{block name="start_field_block"}
|
||||||
{if $field['type'] == 'checkbox_table'}
|
{if $field['type'] == 'checkbox_table'}
|
||||||
<div class="margin-form" style="float: left; padding-left: 0; width: 317px; margin-top: 6px; height: 300px; overflow-y: auto;">
|
<div class="margin-form" style="float: left; padding-left: 0; width: 317px; margin-top: 6px; height: 300px; overflow-y: auto;">
|
||||||
|
|||||||
@@ -30,19 +30,11 @@
|
|||||||
{if $index is odd}class="alt_row"{/if}
|
{if $index is odd}class="alt_row"{/if}
|
||||||
{if isset($tr.color) && $color_on_bg}style="background-color: {$tr.color}"{/if}
|
{if isset($tr.color) && $color_on_bg}style="background-color: {$tr.color}"{/if}
|
||||||
>
|
>
|
||||||
<td class="center">
|
{if isset($tr.has_bulk_actions) && $tr.has_bulk_actions}
|
||||||
{if $bulk_actions}
|
<td class="center">
|
||||||
{assign var=bulkActionPossible value=true}
|
<input type="checkbox" name="{$table}Box[]" value="{$tr.$identifier}" class="noborder" />
|
||||||
{foreach $list_skip_actions as $key => $value}
|
</td>
|
||||||
{if in_array($tr.$identifier, $value) == true}
|
{/if}
|
||||||
{assign var=bulkActionPossible value=false}
|
|
||||||
{/if}
|
|
||||||
{/foreach}
|
|
||||||
{if $bulkActionPossible == true}
|
|
||||||
<input type="checkbox" name="{$table}Box[]" value="{$tr.$identifier}" class="noborder" />
|
|
||||||
{/if}
|
|
||||||
{/if}
|
|
||||||
</td>
|
|
||||||
{foreach $fields_display AS $key => $params}
|
{foreach $fields_display AS $key => $params}
|
||||||
<td
|
<td
|
||||||
{if isset($params.position)}
|
{if isset($params.position)}
|
||||||
|
|||||||
@@ -106,7 +106,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr class="nodrag nodrop">
|
<tr class="nodrag nodrop">
|
||||||
<th style="width:10px;">
|
<th style="width:10px;">
|
||||||
{if $delete}
|
{if $has_bulk_actions}
|
||||||
<input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, '{$table}Box[]', this.checked)" />
|
<input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, '{$table}Box[]', this.checked)" />
|
||||||
{/if}
|
{/if}
|
||||||
</th>
|
</th>
|
||||||
|
|||||||
+21
-7
@@ -159,18 +159,19 @@ class HelperListCore extends Helper
|
|||||||
* @param string $token
|
* @param string $token
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @param int $value state enabled or not
|
* @param int $value state enabled or not
|
||||||
* @param unknown_type $active
|
* @param string $active status
|
||||||
* @param unknown_type $id_category
|
* @param int $id_category
|
||||||
* @param unknown_type $id_product
|
* @param int $id_product
|
||||||
*/
|
*/
|
||||||
protected function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null)
|
protected function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null)
|
||||||
{
|
{
|
||||||
$this->context->smarty->assign(array(
|
$tpl_enable = $this->context->smarty->createTemplate('helper/list/list_action_enable.tpl');
|
||||||
|
$tpl_enable->assign(array(
|
||||||
'enabled' => (bool)$value,
|
'enabled' => (bool)$value,
|
||||||
'url_enable' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&'.$active.$this->table.
|
'url_enable' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&'.$active.$this->table.
|
||||||
((int)$id_category && (int)$id_product ? '&id_category='.$id_category : '').'&token='.($token != null ? $token : $this->token)
|
((int)$id_category && (int)$id_product ? '&id_category='.$id_category : '').'&token='.($token != null ? $token : $this->token)
|
||||||
));
|
));
|
||||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/helper/list/list_action_enable.tpl');
|
return $tpl_enable->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function displayListContent($token = null)
|
public function displayListContent($token = null)
|
||||||
@@ -213,16 +214,26 @@ class HelperListCore extends Helper
|
|||||||
$this->_list[$index][$action] = $this->context->controller->$method_name($token, $id);
|
$this->_list[$index][$action] = $this->context->controller->$method_name($token, $id);
|
||||||
else if (method_exists($this, $method_name))
|
else if (method_exists($this, $method_name))
|
||||||
$this->_list[$index][$action] = $this->$method_name($token, $id);
|
$this->_list[$index][$action] = $this->$method_name($token, $id);
|
||||||
|
|
||||||
|
// At least one bulk action is possible for this row
|
||||||
|
$this->_list[$index]['has_bulk_actions'] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach ($this->fieldsDisplay as $key => $params)
|
foreach ($this->fieldsDisplay as $key => $params)
|
||||||
{
|
{
|
||||||
$tmp = explode('!', $key);
|
$tmp = explode('!', $key);
|
||||||
$key = isset($tmp[1]) ? $tmp[1] : $tmp[0];
|
$key = isset($tmp[1]) ? $tmp[1] : $tmp[0];
|
||||||
|
|
||||||
if (isset($params['active']))
|
if (isset($params['active']))
|
||||||
$this->_list[$index][$key] = $this->displayEnableLink(
|
{
|
||||||
|
// If method is defined in calling controller, use it instead of the Helper method
|
||||||
|
if (method_exists($this->context->controller, 'displayEnableLink'))
|
||||||
|
$calling_obj = $this->context->controller;
|
||||||
|
else
|
||||||
|
$calling_obj = $this;
|
||||||
|
$this->_list[$index][$key] = $calling_obj->displayEnableLink(
|
||||||
$this->token,
|
$this->token,
|
||||||
$id,
|
$id,
|
||||||
$tr[$key],
|
$tr[$key],
|
||||||
@@ -230,6 +241,7 @@ class HelperListCore extends Helper
|
|||||||
Tools::getValue('id_category'),
|
Tools::getValue('id_category'),
|
||||||
Tools::getValue('id_product')
|
Tools::getValue('id_product')
|
||||||
);
|
);
|
||||||
|
}
|
||||||
else if (isset($params['activeVisu']))
|
else if (isset($params['activeVisu']))
|
||||||
$this->_list[$index][$key] = (bool)$tr[$key];
|
$this->_list[$index][$key] = (bool)$tr[$key];
|
||||||
else if (isset($params['position']))
|
else if (isset($params['position']))
|
||||||
@@ -309,6 +321,7 @@ class HelperListCore extends Helper
|
|||||||
'view' => in_array('view', $this->actions),
|
'view' => in_array('view', $this->actions),
|
||||||
'edit' => in_array('edit', $this->actions),
|
'edit' => in_array('edit', $this->actions),
|
||||||
'has_actions' => (bool)count($this->actions),
|
'has_actions' => (bool)count($this->actions),
|
||||||
|
'has_bulk_actions' => (bool)count($this->bulk_actions),
|
||||||
'list_skip_actions' => $this->list_skip_actions,
|
'list_skip_actions' => $this->list_skip_actions,
|
||||||
));
|
));
|
||||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/'.$this->content_tpl);
|
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/'.$this->content_tpl);
|
||||||
@@ -550,7 +563,8 @@ class HelperListCore extends Helper
|
|||||||
'identifier' => $this->identifier,
|
'identifier' => $this->identifier,
|
||||||
'id_cat' => $id_cat,
|
'id_cat' => $id_cat,
|
||||||
'shop_link_type' => $this->shopLinkType,
|
'shop_link_type' => $this->shopLinkType,
|
||||||
'has_actions' => (boolean)count($this->actions),
|
'has_actions' => (bool)count($this->actions),
|
||||||
|
'has_bulk_actions' => (bool)count($this->bulk_actions),
|
||||||
'toolbar_btn' => $this->toolbar_btn,
|
'toolbar_btn' => $this->toolbar_btn,
|
||||||
'table_id' => isset($table_id) ? $table_id : null,
|
'table_id' => isset($table_id) ? $table_id : null,
|
||||||
'table_dnd' => isset($table_dnd) ? $table_dnd : null,
|
'table_dnd' => isset($table_dnd) ? $table_dnd : null,
|
||||||
|
|||||||
@@ -0,0 +1,237 @@
|
|||||||
|
<?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: 7060 $
|
||||||
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||||
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
|
*/
|
||||||
|
|
||||||
|
class AdminTaxesControllerCore extends AdminController
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->table = 'tax';
|
||||||
|
$this->className = 'Tax';
|
||||||
|
$this->lang = true;
|
||||||
|
$this->addRowAction('edit');
|
||||||
|
$this->addRowAction('delete');
|
||||||
|
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
|
||||||
|
|
||||||
|
$this->fieldsDisplay = array(
|
||||||
|
'id_tax' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
|
||||||
|
'name' => array('title' => $this->l('Name'), 'width' => 140),
|
||||||
|
'rate' => array('title' => $this->l('Rate'), 'align' => 'center', 'suffix' => '%', 'width' => 50),
|
||||||
|
'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false));
|
||||||
|
|
||||||
|
$ecotax_desc = '';
|
||||||
|
if (Configuration::get('PS_USE_ECOTAX'))
|
||||||
|
$ecotax_desc = $this->l('If you disable the ecotax, the ecotax for all your products will be set to 0');
|
||||||
|
|
||||||
|
$this->options = array(
|
||||||
|
'general' => array(
|
||||||
|
'title' => $this->l('Tax options'),
|
||||||
|
'fields' => array(
|
||||||
|
'PS_TAX' => array('title' => $this->l('Enable tax:'), 'desc' => $this->l('Select whether or not to include tax on purchases'), 'cast' => 'intval', 'type' => 'bool'),
|
||||||
|
'PS_TAX_DISPLAY' => array('title' => $this->l('Display tax in cart:'), 'desc' => $this->l('Select whether or not to display tax on a distinct line in the cart'), 'cast' => 'intval', 'type' => 'bool'),
|
||||||
|
'PS_TAX_ADDRESS_TYPE' => array('title' => $this->l('Base on:'), 'cast' => 'pSQL', 'type' => 'select', 'list' => array(array('name' => $this->l('Invoice Address'), 'id' => 'id_address_invoice'), array('name' => $this->l('Delivery Address'), 'id' => 'id_address_delivery')), 'identifier' => 'id'),
|
||||||
|
'PS_USE_ECOTAX' => array('title' => $this->l('Use ecotax'), 'desc' => $ecotax_desc, 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'),
|
||||||
|
),
|
||||||
|
'submit' => array()
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (Configuration::get('PS_USE_ECOTAX'))
|
||||||
|
$this->optionsList['general']['fields']['PS_ECOTAX_TAX_RULES_GROUP_ID'] = array('title' => $this->l('Ecotax:'), 'desc' => $this->l('The tax to apply on the ecotax (e.g., French ecotax: 19.6%).'),
|
||||||
|
'cast' => 'intval', 'type' => 'select', 'identifier' => 'id_tax', 'identifier' => 'id_tax_rules_group', 'list' => TaxRulesGroup::getTaxRulesGroupsForOptions());
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display delete action link
|
||||||
|
*/
|
||||||
|
public function displayDeleteLink($token = null, $id)
|
||||||
|
{
|
||||||
|
if (!array_key_exists('Delete', self::$cache_lang))
|
||||||
|
self::$cache_lang['Delete'] = $this->l('Delete');
|
||||||
|
|
||||||
|
if (!array_key_exists('DeleteItem', self::$cache_lang))
|
||||||
|
self::$cache_lang['DeleteItem'] = $this->l('Delete item #', __CLASS__, true, false);
|
||||||
|
|
||||||
|
if (TaxRule::isTaxInUse($id))
|
||||||
|
$confirm = $this->l('This tax is currently in use in a tax rule. Are you sure?');
|
||||||
|
|
||||||
|
$this->context->smarty->assign(array(
|
||||||
|
'href' => self::$currentIndex.'&'.$this->identifier.'='.$id.'&delete'.$this->table.'&token='.($token != null ? $token : $this->token),
|
||||||
|
'confirm' => (isset($confirm) ? '\r'.$confirm : self::$cache_lang['DeleteItem'].$id.' ? '),
|
||||||
|
'action' => self::$cache_lang['Delete'],
|
||||||
|
));
|
||||||
|
|
||||||
|
return $this->context->smarty->fetch('helper/list/list_action_delete.tpl');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch the template for action enable
|
||||||
|
*
|
||||||
|
* @param string $token
|
||||||
|
* @param int $id
|
||||||
|
* @param int $value state enabled or not
|
||||||
|
* @param string $active status
|
||||||
|
* @param int $id_category
|
||||||
|
* @param int $id_product
|
||||||
|
*/
|
||||||
|
public function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null)
|
||||||
|
{
|
||||||
|
if ($value AND TaxRule::isTaxInUse($id))
|
||||||
|
$confirm = $this->l('This tax is currently in use in a tax rule. If you continue this tax will be removed from the tax rule, are you sure?');
|
||||||
|
|
||||||
|
$tpl_enable = $this->context->smarty->createTemplate('helper/list/list_action_enable.tpl');
|
||||||
|
$tpl_enable->assign(array(
|
||||||
|
'enabled' => (bool)$value,
|
||||||
|
'url_enable' => self::$currentIndex.'&'.$this->identifier.'='.$id.'&'.$active.$this->table.
|
||||||
|
((int)$id_category && (int)$id_product ? '&id_category='.$id_category : '').'&token='.($token != null ? $token : $this->token),
|
||||||
|
'confirm' => isset($confirm) ? $confirm : null,
|
||||||
|
));
|
||||||
|
|
||||||
|
return $tpl_enable->fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initForm()
|
||||||
|
{
|
||||||
|
$this->fields_form = array(
|
||||||
|
'legend' => array(
|
||||||
|
'title' => $this->l('Taxes'),
|
||||||
|
'image' => '../img/admin/dollar.gif'
|
||||||
|
),
|
||||||
|
'input' => array(
|
||||||
|
array(
|
||||||
|
'type' => 'text',
|
||||||
|
'label' => $this->l('Name:'),
|
||||||
|
'name' => 'name',
|
||||||
|
'size' => 33,
|
||||||
|
'required' => true,
|
||||||
|
'lang' => true,
|
||||||
|
'hint' => $this->l('Invalid characters:').' <>;=#{}',
|
||||||
|
'p' => $this->l('Tax name to display in cart and on invoice, e.g., VAT')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'type' => 'text',
|
||||||
|
'label' => $this->l('Rate:'),
|
||||||
|
'name' => 'rate',
|
||||||
|
'size' => 4,
|
||||||
|
'maxlength' => 6,
|
||||||
|
'required' => true,
|
||||||
|
'hint' => $this->l('Invalid characters:').' <>;=#{}',
|
||||||
|
'p' => $this->l('Format: XX.XX or XX.XXX (e.g., 19.60 or 13.925)')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'type' => 'radio',
|
||||||
|
'label' => $this->l('Enable:'),
|
||||||
|
'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')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
'submit' => array(
|
||||||
|
'title' => $this->l(' Save '),
|
||||||
|
'class' => 'button'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return parent::initForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postProcess()
|
||||||
|
{
|
||||||
|
if ($this->action == 'save')
|
||||||
|
{
|
||||||
|
/* Checking fields validity */
|
||||||
|
$this->validateRules();
|
||||||
|
if (!sizeof($this->_errors))
|
||||||
|
{
|
||||||
|
$id = (int)(Tools::getValue('id_'.$this->table));
|
||||||
|
|
||||||
|
/* Object update */
|
||||||
|
if (isset($id) AND !empty($id))
|
||||||
|
{
|
||||||
|
$object = new $this->className($id);
|
||||||
|
if (Validate::isLoadedObject($object))
|
||||||
|
{
|
||||||
|
$this->copyFromPost($object, $this->table);
|
||||||
|
$result = $object->update(false, false);
|
||||||
|
|
||||||
|
if (!$result)
|
||||||
|
$this->_errors[] = Tools::displayError('An error occurred while updating object.').' <b>'.$this->table.'</b>';
|
||||||
|
elseif ($this->postImage($object->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)');
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Object creation */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$object = new $this->className();
|
||||||
|
$this->copyFromPost($object, $this->table);
|
||||||
|
if (!$object->add())
|
||||||
|
$this->_errors[] = Tools::displayError('An error occurred while creating object.').' <b>'.$this->table.'</b>';
|
||||||
|
elseif (($_POST['id_'.$this->table] = $object->id /* voluntary */) AND $this->postImage($object->id) AND $this->_redirect)
|
||||||
|
{
|
||||||
|
Tools::redirectAdmin(self::$currentIndex.'&id_'.$this->table.'='.$object->id.'&conf=3'.'&token='.$this->token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
parent::postProcess();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateOptionPsUseEcotax($value)
|
||||||
|
{
|
||||||
|
$old_value = (int)Configuration::get('PS_USE_ECOTAX');
|
||||||
|
|
||||||
|
if ($old_value != $value)
|
||||||
|
{
|
||||||
|
// Reset ecotax
|
||||||
|
if ($value == 0)
|
||||||
|
Product::resetEcoTax();
|
||||||
|
|
||||||
|
Configuration::updateValue('PS_USE_ECOTAX', (int)$value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user