[-] BO: Fix Currencies bulk statuses and deletion

This commit is contained in:
Rémi Gaillard committed 2013-03-05 18:16:52 +01:00
1 parent 3919fe810c
commit a97e01ce2b
1 file changed
+68 -23
+68 -23
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))
if ($object->id == Configuration::get('PS_CURRENCY_DEFAULT')) return false;
$this->errors[] = $this->l('You cannot delete the default currency'); return parent::processDelete();
else if ($object->delete())
Tools::redirectAdmin(self::$currentIndex.'&conf=1'.'&token='.$this->token);
else
$this->errors[] = Tools::displayError('An error occurred during deletion.');
} }
else
$this->errors[] = Tools::displayError('An error occurred while deleting object.').' protected function processBulkDelete()
<b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)'); {
if (is_array($this->boxes) && !empty($this->boxes))
{
foreach ($this->boxes as $id_currency)
{
$object = new Currency((int)$id_currency);
if (!$this->checkDeletion($object))
return false;
}
}
return parent::processBulkDelete();
} }
/** /**
@@ -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))
if ($object->active && $object->id == Configuration::get('PS_CURRENCY_DEFAULT')) return false;
$this->errors[] = $this->l('You cannot disable the default currency');
else if ($object->toggleStatus()) return parent::processStatus();
Tools::redirectAdmin(self::$currentIndex.'&conf=5'.((($id_category =
(int)Tools::getValue('id_category')) && Tools::getValue('id_product')) ? '&id_category='.$id_category : '').'&token='.$this->token);
else
$this->errors[] = Tools::displayError('An error occurred while updating status.');
} }
else
$this->errors[] = Tools::displayError('An error occurred while updating status for object.').' protected function processBulkDisableSelection()
<b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)'); {
if (is_array($this->boxes) && !empty($this->boxes))
{
foreach ($this->boxes as $id_currency)
{
$object = new Currency((int)$id_currency);
if (!$this->checkDisableStatus($object))
return false;
}
}
return parent::processBulkDisableSelection();
} }
/** /**