robwittman/shopify-php-sdk
Composer 安装命令:
composer require robwittman/shopify-php-sdk
包简介
PHP SDK for Shopify API
关键字:
README 文档
README
Shopify PHP SDK
This SDK was created to enable rapid efficient development using Shopify's API.
Installation
Easily install this package with composer
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
Initialization
To initialize the Api Client:
$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:
$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
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
$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
$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.
Using objects
Object properties can be accessed using object->property. Nested objects are instantiated classes. All timestamp fields are instances of \DateTime.
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
robwittman/shopify-php-sdk 适用场景与选型建议
robwittman/shopify-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 102.89k 次下载、GitHub Stars 达 70, 最近一次更新时间为 2017 年 06 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「ecommerce」 「api」 「shopify」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 robwittman/shopify-php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 robwittman/shopify-php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 robwittman/shopify-php-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Nevogate Payment Gateway SDK
Dealing with payments through the Egyptian payment gateway PayMob
A PSR-7 compatible library for making CRUD API endpoints
A PHP (and Laravel) package to interface with the Snipcart api.
Alfabank REST API integration
Customer notes for Contao Isotope eCommerce checkout.
统计信息
- 总下载量: 102.89k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 71
- 点击次数: 10
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-06-30