Intializing the client

You can initialize the client in different ways to start communicating with the Shopify API.

use Pactode\Shopify\Shopify;

$shopify = new Shopify(
    env('SHOPIFY_ACCESS_TOKEN'),
    env('SHOPIFY_DOMAIN'),
    env('SHOPIFY_API_VERSION')
);

Resolve from the service container

Using class:

use Pactode\Shopify\Shopify;

$shopify = app(Shopify::class);

Using alias:

$shopify = app('shopify');

Resolve using the factory

$shopify = \Pactode\Shopify\Factory::fromConfig();

Resolve using dependency injection

You may also inject the Shopify class into a method of a Controller:

use Illuminate\Http\Request;
use Pactode\Shopify\Shopify;

class ProductController{
    public function index(Request $request, Shopify $shopify)
    {
        // do something here    
    }
}

By default it will look for credentials in your config, when resolving the client.

Last updated