forked from anchetaWern/shopify-tester
/
get-products.php
38 lines (29 loc) · 944 Bytes
/
get-products.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();
$db = new Mysqli(getenv('MYSQL_HOST'), getenv('MYSQL_USER'), getenv('MYSQL_PASS'), getenv('MYSQL_DB'));
$store = 'test-shop.myshopify.com';
$select = $db->query("SELECT access_token FROM installs WHERE store = '$store'");
$user = $select->fetch_object();
$access_token = $user->access_token;
$client = new Client();
$response = $client->request(
'GET',
"https://{$store}/admin/products.json",
[
'query' => [
'fields' => 'id,images,title,variants',
'access_token' => $access_token
]
]
);
$result = json_decode($response->getBody()->getContents(), true);
$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader, [
'cache' => 'cache',
'debug' => true
]);
$template = $twig->loadTemplate('products.html');
echo $template->render(['products' => $result['products']]);