What is Shopify?
Shopify is a platform which helps to create a simple online store very quickly and safely.
If you want to build custom functionality for your shop, Shopify provides you with robust functionality to solve any of your issues in this regard. The platform has the App Store, where you can install tons of apps and plugins of your choice, and a powerful API for developers, which helps to create any kind of app.
In this article, I’ll try to explain the difference between private and public apps and show how to make a Shopify app using Ruby on Rails.
The difference between private and public apps in Shopify
First, you need to decide on the type of application to use. Shopify allows both private and public apps.
Public apps are well-known among Shopify merchants as they can be installed from Shopify’s App Store, either for free or paid by subscription. This kind of app can work with Shopify API on behalf of multiple stores. Public apps are made by third-party developers, not by Shopify.
Another type of apps is a private app. These are custom apps built specifically for one store which means that nobody has access to it except the merchant and the developer who made it. The private app uses the same API as the public one but has a different authentication method.
This guide will focus on public Shopify app development.
How to build a Shopify app using Ruby on Rails
Before you start building your first Shopify app, you need some preparation steps:
You need to have a partner account in Shopify. If you don’t have that type of account, you can register for one at the following link.
Then, you need to create an app in your Shopify account in order to get the app and the API keys. Go to the “Apps” tab and click “Create App” button.
Finally, create a store for app testing. Go to the “Development Stores” tab and create a store there.
Now you can start building your first Shopify app. As I have previously mentioned, we’ll use Ruby on Rails for development.
Let's start.
Basic environment configuration
1. Let’s create a RoR app with a database.
$ rails new simple-shopify-app --database=postgresql
$ rails db:setup
2. Check that the application starts up and everything works.
$ rails s
Configuration and installing shopify_app gem
1. Add the gem ‘shopify_app’ into Gemfile and run bundle installs.
2. After that, start the generator and add the ShopifyApp Engine. The generator will add shopify_app.rb to config/initializers.
$ rails generate shopify_app
The config file looks like this:
ShopifyApp.configure do |config|
config.application_name = "Shopify App"
config.api_key = Rails.application.secrets.shopify[‘api_key’]
config.secret = Rails.application.secrets.shopify[‘secret’]
config.scope = "read_products"
config.embedded_app = true
config.after_authenticate_job = false
config.session_repository = Shop
end
The attributes config.api_key and config.secrets need to be replaced with the keys that you received at the time of creating the application in the partner’s dashboard. In this case, we have written these keys in config/secrets.yml and it looks like this:
development:
secret_key_base: a2b8df95ca034ceb0e2157068ba5602934734cadb584c80fa816792
shopify:
api_key: 2415d202f987db74f4fb583788bccd997de18274 #example
secret: 157068ba5602934734cadb584c80fa #example
After you have configured the environment and gem, start creating the controller and models for the Shopify App. By running the next generator, get shop_model and migration.
$ rails generate shopify_app:shop_model
$ rails db:migrate
Next, create an example controller that builds and displays products using Shopify API.
$ rails generate shopify_app:home_controller
Deployment and Testing
Testing Shopify applications is not a difficult task; it can be effected using such tools as localtunnel or ngrok.
After creating the URL, you need to update the “Whitelisted redirection URL(s)” in the settings of the Shopify app and add the URL (example: https://shopifyapp.localtunnel.me/auth/shopify/callback), which you have implemented using localtunnel / ngrok.
As for deployment, it is the same as the usual Ruby on Rails application development. You can either use the Heroku provider or read our article on deploying a Ruby on Rails application using ElasticBeanstalk.
Summarizing
It would be difficult to develop an online store using Shopify without any third-party applications. Though many ready-made applications can be found in the Shopify App Store, you’ll probably need some custom plugins made specifically for your store.
I hope my small Ruby on Rails Shopify tutorial was useful for you. If you have any questions on Shopify app development pricing, or you want our team to develop a Shopify app for you (either public or private), drop me a message in our live chat.
Rate this post!
264 ratings, average ratings is 4.6 out of 5
Related Posts
Effective Food Delivery App: Key Tips & Best Practices
In this article, we will share our experience in creating a design for a specialized food delivery management software, as well as best practices in designing such an application.
02 August 2023
E-learning Platform Development: Features & Steps to Build
Build an online learning platform with ease: A guide to essential features and step-by-step processes for successful e-learning platform development.
07 May 2021
How to Integrate 3D Models into Web Apps
We discuss the value of 3D models to your business, pick things to consider before collaborating with your IT partner, and look at 3D web apps.
29 April 2021
Why Use Ruby on Rails and How Can It Benefit Your Next Product?
Learn when to use Ruby on Rails framework for the backend of your app or website and how to choose web developers who use Ruby on Rails programming language.
06 November 2020
Dedicated Team Model: What It Is, Pros & Cons for Your Project
Dedicated team model - a winning approach to scaling your project fast when done right. Find out pros and cons and how to find a dedicated software team that will fit your needs
23 June 2020
Choosing an Outsourcing Engagement Model: What Is Right For You
Agente will help you to choose an outsourcing engagement model for software development according to your scope, budget, and timeframe.
Let's talk
Is there a challenge your organization or company needs help solving? We’d love to discuss it.
Managing Director, Partner
Andrew Terehin
Thank You!
Your message has been successfully sent.
We will contact you very soon.