How To Create a Shopify App Using PHP?

Many of them choose Shopify as their e-commerce platform, which is obvious as it is quite simple for Shopify to launch an e-commerce store. As Shopify is a Rails application, there is a large number of Shopify repositories that you can use for FREE to integrate your website to Shopify API. The Shopify platform contains a whole host of built-in functionality, thanks to its fully-featured REST and GraphQL API access, it is also a thriving app store with a huge range of plug-ins designed to enhance Shopify store functionality in many ways. Building Shopify Apps is very easy it is not a difficult task, all you need is to understand how the API works. Now we move to create a Shopify app using PHP.

Build your own shopify app using PHP

Developing a Shopify app is not rocket science. If you don’t have a Shopify account then You have to create a new Shopify app in your Shopify Developer account.

How To Create a Shopify App Using PHP?

You have an account then you proceed to login and after login, you see this page on your screen.

How To Create a Shopify App Using PHP?

On the left sidebar, you see the navigation panel, on the navigation panel click Apps category,

How To Create a Shopify App Using PHP?

Click Create app and select what type of app you want to build. They are two types, Custom app, and Public app, choose what you may want. For custom apps, you can install the app on Shopify store with no need for Shopify to review your app. For public apps, Shopify will need to review your app in order for Shopify stores to install your Shopify app.

How To Create a Shopify App Using PHP?

After selecting that you should be directed following form,

You need to fill in some information follows,

  • App Name- Name of the Shopify App you are going to create.
  • App URL- URL of the website where you going to upload your Shopify files.
  • Whitelisted Redirection URL(s)- This is where you’re going to list yours generate a token script or URLs you need as you authenticate your Shopify.

After filling the form, click create app.

How To Create a Shopify App Using PHP?

Now your Shopify app has been created, you need to connect your website by using the API credentials. For API, you need to download at least one Shopify repository. You can download any one projects you like from this:

  • Shopify API by Alexaitken.
  • PHP Shopify API by LukeTowers.
  • PHP Shopify API Wrapper by Zapien.
  • Simple Shopify API Client.
How To Create a Shopify App Using PHP?

These are the files you see after extracting GitHub project

  • inc file which contains PHP function it is used for making Shopify actions like displaying products.
  • api_call_write_products.php, it is a PHP file for creating actions.
  • generate_token.php, a PHP file for generating tokens per store.
  • install.php, as the name implies, is a Shopify installment file.

Install.php

How To Create a Shopify App Using PHP?

In the install.php file, for your app, you need to assign the value of $_GET[‘shop’] in $shop. The value is your URL that the user will be visiting.

The URL should be like this

https://ex.com/install.php?shop=ex.myshopify.com

$api_key variable is where you’ll be assigning your API key.

You can find your API key from your developer app page.

How To Create a Shopify App Using PHP?

You may leave the $scope variable.

$redirect_uri should contain the URL of your generate_token.php file

$install_url is a variable that contains the complete URL where the user will be prompted to install the app.

After setting up the variables, redirection to the URL from the $install_url variable will happen.

Importantly You should only change the value of the $api_key and $redirect_uri variables.

generate_token.php

How To Create a Shopify App Using PHP?

Before we proceed, make sure you change the value of the variables $api_key and $shared_secret. It is same as before where you get the API from the Developer app dashboard.

If you noticed, the code above is using the cURL client to execute requests. These requests will give you a value that is a JSON data type and that needs to be decoded so that PHP can use this value.

After getting the access token, you may add a MySQL query to save the value of the $access_token variable for future use.

Installing the shopify app

Once everything is set up, you may go to your project URL and run install.php. For this, you need to include the variable shop in the URL. For example:

https://ex.com/ex/install.php?shop=shop.myshopify.com

check it’s the same URL from your app dashboard. Or else, it was showing errors.

Conclusion

How To Create a Shopify App Using PHP?

If you’ve seen the above page it means your PHP files are working properly. Using Shopify API and PHP you display products, in your app. Congrats you created a Shopify app using PHP, it’s simple as you have seen.