Task #1 grayloon#55
Remember your job is to make incremental progress, break the task into smaller tasks, or finish something in 15 minutes, then pass it along to the next contributor. No responsibility, only fun.
When you have finished your 15 minutes, add your next task to the readme.md. Then make a pull request to the repo.
A Magento 2 API Object Oriented wrapper for a Laravel application.
Install this package via Composer:
composer require grayloon/laravel-magento-api
Publish the config options:
php artisan vendor:publish --provider="Grayloon\Magento\MagentoServiceProvider"
Configure your Magento 2 API endpoint and token in your .env
file:
MAGENTO_BASE_URL="https://mydomain.com"
MAGENTO_ACCESS_TOKEN="client_access_token_here"
# Optional Config:
MAGENTO_BASE_PATH="rest"
MAGENTO_STORE_CODE="all"
MAGENTO_API_VERSION="V1"
Example:
use Grayloon\Magento\Magento;
$magento = new Magento();
$response = $magento->api('products')->all();
$response->body() : string;
$response->json() : array|mixed;
$response->status() : int;
$response->ok() : bool;
Will throw an exception on >500 errors.
/V1/integration/admin/token
Generate a admin token:
Magento::api('integration')->adminToken($username, $password);
/V1/bundle-products/{sku}/options/all
Get all options for bundle product.
Magento::api('bundleProduct')->options($sku);
/V1/carts/mine
Returns information for the cart for the authenticated customer. Must use a single store code.
Magento::api('carts')->mine();
/V1/carts/mine/coupons/{couponCode}
Apply a coupon to a specified cart.
Magento::api('carts')->couponCode($couponCode);
/V1/carts/mine/items/
Lists items that are assigned to a specified customer cart. Must have a store code.
Magento::api('cartItems')->mine();
/V1/carts/mine/items/
Add/update the specified cart item with a customer token. Must have a store code.
Magento::api('cartItems')->addItem($cartId, $sku, $quantity);
put
- /V1/carts/mine/items/{itemId}
Update the specified cart item with a customer token. Must have a store code.
Magento::api('cartItems')->editItem($itemId, $body = []);
Remove the specified cart item with a customer token. Must have a store code.
Magento::api('cartItems')->removeItem($itemId);
/V1/carts/mine/totals
Returns information for the cart totals for the authenticated customer. Must use a single store code.
Magento::api('cartTotals')->mine();
/V1/categories
Get a list of all categories:
Magento::api('categories')->all($pageSize = 50, $currentPage = 1, $filters = []);
/V1/integration/customer/token
Generate a customer token:
Magento::api('integration')->customerToken($username, $password);
/V1/customers/search
Get a list of customers:
Magento::api('customers')->all($pageSize = 50, $currentPage = 1, $filters = []);
/V1/customers/password
Send an email to the customer with a password reset link.
Magento::api('customers')->password($email, $template, $websiteId);
/V1/customers/resetPassword
Reset customer password.
Magento::api('customers')->resetPassword($email, $resetToken, $newPassword);
/V1/guest-carts
Enable customer or guest user to create an empty cart and quote for an anonymous customer.
Magento::api('guestCarts')->create();
/V1/guest-carts/{cartId}
Return information for a specified cart.
Magento::api('guestCarts')->cart($cartId);
/V1/guest-carts/{cartId}/items
List items that are assigned to a specified cart.
Magento::api('guestCarts')->items($cartId);
/V1/guest-carts/{cartId}/items
Add/update the specified cart item.
Magento::api('guestCarts')->addItem($cartId, $sku, $quantity);
put
- /V1/guest-carts/{cartId}/items/{itemId}
Update the specified cart item.
Magento::api('guestCarts')->editItem($cartId, $itemId, $body = []);
Remove the specified cart item.
Magento::api('guestCarts')->removeItem($cartId, $itemId);
/V1/guest-carts/{cartId}/estimate-shipping-methods
Estimate shipping by address and return list of available shipping methods.
Magento::api('guestCarts')->estimateShippingMethods($cartId);
/V1/guest-carts/{cartId}/coupons/{couponCode}
Apply a coupon to a specified cart.
Magento::api('guestCarts')->couponCode($cartId, $couponCode);
Lists orders that match specified search criteria.
/V1/orders
Magento::api('orders')->all($pageSize = 50, $currentPage = 1, $filters = []);
/V1/orders/{id}
List a specified order:
Magento::api('orders')->show($orderId);
/V1/products/attributes/{attributeCode}
Retrieve specific product attribute information:
Magento::api('productAttributes')->show($attributeCode);
/V1/products/links/types
Retrieve information about available product link types:
Magento::api('productLinkType')->types();
/V1/products
Get a list of products:
Magento::api('products')->all($pageSize = 50, $currentPage = 1, $filters = []);
/V1/products/{sku}
Get info about a product by the product SKU:
Magento::api('products')->show($sku);
Magento modules can have their own API endpoints. For example:
<route method="POST" url="/V1/my-custom-endpoint/save">
...
</route>
<route method="GET" url="/V1/my-custom-endpoint/get/:id">
...
</route>
To use these you can directly use get/post methods:
Magento::api('my-custom-endpoint')->post('save', [...]);
Magento::api('my-custom-endpoint')->get('get/1');
Get a schema blueprint of the Magento 2 REST API:
Magento::api('schema')->show();
/V1/inventory/source-items
Get a list of paginated sort items (typically used for quantity retrieval):
Magento::api('sourceItems')->all($pageSize = 50, $currentPage = 1, $filters = []);
/V1/inventory/sources
Get a list of paginated sources.
Magento::api('sources')->all($pageSize = 50, $currentPage = 1, $filters = []);
/V1/inventory/sources/{$name}
Get a specified source.
Magento::api('sources')->bySourceName($name);
/V1/inventory/stocks
Get a list of paginated stocks.
Magento::api('stocks')->all($pageSize = 50, $currentPage = 1, $filters = []);
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email webmaster@grayloon.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.