From a43851469e65d5a11f5bfb0880553c037187005d Mon Sep 17 00:00:00 2001 From: gRoussac Date: Tue, 29 Oct 2013 15:39:17 +0100 Subject: [PATCH] [-] CORE : Currency conversion rate can not be 0 --- classes/Currency.php | 17 +++++++++++++---- controllers/admin/AdminCurrenciesController.php | 2 ++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/classes/Currency.php b/classes/Currency.php index af07ba30d..3280ec189 100644 --- a/classes/Currency.php +++ b/classes/Currency.php @@ -73,7 +73,7 @@ class CurrencyCore extends ObjectModel 'sign' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 8), 'format' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'decimals' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true), - 'conversion_rate' =>array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'required' => true, 'shop' => true), + 'conversion_rate' =>array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat', 'required' => true, 'shop' => true), 'deleted' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), ), @@ -107,14 +107,23 @@ class CurrencyCore extends ObjectModel $this->suffix = $this->format % 2 == 0 ? ' '.$this->sign : ''; } /** - * Overriding check if currency with the same iso code already exists. - * If it's true, currency is doesn't added. + * Overriding check if currency rate is not empty and if currency with the same iso code already exists. + * If it's true, currency is not added. * * @see ObjectModelCore::add() */ public function add($autodate = true, $nullValues = false) { - return Currency::exists($this->iso_code, $this->iso_code_num) ? false : parent::add(); + if ((float)$this->conversion_rate <= 0) + return false; + return Currency::exists($this->iso_code, $this->iso_code_num) ? false : parent::add($autodate, $nullValues); + } + + public function update($autodate = true, $nullValues = false) + { + if ((float)$this->conversion_rate <= 0) + return false; + return parent::update($autodate, $nullValues); } /** diff --git a/controllers/admin/AdminCurrenciesController.php b/controllers/admin/AdminCurrenciesController.php index fea2c00a4..10302ee93 100644 --- a/controllers/admin/AdminCurrenciesController.php +++ b/controllers/admin/AdminCurrenciesController.php @@ -346,6 +346,8 @@ class AdminCurrenciesControllerCore extends AdminController } if (Tools::isSubmit('submitAddcurrency') && !Tools::getValue('id_currency') && Currency::exists(Tools::getValue('iso_code'), Tools::getValue('iso_code_num'))) $this->errors[] = Tools::displayError('This currency already exists.'); + if (Tools::isSubmit('submitAddcurrency') && (float)Tools::getValue('conversion_rate') <= 0) + $this->errors[] = Tools::displayError('This currency conversion rate can not be equal to 0.'); parent::initProcess(); } }