erkineren / shopware-sdk
[改进] Shopware 5 REST API 的 LeadCommerce PHP SDK。
1.0.2.1
2017-01-26 19:52 UTC
Requires
- php: >=5.5
- guzzlehttp/guzzle: ^6.2
Requires (Dev)
- phpunit/phpunit: ~4.8.21
- satooshi/php-coveralls: ~1.0.0
This package is auto-updated.
Last update: 2024-09-29 05:28:21 UTC
README
为 Shopware 5 REST API 编辑的 PHP SDK。
此仓库是从 leadcommerce/shopware-sdk 分支出来的,并进行了调整以使其可用。
与原始库相比,这个库额外提供了什么?
- 修复的 Bug(例如,创建实体方法的异常、未找到错误等)
- 编辑缺少的功能(例如,订单实体、方法参数)
- 改进查询(例如,过滤参数)
主要区别
-
查询响应
Query\Base
类。查询类不再从响应返回映射的实体。它们返回自身。为了获取与原始库类似的映射实体,您可以使用getEntity()
。现在您还有 3 个选项:)getEntity()
查询的实体类。从 JSON 响应返回映射的实体。getEntities()
查询的实体类数组。从 JSON 响应返回映射的实体。getRawResponse()
从 Shopware REST API 返回的原始字符串响应。getArrayResponse()
从 Shopware REST API 返回的原始 JSON 响应的解码关联数组。
-
NotValidApiResponseException createEntityFromResponse 方法解码 JSON 响应并继续自己的逻辑。如果您查询不存在的订单或 Shopware REST API 返回任何错误(非 JSON),程序将失败。但现在您可以捕获此错误。如果 JSON 解码过程中出现错误,将抛出此异常。
安装
composer require leadcommerce/shopware-sdk
composer require erkineren/shopware-sdk
示例
<?php require 'vendor/autoload.php'; // Create a new client $client = new ShopwareClient('http://shopware.dev/api/', 'user', 'api_key'); /** * set custom options for guzzle * the official guzzle documentation contains a list of valid options (http://docs.guzzlephp.org/en/latest/request-options.html) */ //$client = new ShopwareClient('http://shopware.dev/api/', 'user', 'api_key', ['cert' => ['/path/server.pem']]); // Fetch all articles $articles = $client->getArticleQuery()->findAll(); // NEW FEATURE Fetch all articles with filters $articles = $client->getArticleQuery()->findAll( [ 'filter' => [ [ 'property' => 'number', 'value' => 'SW0001' ] ] ] ); // Fetch one article by id $article = $client->getArticleQuery()->findOne(1); // NEW FEATURE Fetch one article by articlenumber $article = $client->getArticleQuery()->findOne('SW0001', true); // Create an article $article = new Article(); $article->setName("John product doe"); $article->setDescription("Lorem ipsum"); // ... <- more setters are required $client->getArticleQuery()->create($article); // Update article $article->setName("John product doe"); $updatedArticle = $client->getArticleQuery()->update($article)->getEntity(); // Update multiple articles $articleOne = $client->getArticleQuery()->findOne(1)->getEntity(); $articleOne->setName("John product doe"); $articleTwo = $client->getArticleQuery()->findOne(2)->getEntity(); $articleTwo->setName("John product doe 2"); $articles = $client->getArticleQuery()->updateBatch([$articleOne, $articleTwo])->getArrayResponse(); // Delete an article $client->getArticleQuery()->delete(1); // Delete multiple articles at once $client->getArticleQuery()->deleteBatch([1, 2, 3]); ?>
问题/功能建议
这里 是问题跟踪器。
贡献 :-)
- 阅读 行为准则
- 编写一些代码
- 编写一些测试