From: Christian Weiske Date: Fri, 20 Dec 2019 09:27:37 +0000 (+0100) Subject: Buying games #1: output promoted products X-Git-Tag: v1.0.0~23 X-Git-Url: https://git.cweiske.de/stouyapi.git/commitdiff_plain/42ed43ca190da18e957d1ec948e8f26d30a3b8d7 Buying games #1: output promoted products --- diff --git a/bin/import-game-data.php b/bin/import-game-data.php index bb3fef8..0ae5a4e 100755 --- a/bin/import-game-data.php +++ b/bin/import-game-data.php @@ -210,6 +210,21 @@ function buildApps($game) { $latestRelease = $game->latestRelease; + $product = null; + $gamePromoted = getPromotedProduct($game); + if ($gamePromoted) { + $product = [ + 'type' => 'entitlement', + 'identifier' => $gamePromoted->identifier, + 'name' => $gamePromoted->name, + 'description' => $gamePromoted->description ?? '', + 'localPrice' => $gamePromoted->localPrice, + 'originalPrice' => $gamePromoted->originalPrice, + 'percentOff' => 0, + 'currency' => $gamePromoted->currency, + ]; + } + // http://cweiske.de/ouya-store-api-docs.htm#get-https-devs-ouya-tv-api-v1-apps-xxx return [ 'app' => [ @@ -247,7 +262,7 @@ function buildApps($game) 'supportPhone' => $game->developer->supportPhone, 'founder' => $game->developer->founder, - 'promotedProduct' => null, + 'promotedProduct' => $product, ], ]; } @@ -307,6 +322,21 @@ function buildDetails($game) ]; } + $product = null; + $gamePromoted = getPromotedProduct($game); + if ($gamePromoted) { + $product = [ + 'type' => 'entitlement', + 'identifier' => $gamePromoted->identifier, + 'name' => $gamePromoted->name, + 'description' => $gamePromoted->description ?? '', + 'localPrice' => $gamePromoted->localPrice, + 'originalPrice' => $gamePromoted->originalPrice, + 'percentOff' => 0, + 'currency' => $gamePromoted->currency, + ]; + } + // http://cweiske.de/ouya-store-api-docs.htm#get-https-devs-ouya-tv-api-v1-details return [ 'type' => 'Game', @@ -363,7 +393,7 @@ function buildDetails($game) 'url' => null, ], - 'promotedProduct' => null, + 'promotedProduct' => $product, 'buttons' => $buttons, ]; } @@ -589,6 +619,19 @@ function getAllImageUrls($media) return $imageUrls; } +function getPromotedProduct($game) +{ + if (!isset($game->products) || !count($game->products)) { + return null; + } + foreach ($game->products as $gameProd) { + if ($gameProd->promoted) { + return $gameProd; + } + } + return null; +} + function writeJson($path, $data) { global $wwwDir;