ptchr / magento2-rest-client
Magento 2 rest api 客户端
2.14
2023-05-09 10:57 UTC
Requires
- php: ^7.2|^8
- ext-json: *
- guzzlehttp/guzzle: ^6|^7
- nesbot/carbon: ^2.36
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- phpunit/phpunit: ^9.0
- symfony/var-dumper: ^5.1
- vimeo/psalm: ^3.11
This package is auto-updated.
Last update: 2024-09-09 13:57:06 UTC
README
安装
通过 Magento 2 REST API 简化 API 调用
您可以通过 composer 安装此包
composer require ptchr/magento2-rest-client
使用方法
初始化客户端
$client = new Ptchr\Magento2RestClient\Client('BASE_URL', 'ADMIN_USERNAME', 'ADMIN_PASSWORD');
通过电子邮件搜索客户
$customer = $client->searchCustomerByEmail('john@example.com');
搜索订单
Magento 文档:https://magento.redoc.ly/2.3.5-admin/#operation/salesOrderRepositoryV1GetListGet
$orders = $this->client->getOrders($currentPage, $resultsPerPage, $filters, $sort);
创建购物车实例
$quoteId = $client->createCart($customer['id']);
将产品添加到购物车
$cart = $client->addProductToCart($quoteId, 'SKU', 3);
估算购物车的可用配送方式
$shippingMethods = $client->estimateAvailableShippingMethodsForCart($customer, $quoteId);
将配送信息添加到购物车
$shippingInfo = $client->addShippingInformationToCart($customer, $quoteId);
使用选定的配送方式添加配送信息
$shippingMethods = $client->estimateAvailableShippingMethodsForCart($customer, $quoteId); $shippingMethod = $shippingMethods[0]; $shippingInfo = $client->addShippingInformationToCart($customer, $quoteId, $shippingMethod['method_code'], $shippingMethod['carrier_code']);
获取购物车的可用支付方式
$paymentMethods = $this->client->getAvailablePaymentMethodsForCart($quoteId);
设置支付信息
$this->client->setPaymentInformation($quoteId, $paymentMethod);
使用采购订单号设置支付信息
$this->client->setPaymentInformation($quoteId, $paymentMethod, 'purchase_order_number');
创建订单
$orderId = $client->createOrder($quoteId, $paymentMethod);
使用采购订单号
$orderId = $client->createOrder($quoteId, $paymentMethod, '123');
为订单创建完整发票
Paid: $client->fullInvoiceOrder($orderId, true); Not paid: $client->fullInvoiceOrder($orderId, false);
发货订单
$orderId = $client->shipOrder($orderId);
取消订单
$client->cancelOrder($orderId);
测试
composer test
变更日志
请参阅 CHANGELOG 以获取更多最近更改的信息。
贡献
请参阅 CONTRIBUTING 获取详细信息。
鸣谢
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 以获取更多信息。