From 6c86e2c1f73897180d56d0a0d10e37e8eb63dbb9 Mon Sep 17 00:00:00 2001 From: sysadminstory Date: Fri, 8 Nov 2024 08:11:18 +0100 Subject: [PATCH] [IdealoBridge] Really fix Logic and enhance Feed Content (#4321) - Fix Feed Title generation (wrong usage of loadCacheValue) - Use a more reliable way to get New and Used Price - If no new Price and no Used Price are present in the page, then don't delete previous New Price and previous Used Price - If there is no New Price and no Used Price, then return no Feed Item - Fix the "now" date format - Make the Feed Item Title more readable - Use the Product Link as the Feed URL --- bridges/IdealoBridge.php | 48 ++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/bridges/IdealoBridge.php b/bridges/IdealoBridge.php index 7432f78ae51..92bb30d0bad 100644 --- a/bridges/IdealoBridge.php +++ b/bridges/IdealoBridge.php @@ -49,7 +49,7 @@ private function getFeedTitle() $cacheDuration = 604800; $link = $this->getInput('Link'); $keyTITLE = $link . 'TITLE'; - $product = $this->loadCacheValue($keyTITLE, $cacheDuration); + $product = $this->loadCacheValue($keyTITLE); // The cache does not contain the title of the bridge, we must get it and save it in the cache if ($product === null) { @@ -147,30 +147,32 @@ public function collectData() $OldPriceUsed = $this->loadCacheValue($KeyUSED); // 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; + $ActualNewPrice = $html->find('div[id=oopStage-conditionButton-new]', 0); + // Second Button contains the used product price + $ActualUsedPrice = $html->find('div[id=oopStage-conditionButton-used]', 0); + + if ($ActualNewPrice) { + $PriceNew = $ActualNewPrice->find('strong', 0)->plaintext; // Save current price $this->saveCacheValue($KeyNEW, $PriceNew); - } else if ($FirstButton === null) { - // In case there is no actual New Price delete the previous value in the cache + } else if ($ActualNewPrice === null && $ActualUsedPrice !== null) { + // In case there is no actual New Price and a Ured Price exists, then delete the previous value in the cache $this->cache->delete($this->getShortName() . '_' . $KeyNEW); } // Second Button contains the used product price - $SecondButton = $html->find('.oopStage-conditionButton-wrapper-text', 1); - if ($SecondButton) { - $PriceUsed = $SecondButton->find('strong', 0)->plaintext; + if ($ActualUsedPrice) { + $PriceUsed = $ActualUsedPrice->find('strong', 0)->plaintext; // Save current price $this->saveCacheValue($KeyUSED, $PriceUsed); - } else if ($SecondButton === null) { - // In case there is no actual Used Price delete the previous value in the cache + } else if ($ActualUsedPrice === null && $ActualNewPrice !== null) { + // In case there is no actual Used Price and a New Price exists, then delete the previous value in the cache $this->cache->delete($this->getShortName() . '_' . $KeyUSED); } - // Only continue if a price has changed - if ($PriceNew != $OldPriceNew || $PriceUsed != $OldPriceUsed) { + // Only continue if a price has changed and there exists a New or Used price (sometimes no new Price _and_ Used Price are shown) + if (!($ActualNewPrice === null && $ActualUsedPrice === null ) && ($PriceNew != $OldPriceNew || $PriceUsed != $OldPriceUsed)) { // Get Product Image $image = $html->find('.datasheet-cover-image', 0)->src; @@ -198,9 +200,9 @@ public function collectData() $content .= ""; - $now = date('d.m.j H:m'); + $now = date('d/m/Y H:i'); - $Pricealarm = 'Pricealarm %s: %s %s %s'; + $Pricealarm = 'Pricealarm %s: %s %s - %s'; // Currently under Max new price if ($this->getInput('MaxPriceNew') != '') { @@ -247,7 +249,7 @@ public function collectData() $title .= 'USED' . $this->getPriceTrend($PriceUsed, $OldPriceUsed) . ' '; } $title .= $Productname; - $title .= ' '; + $title .= ' - '; $title .= $now; $item = [ @@ -275,4 +277,18 @@ public function getName() return parent::getName(); } } + + /** + * Returns the RSS Feed URL according to the parameters + * @return string the RSS feed URL + */ + public function getURI() + { + switch ($this->queriedContext) { + case '0': + return $this->getInput('Link'); + default: + return parent::getURI(); + } + } }