1. Go to this page and download the library: Download zfr/zfr-shopify library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$shopifyClient = new ShopifyClient([
'private_app' => false,
'api_key' => 'YOUR_API_KEY', // In public app, this is the app ID
'access_token' => 'MERCHANT_TOKEN',
'shop' => 'merchant.myshopify.com',
'version' => '2019-04'
]);
// myconfig.php
return [
'zfr_shopify' => [
'private_app' => false,
'api_key' => 'YOUR_API_KEY', // In public app, this is the app ID
'access_token' => 'MERCHANT_TOKEN',
'shop' => 'merchant.myshopify.com',
],
];
use ZfrShopify\Exception\InvalidRequestException;
use ZfrShopify\Validator\RequestValidator;
$validator = new RequestValidator();
try {
$validator->validateRequest($psr7Request, 'shared_secret');
} catch (InvalidRequestException $exception) {
// Request is not valid
}
use ZfrShopify\Exception\InvalidWebhookException;
use ZfrShopify\Validator\WebhookValidator;
$validator = new WebhookValidator();
try {
$validator->validateWebhook($psr7Request, 'shared_secret');
} catch (InvalidWebhookException $exception) {
// Request is not valid
}
use ZfrShopify\Exception\InvalidApplicationProxyRequestException;
use ZfrShopify\Validator\ApplicationProxyRequestValidator;
$validator = new ApplicationProxyRequestValidator();
try {
$validator->validateApplicationProxyRequest($psr7Request, 'shared_secret');
} catch {
// Request is not valid
}
foreach ($shopifyClient->getProductsIterator(['fields' => 'id,title']) as $product) {
// Do something with product
}
$command1 = $client->getCommand('GetShop', ['fields' => 'id']);
$command2 = $client->getCommand('GetProducts', ['fields' => 'id,title']);
$results = $client->executeAll([$command1, $command2]);
// $results[0] represents the response of $command1, $results[1] represents the response of $command2
use GuzzleHttp\Command\Exception\CommandException;
foreach ($results as $singleResult) {
if ($singleResult instanceof CommandException) {
// Get the command that has failed, and eventually retry
$command = $singleResult->getCommand();
continue;
}
// Otherwise, $singleResult is just an array that contains the Shopify data
}