From 1d9dbb802bbc80483343c9038c5fefdd8f4fd9e6 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Mon, 14 Aug 2017 21:02:12 +0100 Subject: [PATCH] fix zero price on homepage --- src/Controller/MainController.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index c585fd4..efc2036 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -53,7 +53,7 @@ class MainController extends AppController { $lastPriceDt = new \DateTime($priceInfo->time); $diff = $now->diff($lastPriceDt); $diffMinutes = $diff->i; - if ($diffMinutes >= 15) { // 15 minutes + if ($diffMinutes >= 15 || $priceInfo->price == 0) { // 15 minutes (or if the price is 0) $shouldRefreshPrice = true; } } @@ -68,10 +68,12 @@ class MainController extends AppController { $lbcPrice = 0; if (isset($blckjson->USD)) { $lbcPrice = $onelbc * $blckjson->USD->buy; - $priceInfo->price = number_format($lbcPrice, 2, '.', ''); - $priceInfo->time = $now->format('c'); - if ($this->redis) { - $this->redis->set(self::lbcPriceKey, json_encode($priceInfo)); + if ($lbcPrice > 0) { + $priceInfo->price = number_format($lbcPrice, 2, '.', ''); + $priceInfo->time = $now->format('c'); + if ($this->redis) { + $this->redis->set(self::lbcPriceKey, json_encode($priceInfo)); + } } } }