diff --git a/bridges/IdealoBridge.php b/bridges/IdealoBridge.php index 4eb66dcb..f426a45c 100644 --- a/bridges/IdealoBridge.php +++ b/bridges/IdealoBridge.php @@ -81,6 +81,25 @@ class IdealoBridge extends BridgeAbstract return $title . ' - ' . $this::NAME; } + /** + * Returns the Price as float + * @return float rhe price converted in float + */ + private function convertPriceToFloat($price) + { + // Every price is stored / displayed as "xxx,xx €", but PHP can't convert it as float + + if ($price !== null) { + // Convert comma as dot + $price = str_replace(',', '.', $price); + // Remove the '€' char + $price = str_replace('€', '', $price); + // Convert to float + return floatval($price); + } else { + return $price; + } + } /** * Returns the Price Trend emoji @@ -88,8 +107,10 @@ class IdealoBridge extends BridgeAbstract */ private function getPriceTrend($NewPrice, $OldPrice) { - // In case there is no old PRice, then show no trend - if ($OldPrice === null) { + $NewPrice = $this->convertPriceToFloat($NewPrice); + $OldPrice = $this->convertPriceToFloat($OldPrice); + // In case there is no old Price, then show no trend + if ($OldPrice === null || $OldPrice == 0) { $trend = ''; } else if ($NewPrice > $OldPrice) { $trend = '↗'; @@ -125,7 +146,7 @@ class IdealoBridge extends BridgeAbstract $OldPriceNew = $this->loadCacheValue($KeyNEW); $OldPriceUsed = $this->loadCacheValue($KeyUSED); - // First button is new. Found at oopStage-conditionButton-wrapper-text class (.) + // First button contains the new price. Found at oopStage-conditionButton-wrapper-text class (.) $FirstButton = $html->find('.oopStage-conditionButton-wrapper-text', 0); if ($FirstButton) { $PriceNew = $FirstButton->find('strong', 0)->plaintext; @@ -133,7 +154,7 @@ class IdealoBridge extends BridgeAbstract $this->saveCacheValue($KeyNEW, $PriceNew); } - // Second Button is used + // Second Button contains the used product price $SecondButton = $html->find('.oopStage-conditionButton-wrapper-text', 1); if ($SecondButton) { $PriceUsed = $SecondButton->find('strong', 0)->plaintext; @@ -149,7 +170,7 @@ class IdealoBridge extends BridgeAbstract $content = ''; // Generate Content - if (isset($PriceNew) && $PriceNew > 1) { + if (isset($PriceNew) && $this->convertPriceToFloat($PriceNew) > 0) { $content .= sprintf('
Price New:
%s %s
Price New before:
$OldPriceNew
Max Price New:
%s,00 €
Price Used:
%s %s
Price Used before:
$OldPriceUsed