vincenth520 / shopify
Shopify PHP SDK to interact with the Shopify API
v1.0
2017-12-11 03:03 UTC
Requires
- php: >=5.5.0
- guzzlehttp/guzzle: ~6.0
This package is auto-updated.
Last update: 2025-05-12 20:56:40 UTC
README
Setup/Installation
You can install it on packgist
composer require vincenth520/shopify
You must first setup a public app. View documentation. You need an authorization URL.
require 'vendor/autoload.php'; session_start(); $APP_API_KEY = ''; //api key $APP_SECRET = ''; //app secret $client = new Shopify\Shopify($_GET['shop'], $APP_API_KEY, $APP_SECRET); $_SESSION['client_id'] = time(); $random_state = $_SESSION['client_id']; $rediect_url = 'http://localhost/shopify/shopify/redirect.php'; //this is your redirect url $client->authorizeUser($rediect_url, [ 'read_products', 'write_products', ], $random_state);
At this point, the user is taken to their store to authorize the application to use their information. If the user accepts, they are taken to the redirect URL.
session_start(); require 'vendor/autoload.php'; $APP_API_KEY = ''; //api key $APP_SECRET = ''; //app secret $client = new Shopify\Shopify($_GET['shop'], $APP_API_KEY, $APP_SECRET); $client->setState($_SESSION['client_id']); if ($token = $client->getAccessToken()) { $_SESSION['shopify_access_token'] = $token; $_SESSION['shopify_shop_domain'] = $_GET['shop']; } else { die('invalid token'); }
Method
- get shop info
$client = new Shopify\Shopify($_SESSION['shopify_shop_domain'], $APP_API_KEY, $APP_SECRET); $client->getShopInfo();
- get webhook
$client = new Shopify\Shopify($_SESSION['shopify_shop_domain'], $APP_API_KEY, $APP_SECRET); $client->getWebhooks();
- add webhook
$client = new Shopify\Shopify($_SESSION['shopify_shop_domain'], $APP_API_KEY, $APP_SECRET); $type = 'collections/create'; //topics [see:https://help.shopify.com/api/reference/webhook] $address = 'https://baidu.com'; //address URIs $format = 'json'; //json or xml $client->addWebhook($type,$address,$format);