ptchr / magento2-rest-client
Magento 2 rest api client
Installs: 1 319
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 3
Open Issues: 1
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-11-09 14:24:01 UTC
README
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.