- How do I install php-shopify in a Laravel project?
- Use Composer to install the package with `composer require phpclassic/php-shopify`. Then register the `ShopifyServiceProvider` in your `config/app.php` under the `providers` array. The SDK will automatically bind the `ShopifyClient` to Laravel’s service container for dependency injection.
- Which Laravel versions does php-shopify support?
- The package is designed for Laravel 9.x and 10.x, leveraging modern features like dependency injection and service containers. Check the package’s `composer.json` for exact version constraints, as Laravel’s LTS cycles may require updates to maintain compatibility with Shopify’s API changes.
- Can I use this SDK for GraphQL queries instead of REST?
- Yes, the SDK supports both REST and GraphQL. For GraphQL, use the `graphql()` method on the `ShopifyClient` instance. GraphQL is recommended for complex queries (e.g., fetching products with variants and inventory) to reduce API calls, but be mindful of Shopify’s 500-point query limit.
- How do I handle Shopify webhooks in Laravel?
- The SDK provides helpers to register webhook routes in your `routes/web.php` or `routes/api.php`. Use Laravel’s `Route::post('/shopify/webhooks', [ShopifyWebhookController::class, 'handle'])` and configure the webhook topic in Shopify’s admin panel. For reliability, pair this with Laravel’s queue system to process webhooks asynchronously.
- What’s the best way to sync Shopify products with Laravel Eloquent models?
- Extend Laravel’s Eloquent models (e.g., `Product`) with accessors/mutators to map Shopify attributes. Use model observers or events (e.g., `ProductUpdated`) to trigger syncs with Shopify. For complex relationships (e.g., variants), consider a repository pattern to handle denormalization or use Laravel’s `hasMany`/`belongsTo` with custom accessors.
- How does the SDK handle Shopify’s rate limits (2–4 requests/sec)?
- The SDK integrates with Laravel’s middleware system. Use `ThrottleRequests` or custom middleware to enforce rate limits. For bulk operations, implement pagination (e.g., `?limit=250`) or GraphQL batching. Monitor API usage via Shopify’s API status page and log throttled requests for debugging.
- Is there built-in support for OAuth 2.0 authentication?
- Yes, the SDK simplifies OAuth 2.0 with methods like `authenticate()` and `getAccessToken()`. Store the `access_token` securely using Laravel’s encryption or a vault package like `spatie/laravel-vault`. For custom apps, extend the `ShopifyOAuth` class to handle additional scopes or redirect flows.
- Can I test Shopify interactions in Laravel’s testing environment?
- Absolutely. Use Laravel’s HTTP test helpers or Mockery to mock the `ShopifyClient`. For integration tests, configure a sandbox Shopify store and use environment-specific API keys. The SDK’s dependency injection makes it easy to swap implementations for testing (e.g., a mock client in `phpunit.xml`).
- What alternatives exist for Shopify-Laravel integration?
- Alternatives include the official `shopify/api` PHP SDK (REST-only) or community packages like `spatie/laravel-shopify`. However, `phpclassic/php-shopify` stands out for its Laravel-native integration (service container, Eloquent sync, and GraphQL support). Choose based on your need for REST vs. GraphQL, or if you require custom business logic beyond the SDK’s scope.
- How do I handle failed API calls or retries in production?
- Implement exponential backoff for retries using Laravel’s `retry` helper or a custom `ShopifyHttpClient` wrapper. For critical failures, log errors to a monitoring system (e.g., Sentry) and use Laravel’s queue system with `retryAfter` to avoid immediate retries. Consider circuit breakers (e.g., `laravel-circuit-breaker`) for prolonged outages.