Giter Site home page Giter Site logo

martinhellgren / magento-laravel-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from grayloon/magento-laravel-api

0.0 0.0 0.0 286 KB

A simple Magento 2 REST API Object Oriented wrapper for Laravel applications.

License: MIT License

PHP 100.00%

magento-laravel-api's Introduction

Build Status Latest Stable Version Style CI Total Downloads License

Laravel - Magento API

A Magento 2 API Object Oriented wrapper for a Laravel application.

Installation

Install this package via Composer:

composer require grayloon/laravel-magento-api

Publish the config options:

php artisan vendor:publish --provider="Grayloon\Magento\MagentoServiceProvider" --tag="config"

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"

API Usage

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.

Available Methods:

Admin Token Integration (IntegrationAdminTokenServiceV1)

/V1/integration/admin/token

Generate a admin token:

$magento->api('integration')->adminToken($username, $password);

Carts

/V1/carts/mine

Returns information for the cart for the authenticated customer. Must use a single store code.

$magento->api('carts')->mine();

Cart Items (quoteCartItemRepositoryV1)

/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);

Cart Totals (quoteCartTotalRepositoryV1)

/V1/carts/mine/totals

Returns information for the cart totals for the authenticated customer. Must use a single store code.

$magento->api('cartTotals')->mine();

Categories (catalogCategoryManagementV1)

/V1/categories

Get a list of all categories:

$magento->api('categories')->all($pageSize = 50, $currentPage = 1, $filters = []);

Customer Token Integration (IntegrationCustomerTokenServiceV1)

/V1/integration/customer/token

Generate a customer token:

$magento->api('integration')->customerToken($username, $password);

Customers (customerCustomerRepositoryV1)

/V1/customers/search

Get a list of customers:

$magento->api('customers')->all($pageSize = 50, $currentPage = 1, $filters = []);

Guest Cart (various)

/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);

/V1/guest-carts/{cartId}/estimate-shipping-methods

Estimate shipping by address and return list of available shipping methods.

$magento->api('guestCarts')->estimateShippingMethods($cartId);

Product Attributes (catalogProductAttributeRepositoryV1)

/V1/products/attributes/{attributeCode}

Retrieve specific product attribute information:

$magento->api('productAttributes')->show($attributeCode);

Product Link Types (catalogProductLinkTypeListV1)

/V1/products/links/types

Retrieve information about available product link types:

$magento->api('productLinkType')->types();

Products (catalogProductRepositoryV1)

/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);

Custom modules

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');

Schema

Get a schema blueprint of the Magento 2 REST API:

$magento->api('schema')->show(); 

Source Items (inventoryApiSourceItemRepositoryV1)

/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 = []);

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

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

magento-laravel-api's People

Contributors

ahinkle avatar vincentbean avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.