Over the course of the last few months, I’ve been tasked with improving or building new Shopify Apps for internal use at work. None of these apps are public, and are strictly for improving accounting and stock management across multiple storefronts. I’m a Laravel developer, and when the Shopify discussion came up, I didn’t really know what the best way to go about building Shopify Apps would be, especially when it came down to choosing a stack.
I eventually chose to build my Shopify Apps with Laravel, and below I explain why.
How Shopify Apps Work
Shopify Apps are really cool in the way they are integrated into Shopify stores. For starters, any interaction with a store’s data once your app is installed is done via the Shopify Store API, and governed by scopes. This makes sense, because some apps for Shopify don’t actually integrate into the Shopify store dashboard and yet have all of the functionalities that embedded apps can have. This took me a while to understand, but boiled down it really is quite simple.
Shopify Apps are web apps that implement the authentication system (OAuth 2.0) to be able to hook into Shopify stores. There is no difference between a standalone app or an app that is integrated into the store dashboard.
This is important, because it means that the stack used should therefore be irrelevant in the development. Why should it matter what you use if you’ll just be calling APIs anyways?
Well, it’s important not to reinvent the wheel.
Shopify Polaris & Official Tutorials
Shopify gives developers the freedom to choose the stack they want, and provides tutorials for commonly used technologies such as Ruby and Sinatra. The issue I came across was that there was very little information on building with Laravel, and what challenges would arise there. I eventually found the osiset/laravel-shopify package, which has proven to be a reliable base for Shopify Apps being built with Laravel.
One more thing to note is Shopify’s Polaris design system that offers React Components is recommended for apps that want to provide a seamless experience. Although I’ve never personally used Polaris, from my understanding it can be used with React and therefore can be built into the Laravel project with Laravel Mix. One day I’ll give this a try!
The Laravel Package
The Laravel package osiset/laravel-shopify has been instrumental in quickly building new Shopify Apps. This package saves me the trouble of figuring out the best ways to implement OAuth and all of the webhook stuff (more on this below), and allows me to grab API Keys from the Partners dashboard and get going.
Authentication is always a burden when starting a new project, and the
laravel-shopify package takes care of it for you. To better understand Shopify’s authentication process, have a look at the package’s wiki here.
Facilitating API Calls
laravel-shopify package makes it very easy to make calls to the Shopify API. I was writing code in no time and using the Shopify API to get the data I needed. The example below is how I get customer specific data.
$customerData = $shop->api()->rest('GET', sprintf('/admin/api/2019-10/customers/%s.json', $customerId))->body;
This call returned the data of the customer specified by the provided ID. Nice and simple!
Although for my purposes billing wasn’t necessary, for most Shopify applications billing will need to be set up. The
laravel-shopify package not only allows for setting up billing, but provides the configuration options to set up recurring or one time charges, trial days, capped amounts and even if the pricing will be shown on install.
The App Bridge is the mechanism used to embed your Shopify App directly into the Shopify store dashboard. To disable the embedding of your Shopify App, you just need to update the configuration with:
Jobs & Webhooks
There are certain cases where changes will need to be made within an application based on the actions of a user. This can be an uninstall or an information request that meets GDPR standards. In any case, the
laravel-shopify package offers some help with this.
The package includes an After Authentication Job that can be triggered after an application is installed. There is also the option to create custom webhooks, which is very useful for creating the GDPR compliant webhooks required by Shopify for user data protection.
I now have multiple functional Shopify Apps deployed, and the best part is this offers myself and the rest of the dev team the option to choose any frontend technology we need to get the job done. Laravel is familiar, and ultimately saved a lot of time just avoiding the learning curve that comes with using an unfamiliar stack.
Though I’d like to take credit for getting this all figured out myself, I’d like to thank the creator of the osiset/laravel-shopify package for doing all of the heavy lifting. The package is a life saver.