ptchr/magento2-rest-client

Magento 2 rest api client

2.14 2023-05-09 10:57 UTC

README

Latest Version on Packagist Tests Total Downloads

Installation

Streamlines API calls through the Magento 2 REST API

You can install the package via composer:

composer require ptchr/magento2-rest-client

Usage

Intitialize client

$client = new Ptchr\Magento2RestClient\Client('BASE_URL', 'ADMIN_USERNAME', 'ADMIN_PASSWORD');

Search customer by email

$customer = $client->searchCustomerByEmail('john@example.com');

Search orders

Magento docs: https://magento.redoc.ly/2.3.5-admin/#operation/salesOrderRepositoryV1GetListGet

$orders = $this->client->getOrders($currentPage, $resultsPerPage, $filters, $sort);

Create cart instance

$quoteId = $client->createCart($customer['id']);

Add product to cart

$cart = $client->addProductToCart($quoteId, 'SKU', 3);

Estimate available shipping methods for cart

$shippingMethods = $client->estimateAvailableShippingMethodsForCart($customer, $quoteId);

Add shipping information to cart

$shippingInfo = $client->addShippingInformationToCart($customer, $quoteId);

Add shipping information with selected shipping method

$shippingMethods = $client->estimateAvailableShippingMethodsForCart($customer, $quoteId);
$shippingMethod = $shippingMethods[0];
$shippingInfo = $client->addShippingInformationToCart($customer, $quoteId, $shippingMethod['method_code'], $shippingMethod['carrier_code']);

Get available payment methods for cart

$paymentMethods = $this->client->getAvailablePaymentMethodsForCart($quoteId);

Set payment information

$this->client->setPaymentInformation($quoteId, $paymentMethod);

Set payment information with purchase order number

$this->client->setPaymentInformation($quoteId, $paymentMethod, 'purchase_order_number');

Create order

$orderId = $client->createOrder($quoteId, $paymentMethod);

With purchase order number

$orderId = $client->createOrder($quoteId, $paymentMethod, '123');

Create full invoice for order

Paid:
$client->fullInvoiceOrder($orderId, true);

Not paid:
$client->fullInvoiceOrder($orderId, false);

Ship order

$orderId = $client->shipOrder($orderId);

Cancel order

$client->cancelOrder($orderId);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.