Code Monkey home page Code Monkey logo

magento-laravel-api's Introduction

Note: This package is no longer maintained. Please use the justbetter/laravel-magento-client package.

Build Status Latest Stable Version Style CI Total Downloads License

Laravel - Magento API

About

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"

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.

You may also utilize the constructor directly without having to configure environment variables:

use Grayloon\Magento\Magento;

$magento = new Magento(
    $baseUrl = 'https://my-magento-shop.com',
    $token = 'client_access_token',
    $version = 'V1',
    $basePath = 'rest',
    $storeCode = 'default'
);

$response = $magento->api('products')->all();

Available Methods:

Admin Token Integration (IntegrationAdminTokenServiceV1)

/V1/integration/admin/token

Generate a admin token:

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

Bundle Product Options (bundleProductOptionRepositoryV1)

/V1/bundle-products/{sku}/options/all

Get all options for bundle product.

Magento::api('bundleProduct')->options($sku);

Carts

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

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

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

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 (various)

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

Customer Groups

GET /V1/customerGroups/{id}

Show the customer group by the provided ID.

Magento::api('customerGroups')->show($id);

PUT /V1/customerGroups/{id}

Save the customer group by the provided ID.

Magento::api('customerGroups')->saveGroup($id, $customerGroupRepositoryV1SavePutBody = []);

DELETE /V1/customerGroups/{id}

Delete customer group by the provided ID.

Magento::api('customerGroups')->deleteGroup($id);

POST /V1/customerGroups

Save/Create Customer Group.

Magento::api('customerGroups')->createGroup($customerGroupRepositoryV1SavePostBody = []);

GET /V1/customerGroups/search

Search the Customer Groups.

Magento::api('customerGroups')->search($pageSize = 50, $currentPage = 1, $filters = []);

GET /V1/customerGroups/default

Get the default customer group.

Magento::api('customerGroups')->default();

PUT /V1/customerGroups/default/{id}

Set the default customer group.

Magento::api('customerGroups')->setDefault($id);

GET /V1/customerGroups/{id}/permissions

Determine if customer group can be deleted.

Magento::api('customerGroups')->permissions($id);

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

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

/V1/guest-carts/{cartId}

Assign a specified customer to a specified shopping cart.

Magento::api('guestCarts')->assignCustomer($cartId, $customerId, $storeId);

Orders (salesOrderRepositoryV1)

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/orders

Performs persist operations for a specified order.

Magento::api('orders')->edit($entity = []);

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

Sources (inventoryApiSourcesRepositoryV1)

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

Stocks (inventoryApiStocksRepositoryV1)

/V1/inventory/stocks

Get a list of paginated stocks.

Magento::api('stocks')->all($pageSize = 50, $currentPage = 1, $filters = []);

Store (storeGroupRepositoryV1)

/V1/store/storeConfigs

Get a list of store configs.

Magento::api('store')->storeConfigs();

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 infinityse avatar jeroen-hso avatar jonathanribas avatar matt-gribben avatar matusstafura avatar mushood avatar ramonrietdijk avatar shoeyn avatar vincentbean avatar zkimffm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

magento-laravel-api's Issues

Magento 2.4.4 support

We are upgrading to Magento 2.4.4 and authorization is not working in staging environment. Is this related to #86? Is there a workaround to use this package with Magento 2.4.4?

Thanks in advance for your help.

Changes to use configs from constructor for multiple stores purpose.

Hi i think that would be best for use the wrapper if had the option of using the settings from constructor and not only from environment or laravel configs, by example:

public function __construct($baseUrl = null, $token = null, $version = null, $basePath = null, $storeCode = null)
{
    $this->baseUrl = $baseUrl ?: config('magento.base_url');
    $this->token = $token ?: config('magento.token');
    $this->version = $version ?: config('magento.version') ?: 'V1';
    $this->basePath = $basePath ?: config('magento.base_path') ?: 'rest';
    $this->storeCode = $storeCode ?: config('magento.store_code') ?: 'all';
}

Filtering data

$response = $magento->api('orders')->all($pageSize = 1, $currentPage = 1, $filters = ["created_at&searchCriteria[filter_groups][0][filters][0][value]=2016-07-01 00:00:00"]);
so i have tried almost everything I can think of to filter the data would you please explain the right way thanks

Looking for maintainers

Hi everyone,

We have discontinued working with Magento in favor of other platforms. We are looking for maintainers to take over this package.

Interested? Drop a comment here or email me at [email protected].

Thanks!

Use Magento:: facade

Adopt the Laravel Facade, Magento::class to use methods statically.

e.g.
Instead of:

$magento = new Magento();
$response = $magento->api('products')->all();

Use:

$magento = Magento::api('products')->all();

laravel 9 support

I'm having an issue updating to laravel 9
Problem 1
- illuminate/support[v7.0.0, ..., v7.28.4] require php ^7.2.5 -> your php version (8.1.6) does not satisfy that requirement.
- illuminate/support[v8.0.0, ..., v8.11.2] require php ^7.3 -> your php version (8.1.6) does not satisfy that requirement.
- Root composer.json requires grayloon/laravel-magento-api ^0.9.0 -> satisfiable by grayloon/laravel-magento-api[0.9.0, 0.9.1].
- Conclusion: don't install laravel/framework v9.0.0-beta.2 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.0.0-beta.3 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.0.0-beta.4 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.0.0-beta.5 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.0.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.0.1 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.0.2 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.1.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.2.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.3.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.3.1 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.4.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.4.1 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.5.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.5.1 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.6.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.7.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.8.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.8.1 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.9.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.10.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.10.1 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.11.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.12.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.12.1 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.12.2 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.13.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.14.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.14.1 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.15.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.16.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.17.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.18.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.19.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.20.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.21.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.21.1 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.21.2 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.21.3 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.21.4 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.21.5 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.21.6 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.22.0 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.22.1 (conflict analysis result)
- Conclusion: don't install laravel/framework v9.0.0-beta.1 (conflict analysis result)
- grayloon/laravel-magento-api[0.9.0, ..., 0.9.1] require illuminate/support ^7.0|^8.0 -> satisfiable by illuminate/support[v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev].
- Only one of these can be installed: illuminate/support[dev-master, v5.0.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev, v9.0.0-beta.1, ..., 9.x-dev], laravel/framework[v9.0.0-beta.1, ..., 9.x-dev]. laravel/framework replaces illuminate/support and thus cannot coexist with it.
- Root composer.json requires laravel/framework ^9.0 -> satisfiable by laravel/framework[v9.0.0-beta.1, ..., 9.x-dev].

Resolve custom attribute values

In magento_custom_attributes type is size, value is 1715 - Where we need to define ID 1715 (which is "L")

Proposal:
Current:
Attribute Type is the hard value string, Attribute Value is the hard value of "value" on the API.

New:
Attributes are resolved using Magento API /V1/products/attributes/{attributeCode}.

  • Add new table, magento_custom_attribute_types
  • magento_custom_attributes.attribute_type becomes magento_custom_attribute_type.id
  • magento_custom_attribute_types.name houses the type "name".
  • magento_custom_attribute_types.options has an json array value of potential options.
  • magento_custom_attributes.value becomes the truth value of an option resolved from magento_custom_attribute_types.options. If the option is not available, use the hardcoded value from the API

Screen Shot 2020-08-10 at 9 45 25 AM

Install Laravel 8.0

Using version ^0.4.1 for grayloon/laravel-magento-api
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Can only install one of: guzzlehttp/guzzle[6.5.x-dev, 7.1.1].
- Can only install one of: guzzlehttp/guzzle[7.1.1, 6.5.x-dev].
- Can only install one of: guzzlehttp/guzzle[6.5.x-dev, 7.1.1].
- grayloon/laravel-magento-api 0.4.1 requires guzzlehttp/guzzle ^6.0 -> satisfiable by guzzlehttp/guzzle[6.5.x-dev].
- Installation request for grayloon/laravel-magento-api ^0.4.1 -> satisfiable by grayloon/laravel-magento-api[0.4.1].
- Installation request for guzzlehttp/guzzle (locked at 7.1.1, required as ^7.0.1) -> satisfiable by guzzlehttp/guzzle[7.1.1].

SKU with slash

Hi Andy,

How to handle sku's with slashes (/)? Do I have to urlencode all the sku's before using an API endpoint or is there setting for this? Is the urlencoding only needed for the url or also for the Postdata?

Thanks!

Order Create (PUT) method

I want to create order from my admin on magento and this package does not have method for order create

Posting data into magento.

Hello.

I am trying to post categories to magento using laravel. I found that this post, put, delete methods are protected. I can not use. Is there any other way? or why it is protected

$magento->api('categories')->post('/',$categoryArray);
  /**
     * Send a POST request with query parameters.
     *
     * @param  string  $path
     * @param  string  $parameters
     * @return \Illuminate\Http\Client\Response
     */
    protected function post($path, $parameters = [])
    {
        return $this->checkExceptions(Http::withToken($this->magento->token)
            ->post($this->apiRequest.$path, $parameters), $this->apiRequest.$path, $parameters);
    }

Products API/Storage

Schema:
Magento Connect (2)

Look into either using hasManyThrough or some type of polymorphic relationships for categories that are attributes.

Improve Documentation Readability

As the project grew, the documentation got a bit messy. The idea here would be to add a <dataset> for each endpoint with an index to quickly navigate to the endpoint at the top of the readme.

Add a nopages method for Orders?

Could we add a function similar to:

public function all_nopages($filters = [])
{
return $this->get('/orders',$filters);
}

to the Api/Orders class?

I'd like to get the raw data :)

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.