PHP code example of crazymeeks / php-shopify
1. Go to this page and download the library: Download crazymeeks/php-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/ */
crazymeeks / php-shopify example snippets
namespace Some\Name\Space;
use Crazymeeks\App\Contracts\ShopifyConfigContextInterface;
class ConfigContext implements ShopifyConfigContextInterface
{
/**
* @implement
*/
public function getApiKey(): string
{
return 'your-shopify-api-key-here';
}
/**
* @implement
*/
public function getSecretKey(): string
{
return 'your-shopify-secret-key-here';
}
/**
* @implement
*/
public function getVersion(): string
{
return '2021-01';
}
}
namespace Your\Name\Space;
use Crazymeeks\App\Contracts\InstallContextInterface;
class InstallContext implements InstallContextInterface
{
/**
* @implemented
*/
public function getScopes(): array
{
// You may add as many scopes as you want here
return [
'read_orders',
'write_products',
];
}
/**
* @implemented
*/
public function getRedirectUri(): string
{
// The url of your website that will be use by shopify
// during installation of your shopify app
return 'https://mywebsite.com/app/generate-token';
}
}
$shopify = new \Crazymeeks\App\Shopify();
$shopify->install(new InstallContext(), 'test.myshopify.com');
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\GetShopAccessToken())
->setData([
'hmac' => 'a3cc315a829340ab014e7f5aa8eabe83f9cfeaf4b9eb6c17f04c85cabf188729',
'code' => '6a94694acf0339e9eb8068d8f4718eea',
'shop' => 'test.myshopify.com',
'timestamp' => '1610955131',
])
->setShopUrl('test.myshopify.com')
->execute();
// echo access_token and scope,
// you must save the response' access token
// for future use
echo 'Access Token: ' . $response->access_token . '<br>Scope: ' . $response->scope;
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\CreateCustomer())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->setData([
'first_name' => 'John',
'last_name' => 'Doe',
'email' => '[email protected] ',
'verified_email' => true,
'send_email_welcome' => false,
'password' => 'test123123',
'password_confirmation' => 'test123123',
])
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\SearchCustomer())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->setData('email:[email protected] ')
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\GetCustomer())
->setAccessToken('your-access-token')
->setResourceId('207119551')
->setShopUrl('test.myshopify.com')
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\GetCustomer())
->setAccessToken('your-access-token')
->setResourceId('207119551')
->setShopUrl('test.myshopify.com')
->setWhitelistedEmailDomains(['@gmail.com', '@hotmail.com'])
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\GetCollect())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\GetCollect())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->setResourceId('455204334')
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\CollectCount())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\GetProductCollections())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->setResourceId('239222980791')
->setPerPage(10) // Optional only
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\GetCollection())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->setResourceId('841564295')
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\AddProductToCollection())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->setData([
'product_id' => 921728736,
'collection_id' => 841564295,
])
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\DeleteProductToCollection())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->setData('455204334')
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\GetOrder())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->setStatus(\Crazymeeks\App\Resource\Action\GetOrder::CANCELLED) // Optional. Other status are: CLOSED, OPEN
->setFinancialStatus(\Crazymeeks\App\Resource\Action\GetOrder::FIN_ANY) // Optional. Other financial status are: FIN_AUTHORIZED, FIN_PENDING, FIN_PAID, FIN_PARTIALLY_PAID, FIN_REFUNDED, FIN_VOIDED, FIN_PARTIALLY_REFUNDED, FIN_UNPAID
->setFulfillmentStatus(\Crazymeeks\App\Resource\Action\GetOrder::FFMT_ANY) // Optional. Other fulfillment status are: FFMT_SHIPPED, FFMT_PARTIAL, FFMT_UNSHIPPED, FFMT_UNFULFILLED
->setPerPage(5) // Optional
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\GetOrder())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->setResourceId('450789469')
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\GetOrderCount())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\CloseOrder())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->setResourceId('450789469')
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\ReOpenOrder())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->setResourceId('450789469')
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\CancelOrder())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->setResourceId('450789469')
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\CreateScriptTag())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->setData('https://myweb.com/script.js')
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\GetScriptTags())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\UpdateScriptTag())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->setResourceId('596726825')
->setData('https://myweb.com/script.js')
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\DeleteScriptTag())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->setResourceId('596726825')
->execute();
$shopify = new \Crazymeeks\App\Shopify(new ConfigContext());
$response = $shopify->setAction(new \Crazymeeks\App\Resource\Action\ScriptTagCount())
->setAccessToken('your-access-token')
->setShopUrl('test.myshopify.com')
->execute();