palpalani/magento2-rest-api-client
最新稳定版本:v1.2.1
Composer 安装命令:
composer require palpalani/magento2-rest-api-client
包简介
README 文档
README
This is a simple PHP SDK lib to easily create Rest API.
Note: From the version 1.2 and above the Namespace was changed.
Installation
- Install it into your Magento 2 project with composer:
composer require palpalani/magento2-rest-api-client
- Enable module
bin/magento setup:upgrade
Example usage
<?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();
Create product
$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);
Update product
$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);
Retrieve product
$result = $service->call('products/experius-example-product'); var_dump($result); $dataArray = [ 'searchCriteria' => [ 'pageSize' => 10 ] ]; $result = $service->call('products', $dataArray); var_dump($result);
Testing
Unit Tests
vendor/bin/phpunit tests/unit
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 20.95k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-04-30