diff --git a/src/bb-modules/Currency/Api/Admin.php b/src/bb-modules/Currency/Api/Admin.php index e48be57d1..63df21b9e 100644 --- a/src/bb-modules/Currency/Api/Admin.php +++ b/src/bb-modules/Currency/Api/Admin.php @@ -160,9 +160,29 @@ class Admin extends \Api_Abstract * * @return bool */ - public function update_key($data) + public function update_rate_settings($data) { - return $this->getService()->updateKey($this->di['array_get']($data, 'currencylayer_key')); + $this->getService()->updateKey($this->di['array_get']($data, 'currencylayer_key')); + + if ($this->di['array_get']($data, 'crons_enabled') == "1") { + $set = "1"; + } else { + $set = "0"; + } + + $this->getService()->setCron($set); + + return true; + } + + /** + * See if CRON jobs are enabled for currency rates + * + * @return string (0/1) + */ + public function is_cron_enabled($data) + { + return $this->getService()->isCronEnabled(); } /** diff --git a/src/bb-modules/Currency/Service.php b/src/bb-modules/Currency/Service.php index dc8d603f1..624a76fcd 100644 --- a/src/bb-modules/Currency/Service.php +++ b/src/bb-modules/Currency/Service.php @@ -350,6 +350,36 @@ class Service implements InjectionAwareInterface $currency = $db->exec($sql, $values); } + public function isCronEnabled() + { + $sql = "SELECT `param`, `value` FROM setting"; + $db = $this->di['db']; + + $pairs = $db->getAssoc($sql); + + if (isset($pairs['currency_cron_enabled']) && $pairs['currency_cron_enabled'] == "1") { + return true; + } else { + return false; + } + } + + public function setCron($data) + { + $sql = "INSERT INTO `setting` (`param`, `value`, `public`, `created_at`, `updated_at`) VALUES ('currency_cron_enabled', :key, '0', CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()) ON DUPLICATE KEY UPDATE `value`=:key, `updated_at`=CURRENT_TIMESTAMP()"; + + if ($data == "1") { + $key = "1"; + } else { + $key = "0"; + } + + $values = array(':key' => $key); + + $db = $this->di['db']; + $currency = $db->exec($sql, $values); + } + public function toApiArray(\Model_Currency $model) { return array( @@ -506,7 +536,9 @@ class Service implements InjectionAwareInterface $currencyService = $di['mod_service']('currency'); try { - $currencyService->updateCurrencyRates(); + if ($currencyService->isCronEnabled()) { + $currencyService->updateCurrencyRates(""); + } } catch (\Exception $e) { error_log($e); } diff --git a/src/bb-modules/Currency/html_admin/mod_currency_settings.phtml b/src/bb-modules/Currency/html_admin/mod_currency_settings.phtml index 45317e2f5..b710dc72f 100644 --- a/src/bb-modules/Currency/html_admin/mod_currency_settings.phtml +++ b/src/bb-modules/Currency/html_admin/mod_currency_settings.phtml @@ -125,7 +125,7 @@

BoxBilling uses data grabbed from European Central Bank for conversions from Euro to other currencies, and currencylayer for conversations from US Dollar to other currencies.
If you choose Euro as your default currency, data from European Central Bank will be used, if you choose US Dollar, data from currencylayer will be used.
While European Central Bank decided to keep it's API free to everyone, you won't need an autorization key to use ECB's data. However, you'll need an API key to use currencylayer.
You can grab your API key from currencylayer's website. BoxBilling doesn't make any profits from your purchases on currencylayer.com

BoxBilling does not take any responsibilities for data grabbed from 3rd party sources, including European Central Bank and currencylayer.

-
+
@@ -134,6 +134,15 @@
+
+ +

If you enable this, conversion rates will be automatically updated whenever the CRON job fires up.

+
+ + +
+
+