霜18 / magento-client-php
一个消耗 Magento 的 REST 和 XMLRPC API 的 PHP 客户端库
1.0
2020-06-02 06:33 UTC
Requires
- php: >=5.3.3
- guzzlehttp/guzzle: ^6.0
- lstrojny/fxmlrpc: >=0.8,<0.9
Requires (Dev)
- pdepend/pdepend: ~1.0
- phploc/phploc: ~2.0
- phpmd/phpmd: ~1.0
- phpunit/phpunit: ~3.0
- satooshi/php-coveralls: *
- sebastian/phpcpd: ~2.0
This package is not auto-updated.
Last update: 2024-10-02 02:46:37 UTC
README
提供客户端库,用于向 Magento 实例发起 REST 和 XMLRPC 调用。
安装
可以使用 Composer 安装 PHP Magento 客户端库,将其作为项目 composer.json 文件中的依赖项添加。
{ "require": { "cpliakas/magento-client-php": "*" } }
在命令行运行 php composer.phar update
后,请在您的 PHP 脚本中包含自动加载器,以便 SDK 类可用。
require_once 'vendor/autoload.php';
有关更详细的安装和使用说明,请参阅 Composer 文档。
使用方法
XMLRPC
以下示例返回以 "123" 开头的 SKU 的产品列表
use Magento\Client\Xmlrpc\MagentoXmlrpcClient; $client = MagentoXmlrpcClient::factory(array( 'base_url' => 'http://magentohost', 'api_user' => 'api.user', 'api_key' => 'some.private.key', )); $filters = array( 'sku' => array('like' => '123%'), ); $result = $client->call('catalog_product.list', array($filters));
REST
以下示例返回产品列表
use Magento\Client\Rest\MagentoRestClient; $client = MagentoRestClient::factory(array( 'base_url' => 'http://magentohost', 'consumer_key' => 'abc123...', 'consumer_secret' => 'def456...', 'token' => 'ghi789...', 'token_secret' => 'jkl012...', )); $result = $client->get('/api/rest/products')->send()->json();
有关向服务器发送请求的更多信息,请参阅 Guzzle 文档。