// code review AdminTaxRulesGroup
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@12587 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -86,12 +86,12 @@ class TaxRuleCore extends ObjectModel
|
|||||||
SELECT g.`id_tax_rule`,
|
SELECT g.`id_tax_rule`,
|
||||||
c.`name` AS country_name,
|
c.`name` AS country_name,
|
||||||
s.`name` AS state_name,
|
s.`name` AS state_name,
|
||||||
t.rate,
|
t.`rate`,
|
||||||
g.`zipcode_from`, g.`zipcode_to`,
|
g.`zipcode_from`, g.`zipcode_to`,
|
||||||
g.`description`,
|
g.`description`,
|
||||||
g.`behavior`
|
g.`behavior`
|
||||||
FROM `'._DB_PREFIX_.'tax_rule` g
|
FROM `'._DB_PREFIX_.'tax_rule` g
|
||||||
LEFT JOIN `'._DB_PREFIX_.'country_lang` c ON (g.`id_country` = c.`id_country` AND id_lang = '.(int)$id_lang.')
|
LEFT JOIN `'._DB_PREFIX_.'country_lang` c ON (g.`id_country` = c.`id_country` AND `id_lang` = '.(int)$id_lang.')
|
||||||
LEFT JOIN `'._DB_PREFIX_.'state` s ON (g.`id_state` = s.`id_state`)
|
LEFT JOIN `'._DB_PREFIX_.'state` s ON (g.`id_state` = s.`id_state`)
|
||||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (g.`id_tax` = t.`id_tax`)
|
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (g.`id_tax` = t.`id_tax`)
|
||||||
WHERE `id_tax_rules_group` = '.(int)$id_group.'
|
WHERE `id_tax_rules_group` = '.(int)$id_group.'
|
||||||
@@ -137,6 +137,8 @@ class TaxRuleCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
$zip_codes = preg_split('/-/', $zip_codes);
|
$zip_codes = preg_split('/-/', $zip_codes);
|
||||||
|
|
||||||
|
$from = $zip_codes[0];
|
||||||
|
$to = isset($zip_codes[1]) ? $zip_codes[1]: 0;
|
||||||
if (count($zip_codes) == 2)
|
if (count($zip_codes) == 2)
|
||||||
{
|
{
|
||||||
$from = $zip_codes[0];
|
$from = $zip_codes[0];
|
||||||
|
|||||||
@@ -27,10 +27,10 @@
|
|||||||
|
|
||||||
class AdminTaxRulesGroupControllerCore extends AdminController
|
class AdminTaxRulesGroupControllerCore extends AdminController
|
||||||
{
|
{
|
||||||
public $tax_rule;
|
public $tax_rule;
|
||||||
public $selected_countries = array();
|
public $selected_countries = array();
|
||||||
public $selected_states = array();
|
public $selected_states = array();
|
||||||
public $_errors_tax_rule;
|
public $_errors_tax_rule;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@@ -214,7 +214,7 @@ class AdminTaxRulesGroupControllerCore extends AdminController
|
|||||||
'name' => 'country[]',
|
'name' => 'country[]',
|
||||||
'id' => 'country',
|
'id' => 'country',
|
||||||
'options' => array(
|
'options' => array(
|
||||||
'query' => Country::getCountries((int)$this->context->language->id),
|
'query' => Country::getCountries($this->context->language->id),
|
||||||
'id' => 'id_country',
|
'id' => 'id_country',
|
||||||
'name' => 'name',
|
'name' => 'name',
|
||||||
'default' => array(
|
'default' => array(
|
||||||
@@ -347,73 +347,77 @@ class AdminTaxRulesGroupControllerCore extends AdminController
|
|||||||
public function postProcess()
|
public function postProcess()
|
||||||
{
|
{
|
||||||
if (Tools::isSubmit('deletetax_rule'))
|
if (Tools::isSubmit('deletetax_rule'))
|
||||||
{
|
$this->processDeleteTaxRule();
|
||||||
$id_rule = (int)Tools::getValue('id_tax_rule');
|
else if (Tools::getValue('action') == 'create_rule')
|
||||||
$tax_rule = new TaxRule($id_rule);
|
$this->processCreateRule();
|
||||||
|
else
|
||||||
|
parent::postProcess();
|
||||||
|
}
|
||||||
|
|
||||||
if (Validate::isLoadedObject($tax_rule))
|
protected function processCreateRule()
|
||||||
|
{
|
||||||
|
$zipcode = Tools::getValue('zipcode');
|
||||||
|
$id_rule = (int)Tools::getValue('id_tax_rule');
|
||||||
|
|
||||||
|
$this->selected_countries = Tools::getValue('country');
|
||||||
|
$this->selected_states = Tools::getValue('states');
|
||||||
|
|
||||||
|
if (empty($this->selected_states) || count($this->selected_states) == 0)
|
||||||
|
$this->selected_states = array(0);
|
||||||
|
|
||||||
|
foreach ($this->selected_countries as $id_country)
|
||||||
|
{
|
||||||
|
foreach ($this->selected_states as $id_state)
|
||||||
{
|
{
|
||||||
$tax_rule->delete();
|
$tr = new TaxRule();
|
||||||
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$tax_rule->id_tax_rules_group.'&conf=4&update'.$this->table.'&token='.$this->token);
|
|
||||||
|
// update or creation?
|
||||||
|
if (isset($id_rule))
|
||||||
|
$tr->id = $id_rule;
|
||||||
|
|
||||||
|
$tr->id_tax = (int)Tools::getValue('id_tax');
|
||||||
|
$tr->id_tax_rules_group = (int)Tools::getValue('id_tax_rules_group');
|
||||||
|
$tr->id_country = (int)$id_country;
|
||||||
|
$tr->id_state = (int)$id_state;
|
||||||
|
list($tr->zipcode_from, $tr->zipcode_to) = $tr->breakDownZipCode($zipcode);
|
||||||
|
$tr->behavior = (int)Tools::getValue('behavior');
|
||||||
|
$tr->description = Tools::getValue('description');
|
||||||
|
$this->tax_rule = $tr;
|
||||||
|
$_POST['id_state'] = $tr->id_state;
|
||||||
|
$this->_errors_tax_rule = $this->validateTaxRule($tr);
|
||||||
|
if (count($this->_errors_tax_rule) == 0)
|
||||||
|
if (!$tr->save())
|
||||||
|
$this->errors[] = Tools::displayError('An error has occured: Can\'t save the current tax rule');
|
||||||
|
else
|
||||||
|
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$tr->id_tax_rules_group.'&conf=4&update'.$this->table.'&token='.$this->token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (Tools::getValue('action') == 'create_rule')
|
|
||||||
|
if (count($this->_errors_tax_rule) == 0)
|
||||||
|
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$tr->id_tax_rules_group.'&conf=4&update'.$this->table.'&token='.$this->token);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function processDeleteTaxRule()
|
||||||
|
{
|
||||||
|
$id_rule = (int)Tools::getValue('id_tax_rule');
|
||||||
|
$tax_rule = new TaxRule($id_rule);
|
||||||
|
|
||||||
|
if (Validate::isLoadedObject($tax_rule))
|
||||||
{
|
{
|
||||||
$zipcode = Tools::getValue('zipcode');
|
$tax_rule->delete();
|
||||||
$id_rule = (int)Tools::getValue('id_tax_rule');
|
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$tax_rule->id_tax_rules_group.'&conf=4&update'.$this->table.'&token='.$this->token);
|
||||||
|
}
|
||||||
$this->selected_countries = Tools::getValue('country');
|
|
||||||
$this->selected_states = Tools::getValue('states');
|
|
||||||
|
|
||||||
if (empty($this->selected_states) || count($this->selected_states) == 0)
|
|
||||||
$this->selected_states = array(0);
|
|
||||||
|
|
||||||
foreach ($this->selected_countries as $id_country)
|
|
||||||
{
|
|
||||||
foreach ($this->selected_states as $id_state)
|
|
||||||
{
|
|
||||||
$tr = new TaxRule();
|
|
||||||
|
|
||||||
// update or creation?
|
|
||||||
if (isset($id_rule))
|
|
||||||
$tr->id = $id_rule;
|
|
||||||
|
|
||||||
$tr->id_tax = (int)Tools::getValue('id_tax');
|
|
||||||
$tr->id_tax_rules_group = (int)Tools::getValue('id_tax_rules_group');
|
|
||||||
$tr->id_country = (int)$id_country;
|
|
||||||
$tr->id_state = (int)$id_state;
|
|
||||||
list($tr->zipcode_from, $tr->zipcode_to) = $tr->breakDownZipCode($zipcode);
|
|
||||||
$tr->behavior = (int)Tools::getValue('behavior');
|
|
||||||
$tr->description = Tools::getValue('description');
|
|
||||||
$this->tax_rule = $tr;
|
|
||||||
$_POST['id_state'] = $tr->id_state;
|
|
||||||
$this->_errors_tax_rule = $this->validateTaxRule($tr);
|
|
||||||
if (count($this->_errors_tax_rule) == 0)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!$tr->save())
|
|
||||||
$this->errors[] = Tools::displayError('An error has occured: Can\'t save the current tax rule');
|
|
||||||
} else
|
|
||||||
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$tr->id_tax_rules_group.'&conf=4&update'.$this->table.'&token='.$this->token);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($this->_errors_tax_rule) == 0)
|
|
||||||
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$tr->id_tax_rules_group.'&conf=4&update'.$this->table.'&token='.$this->token);
|
|
||||||
|
|
||||||
} else
|
|
||||||
parent::postProcess();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if the tax rule could be added in the database
|
* check if the tax rule could be added in the database
|
||||||
* @param TaxRule $tr
|
* @param TaxRule $tr
|
||||||
*/
|
*/
|
||||||
protected function validateTaxRule(TaxRule $tr)
|
protected function validateTaxRule(TaxRule $tr)
|
||||||
{
|
{
|
||||||
// TODO: check if the rule already exists
|
// TODO: check if the rule already exists
|
||||||
return $tr->validateController();
|
return $tr->validateController();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user