Download the PHP package justbetter/laravel-magento-client without Composer
On this page you can find all versions of the php package justbetter/laravel-magento-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download justbetter/laravel-magento-client
More information about justbetter/laravel-magento-client
Files in justbetter/laravel-magento-client
Package laravel-magento-client
Short Description A client to interact with Magento
License MIT
Informations about the package laravel-magento-client
Laravel Magento Client
A client to communicate with Magento from your Laravel application.
Installation
Are you coming from
grayloon/laravel-magento-api
? We have written a migration guide!
Require this package:
Configuration
Add the following to your .env
:
Optionally, publish the configuration file of this package.
Multiple connections
This package supports connecting to multiple Magento instances. In the configuration file you will find an array with the connections where you can configure each connection.
The connection
setting sets which connection is used by default.
You can switch connections by using the connection
method on the client.
Authentication
By default, this packages uses Bearer tokens to authenticate to Magento. Since Magento 2.4.4, this method of authentication requires additional configuration in Magento as described here.
It is recommended to authenticate to Magento using OAuth 1.0 which will also prevent the additional configuration requirements, besides setting up the integration itself.
Setting up OAuth 1.0
Start by adding the following variable to your .env
-file.
Note that you can also remove MAGENTO_ACCESS_TOKEN
at this point, as it will be saved in a file instead.
Next, open Magento and create a new integration. When configuring, supply a Callback URL
and Identity link URL
. If you have not made any changes to your configuration, these are the URLs:
connection
is the key in your connections array in the configuration file.
When creating the integration, Magento will send multiple tokens and secrets to your application via the callback
-endpoint. This information will be saved in the database, as configured in magento.php
. You may adjust this to save the key in a JSON file or create your own implementation
Magento will redirect you to the identity
-endpoint in order to activate the integration.
For more information about OAuth 1.0 in Magento, please consult the documentation.
Identity endpoint
[!CAUTION] Be sure to add your authentication middleware
Note that the identity
-endpoint does not have any authentication or authorization middleware by default - you should add this in the configuration yourself. If you do not have any form of protection, anyone could change the tokens in your secret file.
It is recommended that only administrators of your application are allowed to access the identity endpoint.
Usage
You can get an instance of the client by injecting it or by resolving it:
After you got an instance you can use the graphql
, get
, post
, put
and patch
methods to use the Magento API.
SearchCriteria / Filtering
To easily create search criteria you can use the \JustBetter\MagentoClient\Query\SearchCriteria
class.
For example:
You can view more examples in Magento's documentation.
Connections
You can connect to other connections using the connection
method on the client.
GraphQL
You can run authenticated GraphQL queries using the graphql
method on the client.
More Examples
You can view the tests for more examples.
Checking if Magento is available
This client keeps track whether Magento is available by storing the count of any >=502 and <=504 response code in cache.
You may use the available()
method on the client in order to check if Magento is available.
The threshold, timespan and status codes can be configured in the configuration file per connection.
Jobs
This package provides a job middleware that releases jobs back onto the queue when Magento is not available.
The middleware is located at \JustBetter\MagentoClient\Jobs\Middleware\AvailableMiddleware
.
Testing
This package uses Laravel's HTTP client so that you can fake the requests.
Quality
To ensure the quality of this package, run the following command:
This will execute three tasks:
- Makes sure all tests are passed
- Checks for any issues using static code analysis
- Checks if the code is correctly formatted
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Vincent Boon
- Ramon Rietdijk
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-magento-client with dependencies
guzzlehttp/guzzle Version ^7.5
laravel/framework Version ^10.0|^11.0
league/oauth1-client Version ^1.10