From 3eec0939704158b551c539b3d930576d07c505cc Mon Sep 17 00:00:00 2001 From: allyans3 Date: Wed, 15 Nov 2023 09:17:59 +0100 Subject: [PATCH] Fixed ItemListings, removed _str fields in "price_data" key (see examples) --- examples/item_listings.php | 3 - src/Responses/Steam/ItemListings.php | 87 ++++++++++------------------ 2 files changed, 31 insertions(+), 59 deletions(-) diff --git a/examples/item_listings.php b/examples/item_listings.php index 3312ae2..6c901c1 100644 --- a/examples/item_listings.php +++ b/examples/item_listings.php @@ -58,11 +58,8 @@ // "currency_id" => 1 // "currency" => "USD" // "price_with_fee" => 2.67 -// "price_with_fee_str" => "$2.67" // "price_with_publisher_fee_only" => 2.56 -// "price_with_publisher_fee_only_str" => "$2.56" // "price_without_fee" => 2.33 -// "price_without_fee_str" => "$2.33" // ] // ] // 1 => array:4 [▶] diff --git a/src/Responses/Steam/ItemListings.php b/src/Responses/Steam/ItemListings.php index d229873..6f9040a 100644 --- a/src/Responses/Steam/ItemListings.php +++ b/src/Responses/Steam/ItemListings.php @@ -98,70 +98,45 @@ private function parseListings($data): array { $returnData = ResponseService::fillBaseData($data); - $document = new Document($data['results_html']); - $listingsNode = $document->find('.market_listing_row, market_recent_listing_row'); - - foreach ($listingsNode as $listing) { - $listingData = self::parseListingHTML($listing); - - foreach ($data['listinginfo'] as $listingId => $value) { - if ($listingId == $listingData['listing_id']) { - $listingData['asset'] = ResponseService::getAssetData($data['assets'], $value['asset']); - - if ($value['price'] > 0 && $value['fee'] > 0) { - $currencyId = $value['currencyid'] - 2000; - $convertedCurrencyId = $value['converted_currencyid'] - 2000; - - $listingData['original_price_data'] = [ - 'currency_id' => $currencyId, - 'currency' => Economic::CURRENCY_LIST[$currencyId], - 'price_with_fee' => ($value['price'] + $value['fee']) / 100, - 'price_with_publisher_fee_only' => ($value['price'] + $value['publisher_fee']) / 100, - 'price_without_fee' => $value['price'] / 100 - ]; - - $listingData['price_data']['currency_id'] = $convertedCurrencyId; - $listingData['price_data']['currency'] = Economic::CURRENCY_LIST[$convertedCurrencyId]; - $listingData['price_data']['price_with_fee'] = ($value['converted_price'] + $value['converted_fee']) / 100; - $listingData['price_data']['price_with_publisher_fee_only'] = ($value['converted_price'] + $value['converted_publisher_fee']) / 100; - $listingData['price_data']['price_without_fee'] = $value['converted_price'] / 100; - } - } - } - - $returnData['listings'][] = $listingData; + foreach ($data['listinginfo'] as $listingId => $value) { + $returnData['listings'][] = self::completeListing($data, $listingId, $value); } - unset($document); - return ResponseService::filterData($returnData, $this->select, $this->makeHidden); } /** - * @param $listing + * @param $data + * @param $listingId + * @param $value * @return array + * @throws InvalidSelectorException */ - private function parseListingHTML($listing): array + private function completeListing($data, $listingId, $value): array { - return [ - 'listing_id' => substr($listing->attr('id'), 8), - 'asset' => [], - - 'original_price_data' => [], - - 'price_data' => [ - 'currency_id' => 0, - 'currency' => '', - - 'price_with_fee' => 0, - 'price_with_fee_str' => trim($listing->find('.market_listing_price_with_fee')[0]->text()), - - 'price_with_publisher_fee_only' => 0, - 'price_with_publisher_fee_only_str' => trim($listing->find('.market_listing_price_with_publisher_fee_only')[0]->text()), - - 'price_without_fee' => 0, - 'price_without_fee_str' => trim($listing->find('.market_listing_price_without_fee')[0]->text()), - ], - ]; + $listingData = []; + + $listingData['listing_id'] = $listingId; + $listingData['asset'] = ResponseService::getAssetData($data['assets'], $value['asset']); + + if ($value['price'] > 0 && $value['fee'] > 0) { + $currencyId = $value['currencyid'] - 2000; + $convertedCurrencyId = $value['converted_currencyid'] - 2000; + + $listingData['original_price_data'] = [ + 'currency_id' => $currencyId, + 'currency' => Economic::CURRENCY_LIST[$currencyId], + 'price_with_fee' => ($value['price'] + $value['fee']) / 100, + 'price_with_publisher_fee_only' => ($value['price'] + $value['publisher_fee']) / 100, + 'price_without_fee' => $value['price'] / 100 + ]; + + $listingData['price_data']['currency_id'] = $convertedCurrencyId; + $listingData['price_data']['currency'] = Economic::CURRENCY_LIST[$convertedCurrencyId]; + $listingData['price_data']['price_with_fee'] = ($value['converted_price'] + $value['converted_fee']) / 100; + $listingData['price_data']['price_with_publisher_fee_only'] = ($value['converted_price'] + $value['converted_publisher_fee']) / 100; + $listingData['price_data']['price_without_fee'] = $value['converted_price'] / 100; + } + return $listingData; } } \ No newline at end of file