A developer that is looking to build an example Shopify app from start to finish and deploy it.
I used the official Shopify app boilerplate tutorial when I first started Shopify app development. It was a good starting place, but it left out key components to building a Shopify app. For example, the tutorial does not explain how to store user information and user preferences in a database. Finally, it wasn't obvious on how to deploy the Shopify app from a local environment to a production environment. I created this Shopify framework tutorial to address these issues and build a working example app from start to finish.
The working example will allow a user to select products and then apply a pricing discount. During this tutorial, you will learn the most important concepts:
I'll supply you with the complete code for the Shopify app, but it helps if you have an understanding of front end and back end javascript frameworks.
This app uses Node.js, and Next.js (React Framework) to create the Shopify app.
{% c-block language="bash" %}
$ node -v
{% c-block-end %}
{% c-block language="bash" %}
$ mkdir shopify-complete-app && cd shopify-complete-app
{% c-block-end %}
{% c-block language="bash" %}
$ npm init -y
{% c-block-end %}
{% c-block language="bash" %}
$ npm install --save react react-dom next
{% c-block-end %}
{% c-block language="bash" %}
$ mkdir pages
{% c-block-end %}
https://gist.github.com/nutterbrand/5f887fc3721c95a142399d5631ad1139
export default Index;
{% c-block-end %}
https://gist.github.com/nutterbrand/44465ec2f8012a0f6f25d324a44d9902
This section will cover everything you need to embed your Shopify App in the store.
{% c-block language="bash" %}
$ npm install ngrok -g
{% c-block-end %}
{% c-block language="bash" %}
$ ngrok http 3000
{% c-block-end %}
{% c-block language="bash" %}
$ vim .env
{% c-block-end %}
https://gist.github.com/nutterbrand/5367cd54157d5e5740fb28e133eee09e
{% c-block language="bash" %}
$ npm install --save koa @shopify/koa-shopify-auth dotenv koa-session isomorphic-fetch
{% c-block-end %}
https://gist.github.com/nutterbrand/12eac56b53cccd5c73a4dbd26a064552
https://gist.github.com/nutterbrand/d0fce636e8c8435cde07c898d61d34c4
{% c-block language="bash" %}
$ npm run dev
{% c-block-end %}
Shopify uses a design system they created called Polaris it serves as an opinionated UI/UX framework. Polaris makes it easy and fast to develop user interfaces the framework is very opinionated. In this next section you will see how fast and easy it is to use.
Polaris, Shopify's UI/UX framework makes UI design extremely easy, even for a back end developer.
{% c-block language="bash" %}
$ npm install --save @zeit/next-css @shopify/polaris
{% c-block-end %}
https://gist.github.com/nutterbrand/0ebbbbb3e102748954c0666821d9d5e7
https://gist.github.com/nutterbrand/23bd2262fc6dbe41f71b864773e0aa7c
{% c-block language="bash" %}
$ npm run dev
{% c-block-end %}
https://gist.github.com/nutterbrand/5401a143c9f2e786003748c76c90b1e6
https://gist.github.com/nutterbrand/c0865f7b0c86d4a952dd1d88fd8f0b2c
https://gist.github.com/nutterbrand/22293ab0c590ef55a903411da57993fe
{% c-block language="bash" %}
$ npm install --save @shopify/app-bridge-react
{% c-block-end %}
https://gist.github.com/nutterbrand/eda9c460980148a03f2faf909edf4c37
{% c-block language="bash" %}
$ npm run dev
{% c-block-end %}
https://gist.github.com/nutterbrand/5d6a74b648ee193c50c4bdb0b16cbc9d
https://gist.github.com/nutterbrand/d1a94ac5370644a849e7eb72edacc7a9
https://gist.github.com/nutterbrand/2c8f59b847356170ff8b7ff6799b3550
https://gist.github.com/nutterbrand/cd52d4348a8c59bd900c1ca426d619ce
https://gist.github.com/nutterbrand/d0a310038141107cde0b129be9f52148
Shopify uses a GraphQL and Apollo to fetch store data and then return it for use. Store data can include orders, inventory, and metadata. In this next section I'll show you how to retrieve store data for your Shopify app. If you want to learn the graphQL admin api, Shopify provides a good tutorial on covering the basics. Everything you will need will be in the next section to complete the app to interface with GraphQL.
Shopify uses GraphQL and Apollo to retrieve merchant store data
{% c-block language="bash" %}
$ npm install --save graphql apollo-boost react-apollo
{% c-block-end %}
{% c-block language="bash" %}
$ npm install --save @shopify/koa-shopify-graphql-proxy
{% c-block-end %}
https://gist.github.com/nutterbrand/c23bfad5a46754e755a4a2b9fd6379de
https://gist.github.com/nutterbrand/d86edfb0975e34f7c36769f6c54b2747
https://gist.github.com/nutterbrand/4c41be8de143b79f273cd54825c444f5
{% c-block language="bash" %}
$ npm install --save store-js
{% c-block-end %}
https://gist.github.com/nutterbrand/f40f03bccb74eb1925ee59e4380b23cd
https://gist.github.com/nutterbrand/5ac1d5080c226f86ac7d9be00b9bd5f9
https://gist.github.com/nutterbrand/3387a9a83a08990e6868b4df0608c103
https://gist.github.com/nutterbrand/8417348cafc45dde43b98c58778162b7
https://gist.github.com/nutterbrand/c0a74e2dc6cb7184825b77c658351850
https://gist.github.com/nutterbrand/a36e89dffa77154c9cfc1134cc6ce2b9
One of the things I love the most about creating Shopify apps is Shopify handles the billing transparently for the customer. For the customer, this means they never have to enter a credit card number to use your app. They simply need to consent authorization and then Shopify will handle it from there. This also means that Shopify will take a 20% cut of your revenue so you need to plan your pricing model so that you will still make money even after the 20%.
The customer only sees the pricing charge once at installation if you are billing the customer on a monthly basis. Furthermore, if the customer uninstalls the app, then they will not be charged at that time.
The following section will show you how to set up monthly billing for $10 when the customer installs your Shopify app.
Shopify handles billing transparently through their system; The customer will be billed for your app on their next Shopify payment cycle.
https://gist.github.com/nutterbrand/4bd9afe396c368698a3f553b8b950adf
https://gist.github.com/nutterbrand/d49a34e2624318f54b627258af43c047
https://gist.github.com/nutterbrand/316fc5ccb3bcd85d75e6cf9fdb0bb702
If you are developing an app for yourself or for a client, it is important to understand how to host the Shopify app. In this next section, I will show you the steps to host your app on Heroku. I chose Heroku since it is extemely easy to launch and most of the setup I can do through command line. The cost for the service should be less than $50 a month for most applications of an app.
{% c-block language="bash" %}
$ heroku login
{% c-block-end %}
{% c-block language="bash" %}
$ git init
{% c-block-end %}
{% c-block language="bash" %}
$ heroku create
{% c-block-end %}
{% c-block language="bash" %}
$ heroku addons:create heroku-postgresql:hobby-basic
{% c-block-end %}
{% c-block language="bash" %}
$ heroku config
{% c-block-end %}
{% c-block language="bash" %}
DATABASE_URL=postgres://PGUSER:PGPASSWORD@PGHOST:PGPORT/PGDATABASE
{% c-block-end %}
{% c-block language="bash" %}
$ heroku config:set PGUSER=YOUR_PGUSER
{% c-block-end %}
{% c-block language="bash" %}
$ heroku config:set PGPASSWORD=YOUR_PGPASSWORD
{% c-block-end %}
{% c-block language="bash" %}
$ heroku config:set PGHOST=YOUR_PGHOST
{% c-block-end %}
{% c-block language="bash" %}
$ heroku config:set PGDATABASE=YOUR_PGDATABASE
{% c-block-end %}
{% c-block language="bash" %}
$ heroku config:set PGPORT=YOUR_PGPORT
{% c-block-end %}
{% c-block language="bash" %}
$ heroku config:set SHOPIFY_API_KEY=YOUR_SHOPIFY_API_KEY
{% c-block-end %}
{% c-block language="bash" %}
$ heroku config:set SHOPIFY_API_SECRET_KEY=YOUR_SHOPIFY_API_SECRET
{% c-block-end %}
{% c-block language="bash" %}
$ heroku config:set SCOPES=read_products,write_products
{% c-block-end %}
{% c-block language="bash" %}
$ heroku config:set API_VERSION=2019-10
{% c-block-end %}
{% c-block language="bash" %}
$ heroku config:set HOST=https://YOUR_HEROKU_APP_NAME.herokuapp.com/
{% c-block-end %}
{% c-block language="bash" %}
$ heroku config
{% c-block-end %}
{% c-block language="bash" %}
$ heroku config:set NODE_ENV=production
{% c-block-end %}
https://gist.github.com/nutterbrand/3f3d3e85e1063adb2981346a0a1cbfa6
https://gist.github.com/nutterbrand/11a46b62a2f9f305aa12532768342ffa
{% c-block language="bash" %}
$ git add .
{% c-block-end %}
{% c-block language="bash" %}
$ git commit -m "Adding changes from Shopify tutorial"
{% c-block-end %}
{% c-block language="bash" %}
$ git push heroku master
{% c-block-end %}
https://gist.github.com/nutterbrand/4fe6a6d21060f035276f7727578160ad
{% c-block language="bash" %}
$ heroku pg:psql --remote shopify-example < table.sql
{% c-block-end %}
{% c-block language="bash" %}
$ heroku logs --app YOUR_HEROKU_APP_NAME --tail
{% c-block-end %}
{% c-block language="bash" %}
$ heroku pg:psql
{% c-block-end %}
{% c-block language="bash" %}
DATABASE=> select shop, user_email from public.shop;
{% c-block-end %}
Together we just built a complete Shopify app from start to finish and deployed the app to Heroku. Most of what is covered in this tutorial you can build off to fetch other data from the Shopify API. Also, you can reuse this framework for multiple apps in the future which makes app development extremely quick. To understand how to set up a development, staging, and production workflow along with the final touches, sign up for the email to get my best practices!