15
OctThe Laravel Shopify package allows you to easily make requests to the Shopify API. It can be utilized to communicate with Shopify from your Laravel application. It covers quite a few endpoints from the API and even provides the ability to make custom requests to the Shopify API, taking care of credentials, etc.
You can install this package via composer:
composer require signifly/laravel-shopify
The package will automatically register itself.
Publish the config file with:
php artisan vendor:publish --tag=laravel-shopify
You need to create a private app to get the necessary credentials for interacting with Shopify.
Initializing the Client
use Signifly\Shopify\Shopify;
$shopify = new Shopify(
env('SHOPIFY_API_KEY'),
env('SHOPIFY_API_PASSWORD'),
env('SHOPIFY_DOMAIN'),
env('SHOPIFY_API_VERSION')
);
Resolve from the service container
Using class:
use Signifly\Shopify\Shopify;
$shopify = app(Shopify::class);
Using alias:
$shopify = app('shopify');
Resolve using the factory
$shopify = \Signifly\Shopify\Factory::fromConfig();
Resolve using dependency injection
You can also inject the Shopify class into a method of a Controller:
use Illuminate\Http\Request;
use Signifly\Shopify\Shopify;
class ProductController{
public function index(Request $request, Shopify $shopify)
{
// do something here
}
}
By default, it will look for credentials in your config, when resolving the client.
Once a client has been initialized, you can make requests to Shopify utilizing the available methods.
Let’s take a look at a couple of examples:
$shopify = \Signifly\Shopify\Factory::fromConfig();
// Paginate products
$cursor = $shopify->paginateProducts(); // returns a Cursor
// Get products count
$count = $shopify->getProductsCount(); // returns an integer
// Get products
$products = $shopify->getProducts(); // returns a Collection of ProductResource
// Create a product
$product = $shopify->createProduct([
'title' => 'Adidas Shoe, Pink',
]); // returns a ProductResource
// Get a specific product
$product = $shopify->getProduct($productId); // returns a ProductResource
// Update a product
$product = $shopify->updateProduct($productId, [
'title' => 'Adidas Shoe, Rose',
]); // returns a ProductResource
// Deleting a product
$shopify->deleteProduct($productId);
This package has API methods for the following high-level Shopify features:
A variety of methods is available on the Shopify client instance, see below:
// HTTP calls
$shopify->get() : Response;
$shopify->post() : Response;
$shopify->put() : Response;
$shopify->delete() : Response;
// Other
$shopify->getLastResponse() : Response;
If you want to learn more about this package, then you can explore its details by visiting its official documentation and source code on Github.
Published at : 15-10-2021
I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.
Launch project