Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Shopify Laravel Package

osiset/laravel-shopify

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require osiset/laravel-shopify
    

    Publish the config file:

    php artisan vendor:publish --provider="Osiset\Shopify\ShopifyServiceProvider"
    

    Add the middleware to your app/Http/Kernel.php:

    'shopify' => \Osiset\Shopify\Middleware\ShopifyMiddleware::class,
    
  2. Configuration: Update .env with your Shopify API credentials:

    SHOPIFY_API_KEY=your_api_key
    SHOPIFY_API_SECRET=your_api_secret
    SHOPIFY_API_SCOPES=read_products,write_products
    SHOPIFY_API_VERSION=2023-10
    
  3. First Use Case: Fetch a Shopify shop’s products in a controller:

    use Osiset\Shopify\Facades\Shopify;
    
    public function index()
    {
        $products = Shopify::get('products');
        return response()->json($products);
    }
    

Where to Look First

  • Wiki: Start with the Installation and Usage guides.
  • Route List: Review the Route List for built-in endpoints.
  • Facades: Use Shopify facade for API interactions (e.g., Shopify::get(), Shopify::post()).

Implementation Patterns

Core Workflows

  1. Authentication & Session Handling:

    • Use the built-in OAuth flow for app installations:
      // Redirect to Shopify for OAuth
      return Shopify::redirectToShopify();
      
      // Handle callback after OAuth
      public function handleCallback()
      {
          return Shopify::handleCallback();
      }
      
    • Store sessions in the database (configured in config/shopify.php).
  2. API Interactions:

    • GET Requests:
      $products = Shopify::get('products', ['limit' => 10]);
      
    • POST Requests:
      $product = Shopify::post('products', ['title' => 'New Product']);
      
    • Webhooks: Register webhook subscriptions:
      Shopify::subscribe('products/create', 'https://your-app.com/webhooks/shopify');
      
  3. Billable Metrics (for Paid Apps):

    • Track usage with Shopify::billable():
      Shopify::billable()->increment('api_calls', 1);
      
  4. Middleware Integration:

    • Protect routes with ShopifyMiddleware to ensure valid sessions:
      Route::middleware(['shopify'])->group(function () {
          Route::get('/dashboard', 'DashboardController@index');
      });
      

Integration Tips

  • Laravel Mix: Use the package’s assets (e.g., Polaris components) for Shopify-compliant UIs.
  • Testing: Mock Shopify responses with:
    $this->mockShopifyResponse('products', ['data' => []]);
    
  • Custom Endpoints: Extend the package by creating custom API handlers in app/Shopify/Handlers.

Gotchas and Tips

Pitfalls

  1. Deprecated Package:

  2. Session Management:

    • Ensure SHOPIFY_SESSION_DRIVER in .env matches your Laravel session driver (e.g., database).
    • Clear stale sessions manually if OAuth fails:
      Shopify::session()->forget();
      
  3. API Rate Limits:

    • Monitor usage with Shopify::billable() to avoid hitting Shopify’s limits.
    • Cache responses aggressively for read-heavy operations:
      $products = Cache::remember('shopify_products', now()->addHours(1), function () {
          return Shopify::get('products');
      });
      
  4. Webhook Verification:

    • Always verify webhook signatures:
      if (!Shopify::verifyWebhook(request()->header('X-Shopify-Hmac-Sha256'))) {
          abort(403);
      }
      

Debugging Tips

  • Enable Debug Mode:

    SHOPIFY_DEBUG=true
    

    Logs will appear in storage/logs/shopify.log.

  • Common Errors:

    • Invalid OAuth token: Regenerate API credentials in Shopify Partners Dashboard.
    • 404 Not Found: Ensure SHOPIFY_API_VERSION matches Shopify’s current API version.
    • Webhook Failures: Check SHOPIFY_WEBHOOK_SECRET in .env matches the Shopify app setting.

Extension Points

  1. Custom Handlers: Override default behavior by publishing and extending:

    php artisan vendor:publish --tag=shopify-views
    

    Modify resources/views/vendor/shopify/ templates.

  2. Event Listeners: Listen to Shopify events (e.g., Shopify\Events\WebhookReceived):

    public function handle(WebhookReceived $event)
    {
        // Process webhook data
    }
    
  3. API Extensions: Add custom API methods to the Shopify facade by binding a service provider:

    Shopify::extend(function ($app) {
        $app->singleton('shopify.custom', function () {
            return new CustomShopifyService();
        });
    });
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui