[-] BO: Fix Currencies bulk statuses and deletion

This commit is contained in:
Rémi Gaillard
2013-03-05 18:16:52 +01:00
parent 3919fe810c
commit a97e01ce2b
+66 -21
View File
@@ -239,23 +239,62 @@ class AdminCurrenciesControllerCore extends AdminController
return parent::renderForm(); return parent::renderForm();
} }
protected function checkDeletion($object)
{
if (Validate::isLoadedObject($object))
{
if ($object->id == Configuration::get('PS_CURRENCY_DEFAULT'))
$this->errors[] = $this->l('You cannot delete the default currency');
else
return true;
}
else
$this->errors[] = Tools::displayError('An error occurred while deleting object.').'
<b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
return false;
}
protected function checkDisableStatus($object)
{
if (Validate::isLoadedObject($object))
{
if ($object->active && $object->id == Configuration::get('PS_CURRENCY_DEFAULT'))
$this->errors[] = $this->l('You cannot disable the default currency');
else
return true;
}
else
$this->errors[] = Tools::displayError('An error occurred while updating status for object.').'
<b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
return false;
}
/** /**
* @see AdminController::processDelete() * @see AdminController::processDelete()
*/ */
public function processDelete() public function processDelete()
{ {
if (Validate::isLoadedObject($object = $this->loadObject())) $object = $this->loadObject();
if (!$this->checkDeletion($object))
return false;
return parent::processDelete();
}
protected function processBulkDelete()
{
if (is_array($this->boxes) && !empty($this->boxes))
{ {
if ($object->id == Configuration::get('PS_CURRENCY_DEFAULT')) foreach ($this->boxes as $id_currency)
$this->errors[] = $this->l('You cannot delete the default currency'); {
else if ($object->delete()) $object = new Currency((int)$id_currency);
Tools::redirectAdmin(self::$currentIndex.'&conf=1'.'&token='.$this->token); if (!$this->checkDeletion($object))
else return false;
$this->errors[] = Tools::displayError('An error occurred during deletion.'); }
} }
else
$this->errors[] = Tools::displayError('An error occurred while deleting object.').' return parent::processBulkDelete();
<b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
} }
/** /**
@@ -263,19 +302,25 @@ class AdminCurrenciesControllerCore extends AdminController
*/ */
public function processStatus() public function processStatus()
{ {
if (Validate::isLoadedObject($object = $this->loadObject())) $object = $this->loadObject();
if (!$this->checkDisableStatus($object))
return false;
return parent::processStatus();
}
protected function processBulkDisableSelection()
{
if (is_array($this->boxes) && !empty($this->boxes))
{ {
if ($object->active && $object->id == Configuration::get('PS_CURRENCY_DEFAULT')) foreach ($this->boxes as $id_currency)
$this->errors[] = $this->l('You cannot disable the default currency'); {
else if ($object->toggleStatus()) $object = new Currency((int)$id_currency);
Tools::redirectAdmin(self::$currentIndex.'&conf=5'.((($id_category = if (!$this->checkDisableStatus($object))
(int)Tools::getValue('id_category')) && Tools::getValue('id_product')) ? '&id_category='.$id_category : '').'&token='.$this->token); return false;
else }
$this->errors[] = Tools::displayError('An error occurred while updating status.');
} }
else return parent::processBulkDisableSelection();
$this->errors[] = Tools::displayError('An error occurred while updating status for object.').'
<b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
} }
/** /**