palpalani / magento2-rest-api-client
v1.2.1
2022-03-16 13:42 UTC
Requires
- php: ^7.2|^8.0
- ext-curl: *
- ext-json: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^4.8
README
这是一个简单的PHP SDK库,可以轻松创建Rest API。
注意
:从版本1.2
开始,命名空间已更改。
安装
- 使用composer将其安装到您的Magento 2项目中
composer require palpalani/magento2-rest-api-client
- 启用模块
bin/magento setup:upgrade
示例用法
<?php require __DIR__ . '/vendor/autoload.php'; $service = new \Experius\Magento2ApiClient\Service\RestApi(); $service->setUsername('username'); $service->setPassword('password'); $service->setUrl('https://www.example.com/index.php/rest/%storecode/V1/'); // OPTIONAL > default = all $service->setStoreCode('default'); $service->init();
创建产品
$data = json_decode(' { "product": { "custom_attributes": [ { "attribute_code": "url_key", "value": "experius-example-product-new" } ], "name": "Experius Example Product", "weight": 1.2, "visibility": 4, "extension_attributes": { "website_ids": [ "1" ], "stock_item": { "is_in_stock": true } }, "sku": "experius-example-product", "status": 1, "type_id": "simple", "attribute_set_id": "4", "price": 10 } }'); $result = $service->call('products', $data, 'POST'); var_dump($result);
更新产品
$data = json_decode(' { "product": { "custom_attributes": [ { "attribute_code": "url_key", "value": "experius-example-product-new" } ], "name": "Experius Example Product", "weight": 1.2, "visibility": 4, "extension_attributes": { "website_ids": [ "1" ], "stock_item": { "is_in_stock": true } }, "sku": "experius-example-product", "status": 1, "type_id": "simple", "attribute_set_id": "4", "price": 10 } }'); $result = $service->call('products/experius-example-product', $data, 'PUT'); var_dump($result);
检索产品
$result = $service->call('products/experius-example-product'); var_dump($result); $dataArray = [ 'searchCriteria' => [ 'pageSize' => 10 ] ]; $result = $service->call('products', $dataArray); var_dump($result);
测试
单元测试
vendor/bin/phpunit tests/unit
变更日志
请参阅CHANGELOG以获取有关最近更改的更多信息。
贡献
请参阅CONTRIBUTING以获取详细信息。
安全漏洞
请查看我们的安全策略以了解如何报告安全漏洞。
致谢
许可
MIT许可(MIT)。请参阅许可文件以获取更多信息。