PHP code example of ptchr / magento2-rest-client

1. Go to this page and download the library: Download ptchr/magento2-rest-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ptchr / magento2-rest-client example snippets

 php
$client = new Ptchr\Magento2RestClient\Client('BASE_URL', 'ADMIN_USERNAME', 'ADMIN_PASSWORD');
 php
$customer = $client->searchCustomerByEmail('[email protected]');
 php
$orders = $this->client->getOrders($currentPage, $resultsPerPage, $filters, $sort);
 php
$quoteId = $client->createCart($customer['id']);
 php
$cart = $client->addProductToCart($quoteId, 'SKU', 3);
 php
$shippingMethods = $client->estimateAvailableShippingMethodsForCart($customer, $quoteId);
 php
$shippingInfo = $client->addShippingInformationToCart($customer, $quoteId);
 php
$shippingMethods = $client->estimateAvailableShippingMethodsForCart($customer, $quoteId);
$shippingMethod = $shippingMethods[0];
$shippingInfo = $client->addShippingInformationToCart($customer, $quoteId, $shippingMethod['method_code'], $shippingMethod['carrier_code']);
 php
$paymentMethods = $this->client->getAvailablePaymentMethodsForCart($quoteId);
 php
$this->client->setPaymentInformation($quoteId, $paymentMethod);
 php
$this->client->setPaymentInformation($quoteId, $paymentMethod, 'purchase_order_number');
 php
$orderId = $client->createOrder($quoteId, $paymentMethod);
 php
$orderId = $client->createOrder($quoteId, $paymentMethod, '123');
 php
Paid:
$client->fullInvoiceOrder($orderId, true);

Not paid:
$client->fullInvoiceOrder($orderId, false);
 php
$orderId = $client->shipOrder($orderId);
 php
$client->cancelOrder($orderId);