• Stars
    star
    127
  • Rank 281,971 (Top 6 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 7 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🚀 Shopify API Client for PHP

🚀 PHP SDK for the Shopify API

Software License Build Status Coverage Status Latest Stable Version Scrutinizer Total Downloads

Installation

Install via composer

$ 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

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('your-store.myshopify.com', $credential, [
    'meta_cache_dir' => './tmp' // Metadata cache dir, required
]);

Middleware

Middleware augments the functionality of handlers by invoking them in the process of generating responses. Middleware is implemented as a higher order function that takes the following form.

$middleware = function(\Psr\Http\Message\ServerRequestInterface $request, callable $next){
    $response = $next($request);
    $this->logger->log($request, $response);
    return $response;
};

$client->getMiddlewares()->push($middleware);

Built-in middleware:

Exception

The Client throws the following types of exceptions.

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:

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

Available managers:

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

Basic CURD

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

The returned value is just an array;

$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" => "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAw==\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" => "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAw==\n"
            ]
        ]
     ]
]);

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

LICENSE

The MIT license. See MIT

More Repositories

1

spike

📣 A fast reverse proxy written in PHP that helps to expose local services to the internet
PHP
660
star
2

composer-registry-manager

🛠️ 🔨 Composer registry manager that help to easily switch to the composer repository you want.
PHP
533
star
3

smartqq

🐧 SmartQQ (原 WebQQ ) API 的 PHP 语言实现,提供了一系列更优雅可读性更高的API
PHP
82
star
4

youzan-pay

基于有赞云和有赞微小店实现个人收款解决方案。
PHP
69
star
5

China

🇨🇳 一个轻巧的中国的地区、民族以及节假日信息的查询PHP库
PHP
55
star
6

shipment-tracking

✨ A flexible shipment tracking library for multi carriers like DHL eCommerce, USPS, YanWen Express, Epacket, E包裹, E特快, 国际EMS, 快递100,递四方 etc.
PHP
26
star
7

process

🐋 The process wrapper and manager based on PCNTL on the Unix-like systems using php
PHP
22
star
8

di

🐑 A flexible dependency injection container; It is an implementation of PSR-11
PHP
20
star
9

social-share.js

🎉 一个可以帮助快速创建社交网站分享按钮的轻巧的 JavaScript 组件
JavaScript
18
star
10

spike-go

📣 A fast reverse proxy written in golang that helps to expose local services to the internet
Go
17
star
11

sql-to-markdown

Convert mysql table schema to markdown table.
PHP
16
star
12

middleware

🐳 A PSR15 middleware dispatcher
PHP
15
star
13

expression-language.js

🌴 An engine that can compile and evaluate expressions written in typescript
TypeScript
10
star
14

event-dispatcher

🔥 A flexible event dispatching library for PHP
PHP
9
star
15

tree-samples

PHP遍历二叉树的实现,深度优先,广度优先,非递归实现;
PHP
9
star
16

cakephp-permission

🍰 The role-based permissions management for CakePHP 3 🥞
PHP
9
star
17

spider

爬虫组件
PHP
8
star
18

config

🎍 A flexible configuration file loader that supports multiple file formats
PHP
8
star
19

composer-alias

🎸 Composer Alias Plugin
PHP
7
star
20

framework

The Slince PHP framework
PHP
7
star
21

mechanic

基于PHP的自动化测试框架
PHP
6
star
22

routing

🐬 A flexible web routing component.
PHP
5
star
23

shipment-tracking-foundation

✨ A flexible and shipment tracking library for multi carriers
PHP
5
star
24

upload

Process file uploads with multiple and extensible validation rules.
PHP
4
star
25

cakephp-pjax

🥞 Pjax plugin for CakePHP
PHP
4
star
26

hello-vm

一个超级mini的栈式虚拟机
Java
2
star
27

cycle-bundle

Symfony Bundle for Cycle ORM and DBAL
PHP
2
star
28

expression

🚀 一个富有语言表现力的表达式引擎的 Java 实现
Java
2
star
29

switchery.js

Annother IOS 7 style switches for your checkboxes
JavaScript
2
star
30

fastserver

PHP
1
star
31

golang-lesson

Go 语言练习
Go
1
star
32

dragbox

基于 Socket 的私有网盘系统
PHP
1
star