コメントありがとうございます。 サービス終了した今なら、安く中古が手に入りそ…
EC-CUBEのWebAPIを叩いて商品一覧を取得する
【参考】EC-CUBE4 Web API プラグイン 開発ドキュメント
アクセストークンが未取得の場合は、EC-CUBEのWebAPIでアクセストークンを発行するにてアクセストークンを取得する。
<?php define("ECCUBE_API_ENDPOINT", "■■■Authorization endpoint■■■"); define("ECCUBE_ACCESS_TOKEN", "■■■アクセストークン■■■"); $query = <<<EOT query { products (page: 1) { edges { node { id name create_date } } nodes { id name create_date } totalCount pageInfo { hasNextPage hasPreviousPage } } } EOT; $post_data = json_encode(["query"=>$query]); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, ECCUBE_API_ENDPOINT); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Authorization: Bearer ' . ECCUBE_ACCESS_TOKEN ]); $result = curl_exec($curl); header("Content-Type: text/html"); echo "<html><body><pre>"; print_r(json_decode($result, true)); echo "</pre></body></html>"; ?>
戻り値のサンプル
Array ( [data] => Array ( [products] => Array ( [edges] => Array ( [0] => Array ( [node] => Array ( [id] => 98 [name] => 商品名:1 [create_date] => 2024-10-02T19:52:14+09:00 ) ) [1] => Array ( [node] => Array ( [id] => 97 [name] => 商品名:2 [create_date] => 2024-10-02T19:20:35+09:00 ) ) [2] => Array ( [node] => Array ( [id] => 96 [name] => 商品名:3 [create_date] => 2024-10-02T18:51:09+09:00 ) ) ) [nodes] => Array ( [0] => Array ( [id] => 98 [name] => 商品名:1 [create_date] => 2024-10-02T19:52:14+09:00 ) [1] => Array ( [id] => 97 [name] => 商品名:2 [create_date] => 2024-10-02T19:20:35+09:00 ) [2] => Array ( [id] => 96 [name] => 商品名:3 [create_date] => 2024-10-02T18:51:09+09:00 ) ) [totalCount] => 94 [pageInfo] => Array ( [hasNextPage] => 1 [hasPreviousPage] => ) ) ) )
検索
コメントを残す