1. Go to this page and download the library: Download esign/laravel-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/ */
esign / laravel-shopify example snippets
namespace App\GraphQL\Queries;
use Esign\LaravelShopify\GraphQL\Contracts\Query;
class GetProductQuery implements Query
{
public function __construct(private string $productId) {}
public function getQuery(): string
{
return <<<'GQL'
query getProduct($id: ID!) {
product(id: $id) {
id
title
description
variants(first: 10) {
edges {
node {
id
price
sku
}
}
}
}
}
GQL;
}
public function getVariables(): array
{
return ['id' => $this->productId];
}
public function mapFromResponse(array $response): mixed
{
return $response['data']['product'];
}
}
use Esign\LaravelShopify\Facades\Shopify;
use App\GraphQL\Queries\GetProductQuery;
// In a controller or job
$product = Shopify::query(new GetProductQuery('gid://shopify/Product/123'));
namespace App\GraphQL\Mutations;
use Esign\LaravelShopify\GraphQL\Contracts\Mutation;
class CreateProductMutation implements Mutation
{
public function __construct(
private string $title,
private string $description
) {}
public function getQuery(): string
{
return <<<'GQL'
mutation createProduct($input: ProductInput!) {
productCreate(input: $input) {
product {
id
title
}
userErrors {
field
message
}
}
}
GQL;
}
public function getVariables(): array
{
return [
'input' => [
'title' => $this->title,
'description' => $this->description,
],
];
}
public function mapFromResponse(array $response): mixed
{
return $response['data']['productCreate']['product'];
}
}
namespace App\GraphQL\Queries;
use Esign\LaravelShopify\GraphQL\Contracts\PaginatedQuery;
class GetAllProductsQuery implements PaginatedQuery
{
public function getQuery(): string
{
return <<<'GQL'
query getAllProducts($cursor: String) {
products(first: 50, after: $cursor) {
edges {
node {
id
title
}
cursor
}
pageInfo {
hasNextPage
endCursor
}
}
}
GQL;
}
public function getVariables(): array
{
return [];
}
public function mapFromResponse(array $response): array
{
return $response['data']['products']['edges'];
}
public function hasNextPage(array $response): bool
{
return $response['data']['products']['pageInfo']['hasNextPage'];
}
public function getNextCursor(array $response): ?string
{
return $response['data']['products']['pageInfo']['endCursor'];
}
}
namespace App\Jobs\Shopify;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class OrdersCreateJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(
public string $shopDomain,
public array $webhookData,
) {}
public function handle(): void
{
Log::info('Order created', [
'shop' => $this->shopDomain,
'order_id' => $this->webhookData['id'],
]);
// Process order data
// YourOrder::create([...]);
}
}
// In EventServiceProvider or via Event::listen()
use Esign\LaravelShopify\Events\AppInstalledEvent;
use Esign\LaravelShopify\Events\AppUninstalledEvent;
Event::listen(AppInstalledEvent::class, function (AppInstalledEvent $event) {
// $event->shop contains the Shop model
Log::info('New shop installed', ['domain' => $event->shop->domain]);
// Dispatch a job if heavy processing is needed
dispatch(new SetupNewShopJob($event->shop));
});
Event::listen(AppUninstalledEvent::class, function (AppUninstalledEvent $event) {
// Clean up external resources, notify team, etc.
});
// In app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
// Delete shops soft-deleted 90+ days ago
$schedule->command('shopify:cleanup-uninstalled-shops --days=90 --force')
->daily();
}
use Esign\LaravelShopify\Models\Shop;
// Get authenticated shop
$shop = Auth::user(); // Returns Shop model
// Check installation status
if ($shop->isInstalled()) {
// Shop is currently installed
}
// Mark as uninstalled (soft delete)
$shop->markAsUninstalled();
// Mark as reinstalled (restore + update token)
$newAccessToken = '...'; // Get new token via token exchange
$shop->markAsReinstalled($newAccessToken);
// Access token (encrypted in database)
$token = $shop->access_token;