2017 © Pedro Peláez
 

library shopify-api-php

Shopify API Client for PHP

image

slince/shopify-api-php

Shopify API Client for PHP

  • Monday, July 23, 2018
  • by slince
  • Repository
  • 4 Watchers
  • 11 Stars
  • 379 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 3 Open issues
  • 7 Versions
  • 124 % Grown

The README.md

, (*1)

:rocket: PHP SDK for the Shopify API, (*2)

Software License Build Status Coverage Status Latest Stable Version Scrutinizer , (*3)

Installation

Install via composer, (*4)

$ composer require slince/shopify-api-php

Quick Start

Initialize the client

You first need to initialize the client. For that you need your Shop Name and AccessToken, (*5)

require __DIR__ . '/vendor/autoload.php';

$credential = new Slince\Shopify\PublicAppCredential('Access Token');
// Or Private App
$credential = new Slince\Shopify\PrivateAppCredential('API KEY', 'PASSWORD', 'SHARED SECRET');

$client = new Slince\Shopify\Client($credential, 'your-store.myshopify.com', [
    'metaCacheDir' => './tmp', // Metadata cache dir, required
    'apiVersion' => '2020-01' // API version
]);

Use Manager to manipulate your data;

  • Lists products
$products = $client->getProductManager()->findAll([
    // Filter your product
    'collection_id' => 841564295
    'page' => 2 // deprecated
]);
  • Lists products by pagination
$pagination = $client->getProductManager()->paginate([
    // filter your product
    'limit' => 3,
    'created_at_min' => '2015-04-25T16:15:47-04:00'
]);
// $pagination is instance of `Slince\Shopify\Common\CursorBasedPagination`

$currentProducts = $pagination->current(); //current page

while ($pagination->hasNext()) {
    $nextProducts = $pagination->next();
}

# to persist across requests you can use next_page_info and previous_page_info
$nextPageInfo = $pagination->getNextPageInfo();
$prevPageInfo = $pagination->getPrevPageInfo();

$products = $pagination->current($nextPageInfo);
  • Get the specified product
$product = $client->getProductManager()->find(12800);

// Update the given product
$product = $client->getProductManager()->update(12800, [
      "title" => "Burton Custom Freestyle 151",
      "body_html" => "<strong>Good snowboard!<\/strong>",
      "vendor"=> "Burton",
      "product_type" => "Snowboard",
]);
  • Creates a new product
$product = $client->getProductManager()->create([
      "title" => "Burton Custom Freestyle 151",
      "body_html" => "<strong>Good snowboard!<\/strong>",
      "vendor"=> "Burton",
      "product_type" => "Snowboard",
]);
  • Removes the product by its id
$client->getProductManager()->remove(12800);

The product is an instance of Slince\Shopify\Manager\Product\Product; You can access properties like following:, (*6)

echo $product->getTitle();
echo $product->getCreatedAt(); // DateTime Object
//...
print_r($product->getVariants());
print_r($product->getImages());

Available managers:, (*7)

You can access the manager like $client->getProductManager(), $client->getOrderManager()., (*8)

Basic CURD

If you don't like to use managers, you can also manipulate data like this:, (*9)

The returned value is just an array;, (*10)

$products = $client->get('products', [
    // Filter your products
]);

$product = $client->get('products/12800');

$product = $client->post('products', [
    "product" => [
        "title" => "Burton Custom Freestyle 151",
        "body_html" => "<strong>Good snowboard!<\/strong>",
        "vendor"=> "Burton",
        "product_type" => "Snowboard",
        "images" => [
            [ 
                "attachment" => "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\n"
            ]
        ]
     ]
]);

$product = $client->put('products/12800', [
    "product" => [
        "title" => "Burton Custom Freestyle 151",
        "body_html" => "<strong>Good snowboard!<\/strong>",
        "vendor"=> "Burton",
        "product_type" => "Snowboard",
        "images" => [
            [ 
                "attachment" => "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\n"
            ]
        ]
     ]
]);

$client->delete('products/12800');

LICENSE

The MIT license. See MIT, (*11)

The Versions

23/07 2018

dev-master

9999999-dev

Shopify API Client for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by tao

rest shopify shopify-api shopify-sdk shopify-client shopify-client-php

23/07 2018

2.0.3

2.0.3.0

Shopify API Client for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by tao

rest shopify shopify-api shopify-sdk shopify-client shopify-client-php

05/06 2018

2.0.2

2.0.2.0

Shopify API Client for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by tao

rest shopify shopify-api shopify-sdk shopify-client shopify-client-php

29/05 2018

2.0.1

2.0.1.0

Shopify API Client for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by tao

rest shopify shopify-api shopify-sdk shopify-client shopify-client-php

31/01 2018

2.0.0-beta1

2.0.0.0-beta1

Shopify API Client for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by tao

rest shopify shopify-api shopify-sdk shopify-client shopify-client-php

29/11 2017

1.0.0-beta2

1.0.0.0-beta2

Shopify API Client for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by tao

rest shopify shopify-api shopify-sdk shopify-client shopify-client-php

29/11 2017

1.0.0-beta1

1.0.0.0-beta1

Shopify API Client for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by tao

rest shopify shopify-api shopify-sdk shopify-client shopify-client-php