Buying games #1: output promoted products
[stouyapi.git] / bin / import-game-data.php
index bb3fef86921a60c64cfaf91dbc993e06203ced6c..0ae5a4ee7ca3347b3bc319fd9a83f9f01ecdc986 100755 (executable)
@@ -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;