diff --git a/bridges/DealabsBridge.php b/bridges/DealabsBridge.php index 4d39502c..a5a3771b 100644 --- a/bridges/DealabsBridge.php +++ b/bridges/DealabsBridge.php @@ -1914,6 +1914,7 @@ class DealabsBridge extends PepperBridgeAbstract 'request-error' => 'Impossible de joindre Dealabs', 'thread-error' => 'Impossible de déterminer l\'ID de la discussion. Vérifiez l\'URL que vous avez entré', 'no-results' => 'Il n'y a rien à afficher pour le moment :(', + 'currency' => '€', 'relative-date-indicator' => [ 'il y a', ], diff --git a/bridges/HotUKDealsBridge.php b/bridges/HotUKDealsBridge.php index a7e62250..44da417a 100644 --- a/bridges/HotUKDealsBridge.php +++ b/bridges/HotUKDealsBridge.php @@ -3278,6 +3278,7 @@ class HotUKDealsBridge extends PepperBridgeAbstract 'request-error' => 'Could not request HotUKDeals', 'thread-error' => 'Unable to determine the thread ID. Check the URL you entered', 'no-results' => 'Ooops, looks like we could', + 'currency' => '£', 'relative-date-indicator' => [ 'ago', ], diff --git a/bridges/MydealsBridge.php b/bridges/MydealsBridge.php index d7e074a9..dda3d2a9 100644 --- a/bridges/MydealsBridge.php +++ b/bridges/MydealsBridge.php @@ -2025,6 +2025,7 @@ class MydealsBridge extends PepperBridgeAbstract 'request-error' => 'Could not request mydeals', 'thread-error' => 'Die ID der Diskussion kann nicht ermittelt werden. Überprüfen Sie die eingegebene URL', 'no-results' => 'Ups, wir konnten nichts', + 'currency' => '€', 'relative-date-indicator' => [ 'vor', 'seit' diff --git a/bridges/PepperBridgeAbstract.php b/bridges/PepperBridgeAbstract.php index 45bfe209..2516fc1e 100644 --- a/bridges/PepperBridgeAbstract.php +++ b/bridges/PepperBridgeAbstract.php @@ -113,8 +113,8 @@ class PepperBridgeAbstract extends BridgeAbstract . $this->getImage($deal) . '"/>' . $this->getHTMLTitle($item) - . $this->getPrice($deal) - . $this->getDiscount($deal) + . $this->getPrice($jsonDealData) + . $this->getDiscount($jsonDealData) . $this->getShipsFrom($deal) . $this->getShippingCost($deal) . $this->getSource($jsonDealData) @@ -273,20 +273,12 @@ HEREDOC; * Get the Price from a Deal if it exists * @return string String of the deal price */ - private function getPrice($deal) + private function getPrice($jsonDealData) { - if ( - $deal->find( - 'span[class*=thread-price]', - 0 - ) != null - ) { - return '
' . $this->i8n('price') . ' : ' - . $deal->find( - 'span[class*=thread-price]', - 0 - )->plaintext - . '
'; + if ($jsonDealData['props']['thread']['discountType'] == null) { + $price = $jsonDealData['props']['thread']['price']; + return '
' . $this->i8n('price') . ' : ' + . $price . ' ' . $this->i8n('currency') . '
'; } else { return ''; } @@ -409,23 +401,22 @@ HEREDOC; * Get the original Price and discout from a Deal if it exists * @return string String of the deal original price and discount */ - private function getDiscount($deal) + private function getDiscount($jsonDealData) { - if ($deal->find('span[class*=mute--text text--lineThrough]', 0) != null) { - $discountHtml = $deal->find('span[class=space--ml-1 size--all-l size--fromW3-xl]', 0); - if ($discountHtml != null) { - $discount = $discountHtml->plaintext; - } else { - $discount = ''; + $oldPrice = $jsonDealData['props']['thread']['nextBestPrice']; + $newPrice = $jsonDealData['props']['thread']['price']; + $percentage = $jsonDealData['props']['thread']['percentage']; + + if ($oldPrice != 0) { + // If there is no percentage calculated, then calculate it manually + if ($percentage == 0) { + $percentage = round(100 - ($newPrice * 100 / $oldPrice), 2); } return '
' . $this->i8n('discount') . ' : ' - . $deal->find( - 'span[class*=mute--text text--lineThrough]', - 0 - )->plaintext - . ' ' - . $discount - . '
'; + . $oldPrice . ' ' . $this->i8n('currency') + . '  -' + . $percentage + . ' %'; } else { return ''; } @@ -448,19 +439,17 @@ HEREDOC; */ private function getShipsFrom($deal) { - $selector = implode( - ' ', /* Notice this is a space! */ - [ - 'hide--toW2', - 'metaRibbon', - ] - ); - if ($deal->find('span[class*=' . $selector . ']', 0) != null) { - $children = $deal->find('span[class*=' . $selector . ']', 0)->children(2); - if ($children) { - return '
' . $children->plaintext . '
'; + $dealMeta = Json::decode($deal->find('div[class=threadGrid-headerMeta]', 0)->find('div[class=js-vue2]', 1)->getAttribute('data-vue2')); + $metas = $dealMeta['props']['metaRibbons']; + $shipsFrom = null; + foreach ($metas as $meta) { + if ($meta['type'] == 'dispatched-from') { + $shipsFrom = $meta['text']; } } + if ($shipsFrom != null) { + return '
' . $shipsFrom . '
'; + } return ''; }