2017 © Pedro Peláez
 

library shopify-php-sdk

PHP SDK for Shopify API

image

robwittman/shopify-php-sdk

PHP SDK for Shopify API

  • Wednesday, July 4, 2018
  • by BugattiRob
  • Repository
  • 3 Watchers
  • 12 Stars
  • 2,123 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 8 Forks
  • 7 Open issues
  • 12 Versions
  • 92 % Grown

The README.md

Build Status, (*1)

Shopify PHP SDK

This SDK was created to enable rapid efficient development using Shopify's API., (*2)

Installation

Easily install this package with composer, (*3)

composer require robwittman/shopify-php-sdk

Before you can start using this SDK, you have to create a Shopify Application You can now use the API key and secret to generate access tokens, which can then access a stores data, (*4)

Initialization

To initialize the Api Client:, (*5)

$client = new Shopify\Api(array(
    'api_key' => '<api_key>',
    'api_secret' => '<api_secret>',
    'myshopify_domain' => 'store.myshopify.com',
    'access_token' => '<store_access_token>'
));

If you are using a Private App for use on an individual store:, (*6)

$client = new Shopify\PrivateApi(array(
    'api_key' => '<api-key>',
    'password' => '<password>',
    'shared_secret' => '<shared-secret>',
    'myshopify_domain' => '<store>.myshopify.com'
));

Once the client is initialized, you can then create a service, and use it to communicate with the api, (*7)

Reading

$service = new Shopify\Service\ProductService($client);
$service->all(); #Fetch all products, with optional params
$service->get($productId); # Get a single product
$service->count(); # Count the resources

Creating

$service = new Shopify\Service\ProductService($client);
$product = new Shopify\Object\Product();
# Set some product fields
$product->title = 'Test Product';
$product->vendor = 'Printer';

$service->create($product);

Updating

$service = new Shopify\Service\ProductService($client);
$product = $service->get($productId);
# Set some product fields
$product->title = 'Test Product';
$product->vendor = 'Printer';

$service->update($product);

Deleting

$service = new Shopify\Service\ProductService($client);
$service->delete($productId);

GraphQL

Query

$service = new Shopify\Service\GraphQLService($client);
$service->graph(
  '{
    products(query: "created_at:<2019", first: 5) {
      edges {
        node {
          title
          description
        }
      }
    }
  }'
);

Mutation

$service = new Shopify\Service\GraphQLService($client);
$service->graph(
  'mutation productCreate($input: ProductInput!){
    productCreate(input: $input) {
      product {
        id
      }
    }
  }',
  ['input' => ['title' => 'Sweet new product','productType' => 'Snowboard','vendor' => 'JadedPixel']]
);

Authentication

Authentication to Shopify's API is done through access tokens, which are obtained through OAuth. To get a token, there is a helper library packaged with this client, (*8)

$client = new Shopify\Api($params);
$helper = $client->getOAuthHelper();

$redirectUri = 'https://localhost/install.php';
$scopes = 'write_products,read_orders,...';

$authorizationUrl = $helper->getAuthorizationUrl($redirectUri, $scopes);
header("Location: {$authorizationUrl}");

At your redirect_uri, instantiate the helper again to get an access token, (*9)

$client = new Shopify\Api($params);
$helper = $client->getOAuthHelper();

$token = $helper->getAccessToken($code);
echo $token->access_token;
echo $token->scopes;

By default, this uses simple session storage. You can implement a custom class that implements PersistentStorageInterface, pass that to new Shopify\Api(), and OAuthHelper will use that instead. This will be required if authorization requests and redirects may be directed to different servers., (*10)

Using objects

Object properties can be accessed using object->property. Nested objects are instantiated classes. All timestamp fields are instances of \DateTime., (*11)

use Shopify\Enum\Fields\ProductFields;
use Shopify\Enum\Fields\ProductVariantFields;

$product = $service->get($productId);
echo $product->created_at->format('Y-m-d H:i:s');
echo $product->title;

foreach ($product->variants as $variant) {
    echo $variant->option1;
    echo $variant->option2;
}

References

Shopify Partner Login, (*12)

Shopify API Reference, (*13)

The Versions

04/07 2018

dev-add-price-rule-service

dev-add-price-rule-service http://github.com/robwittman/shopify-php-sdk

PHP SDK for Shopify API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php ecommerce shopify

12/12 2017

dev-master

9999999-dev http://github.com/robwittman/shopify-php-sdk

PHP SDK for Shopify API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php ecommerce shopify

12/12 2017

v2.1.0

2.1.0.0 http://github.com/robwittman/shopify-php-sdk

PHP SDK for Shopify API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php ecommerce shopify

12/12 2017

dev-fix-old-files

dev-fix-old-files http://github.com/robwittman/shopify-php-sdk

PHP SDK for Shopify API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php ecommerce shopify

24/09 2017

dev-update-class-management

dev-update-class-management http://github.com/robwittman/shopify-php-sdk

PHP SDK for Shopify API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php ecommerce shopify

02/09 2017

dev-fix-some-issues

dev-fix-some-issues http://github.com/robwittman/shopify-php-sdk

PHP SDK for Shopify API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php ecommerce shopify

30/06 2017

v2.0.0

2.0.0.0 http://github.com/robwittman/shopify-php-sdk

PHP SDK for Shopify API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php ecommerce shopify

30/06 2017

dev-v2-rewrite

dev-v2-rewrite http://github.com/robwittman/shopify-php-sdk

PHP SDK for Shopify API

  Sources   Download

MIT

The Requires

 

The Development Requires

api php ecommerce shopify

06/07 2016

v1.0.3

1.0.3.0 http://github.com/RobbyBugatti/shopify-php-sdk

PHP SDK for Shopify API

  Sources   Download

MIT

The Requires

  • php >=5.3.3
  • ext-curl *
  • ext-json *

 

The Development Requires

api php ecommerce shopify

15/06 2016

v1.0.2

1.0.2.0 http://github.com/RobbyBugatti/shopify-php-sdk

PHP SDK for Shopify API

  Sources   Download

MIT

The Requires

  • php >=5.3.3
  • ext-curl *
  • ext-json *

 

The Development Requires

api php ecommerce shopify

10/05 2016

v1.0.1

1.0.1.0 http://github.com/RobbyBugatti/shopify-php-sdk

PHP SDK for Shopify API

  Sources   Download

MIT

The Requires

  • php >=5.3.3
  • ext-curl *
  • ext-json *

 

The Development Requires

api php ecommerce shopify

10/05 2016

v1.0.0

1.0.0.0 http://github.com/RobbyBugatti/shopify-php-api

PHP SDK for Shopify API

  Sources   Download

MIT

The Requires

  • php >=5.3.3
  • ext-curl *
  • ext-json *

 

The Development Requires

api php ecommerce shopify