shoppingfeed / php-sdk
Shopping Feed SDK 用于简化我们API的集成
0.11.0
2024-09-19 12:00 UTC
Requires
- php: >=7.1
- ext-json: *
- symfony/deprecation-contracts: ^2.5|^3.0
Requires (Dev)
- guzzlehttp/guzzle: ^6.0 | ^7.0
- monolog/monolog: ^1.23
- overtrue/phplint: ^1.1
- phpunit/phpunit: ^7.0 | ^9.0
- shoppingfeed/coding-style-php: ~2.1.0
Suggests
- guzzlehttp/guzzle: Guzzle Http 6 is the default http adapter integrated in the SDK
- psr/log: trace HTTP requests performed by the SDK
- shoppingfeed/php-feed-generator: Generates compliant Shopping-Feed XML feed with ease
- dev-master
- 0.11.0
- 0.10.0
- 0.9.0
- 0.8.0
- 0.7.0
- 0.6.0
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.7
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2-beta.1
- 0.2.1-beta.1
- 0.2.0-beta.1
- dev-view-all-orderitem-properties
- dev-add-cursor-hallink
- dev-SFCORE-2829
- dev-SFCORE-2849
- dev-fix_type_issue
- dev-retry-on-499
- dev-fix_rejected_callback
- dev-php71-upgrade
- dev-fix_php81_deprecation
- dev-olivierh94-github-action-php
- dev-add_missing_store_fields
- dev-client-adapter
- dev-handle_body_for_delete
- dev-fix_empty_response
This package is auto-updated.
Last update: 2024-09-19 12:03:07 UTC
README
安装
- 在你的项目根仓库运行
composer require shoppingfeed/php-sdk
- 安装你选择的http客户端,我们推荐使用GuzzleHttp 6,因为SDK集成了对该客户端的适配器。
composer require guzzlehttp/guzzle ^6.3
如果你已经在项目中有一个http客户端库,你也可以开发自己的适配器(更多信息请参阅http适配器文档)。
这将把SDK库加载到vendor
仓库中。
根据PSR-4规范,你应该能够在\ShoppingFeed\Sdk
命名空间下访问SDK。
基本使用
使用SDK的基本有三个步骤:
- 身份验证以启动新会话
- 从会话中检索你想要管理的店铺
- 管理资源
API身份验证
Shopping Feed API要求你必须进行身份验证才能执行任何调用。
为了执行认证调用,你应该像这样构建客户端
<?php namespace ShoppingFeed\Sdk; // Setup credentials to connect to the API, and create session $credential = new Credential\Token('api-token'); /** @var \ShoppingFeed\Sdk\Api\Session\SessionResource $session */ $session = Client\Client::createSession($credential);
访问你的店铺
/** @var \ShoppingFeed\Sdk\Api\Session\SessionResource $session */ $store = $session->selectStore(1276); $store->getName(); // test-store $store->getId(); // 1276 // ... and so on
如果你管理多个店铺,你可以使用店铺集合对象
/** @var \ShoppingFeed\Sdk\Api\Session\SessionResource $session */ // Get store collection $stores = $session->getStores(); // Count the number of stores [int] $stores->count(); // Get a particular store $store = $stores->select('id-or-store-name'); // Loop over available stores foreach ($stores as $store) { $store->getName(); }
SDK指南
SDK资源文档
生成符合XML规范的导入用feed
SDK能够通过提供必要的工具来简化XML feed的创建。
请查看https://github.com/shoppingflux/php-feed-generator上的文档,了解如何创建符合规范的feed。