A Guide on How to Develop a Shopify App with Laravel & PHP

by Kiran / Posted

Screen Shot 2015-12-23 at 10.56.08

What is a Shopify App?

A Shopify app is an external service or software which can manipulate your Shopify store. Generally, anything that you can do with your store, an app can do on your behalf – it can modify products, view orders, edit themes, and so on. Apps are a great way to automate common tasks such as bulk-editing collections or extend your store’s functionality like adding reviews to your products.


The 2 Types of Apps used in Shopify:

Public apps can be submitted to the app store and used by multiple stores. To create and submit normal apps to the Shopify App Store, you need to own a Shopify Partner account.
Private apps are usually used by a single store. They require less setup code and anyone with a Shopify store can develop one. They’re great for adding unique, store-specific functionality, but they can’t be submitted to the app store.

This short introduction to developing Shopify apps will show you to how create a private app for your store which can interact with your products.



To follow along with this guide, you will need:

  • A Shopify store you want to make an app for
  • A web server with PHP 5.4 or higher to host your app
  • A basic understanding of PHP
  • Some familiarity with using the command-line (cmd, Terminal, etc.)


Register your App in Shopify

1. Begin by entering your store dashboard and going to Apps > Private Apps


Screen Shot 2015-12-22 at 11.47.45


2. Create a new private app and provide a title and contact email address

3. Once you save your new app, Shopify will provide you with a list of credentials – your app will need these later to authenticate
Screen Shot 2015-12-22 at 11.50.00
Screen Shot 2015-12-22 at 11.50.47



What tools are we using?

You can create a Shopify app using any system that lets you send web requests but, to make things more practical we can use some common frameworks and tools:

  • Laravel
    Laravel is a modern PHP framework that focuses on clarity and provides a solid foundation for building our app.
  • Composer
    Composer is a PHP package manager that makes it easy to install Laravel and a variety of other PHP tools with minimal effort.
  • RocketCode
    RocketCode’s Shopify API wrapper gives us a simpler way to interact with Shopify by providing functions that abstract away the process of actually sending requests back-and-forth.

Setup your App

Create a folder for your app. Open up cmd, Terminal, or your choice of command line and enter the following commands to setup Composer Laravel, and dependencies:

cd /path/to/app/folder/
curl -sS https://getcomposer.org/installer | php    # Install Composer
create-project laravel/laravel .                    # Install Laravel 5
composer require rocket-code/shopify:2.0            # Add the Shopify API wrapper

Create a route

Laravel’s routing model allows you to specify a URL and provide a function that will be run when someone navigates to that URL. As an example of what you can do with your app, we’re going to create a page at /show_products – when someone visits it, we’ll print out the titles and IDs of all the products in our shop.

Open up: ‘app/code/Http/routes.php’ and add the following to the end of the file:

Route::get('/show_products', function() {
  // Code put here will run when you navigate to /show_products
  // This creates an instance of the Shopify API wrapper and
  // authenticates our app.
  $shopify = App::make('ShopifyAPI', [
    'API_KEY' => 'App API Key',
    'API_SECRET' => 'App Shared Secret',
    'SHOP_DOMAIN' => 'yourshop.myshopify.com',
    'ACCESS_TOKEN' => 'App Password'
  // Continue..

Substitute the credentials in your code with those provided by Shopify earlier.

This defines a route at /show_product. When it’s requested, we’ll make an instance of the Shopify API wrapper and provide our app’s credentials.

Retrieving products

Next, we need to make a call to Shopify and ask for the list of our store’s products. If you refer to the Shopify docs for Product, you can see there’s a method defined as GET /admin/products.json that returns this information.

This method is paginated, meaning we’ll have to request /admin/products?page=1, ..?page=2, ..?page=3, etc. until we’ve run out of products to request. For the purpose of this example, we’ll just get the first page of 50 products:

Route::get('/show_products', function() {
  // Code put here will run when you navigate to /show_products
  // This creates an instance of the Shopify API wrapper and
  // authenticates our app.
  $shopify = App::make('ShopifyAPI', [
    'API_KEY' => 'App API Key',
    'API_SECRET' => 'App Shared Secret',
    'SHOP_DOMAIN' => 'yourshop.myshopify.com',
    'ACCESS_TOKEN' => 'App Password'

  // Gets a list of products
  $result = $shopify->call([
    'METHOD'     => 'GET',
    'URL'         => '/admin/products.json?page=1'
  $products = $result->products;

  // Print out the title of each product we received
  foreach($products as $product) {
    echo '

' . $product->id . ': ' . $product->title . '



Add .htaccess

In order to direct your web server’s requests into Laravel, you’ll need to create a file named .htaccess. Put it in the same folder as the rest of your app’s files, and put the following in it:

RewriteEngine On

RewriteRule ^(.*)$ public/$1 [L]

Upload your App

Put the app onto your web server and navigate to http://yoursite.com/show_products to see it working.

What’s Next

Why not try modifying a product:

  'METHOD'      => 'PUT',
  'URL'         => '/admin/products/123456789.json',
  'DATA'        => [
    'product' => [
      'id'     => 123456789,
      'title'  => 'New product title!'

(Make sure you change the ID in the code above to the ID of one of the products in your shop!)

We hope this guide has been interest for those of you wanting to develop a Shopify App of your own.

If you would like us to develop an app for your site, please get in contact with us and we can get our App Developer, Kiran to help you at: [email protected]

Shopify makes it easy to run an online store

Get a free 2 week trial