Skip to content

Commit

Permalink
Fixed ItemListings, removed _str fields in "price_data" key (see exam…
Browse files Browse the repository at this point in the history
…ples)
  • Loading branch information
Allyans3 committed Nov 15, 2023
1 parent a6b4cd1 commit 3eec093
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 59 deletions.
3 changes: 0 additions & 3 deletions examples/item_listings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [▶]
Expand Down
87 changes: 31 additions & 56 deletions src/Responses/Steam/ItemListings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 3eec093

Please sign in to comment.