7th Sep 2021

How To Modify The Saleor E-Commerce Platform ?

Python

Written By, Sanket Jethava

Overview

Hello techies, we all have learned a few aspects of Saleor e-commerce in our previous blog. As we can see Saleor is reaching the heights in the comparison of the open source e-commerce platforms. So today we are going to get an understanding about how we can make the modification to the existing saleor platform.

Into The Process

Initially, we will start to add new app in the existing saleor code.

Let’s follow some steps

First step would be to clone the officially repository of the Saleor

Once it is cloned, go to the saleor main directory where you’ll find settings.py file.

setting-py

Open up the terminal in that directory, and hit the command to create new app :
django-admin startapp <appname>

Here we have created one new app with name temp :
django-admin startapp temp

After hitting the above command in the terminal you will be able to see one new folder is created in the current directory where we have settings.py file.

Like the screenshot below.

Yayy !! We have created a new app for our saleor platform. Now it’s time to register it in settings.py file, so that we can access this new app temp and its functionalities.

So, let’s begin with it.

  • Open settings.py in code editor and add created new app’s name in the INSTALLED_APPS variable.

https://blog.yudiz.com/wp-content/uploads/2021/09/saleor-temp.png

  • After adding the name of the app, save the file and also add the models to the models.py of the new app if required. Once it is done run the server using python manage.py runserver command inside the project root folder where manage.py exists.
  • Have you hitted makemigrations and migrate command to migrate all new models from our new app name – temp. If not, hit these commands before running the server.
  • And finally run the server – python mananage.py runserver

So it’s time to add GraphQL API’s to our newly created app. If you are not familiar with GraphQl, please refer to this well written GraphQL blog.

  • First we will need to create a new folder with the same name or different name of the newly created app, inside the graphql folder of the project.

graphql-folder

We suggest giving it the same name as the newly created app for better understanding.

Here we have created a temp folder with some basic required files for creating new queries and mutations for GraphQL API. The structure of folder and files will look like below:

temp-folder-path

At last, the remaining step is to link up the graphql files with the main graphql module of Saleor. 

Let’s do that

  • Go to the graphql module where you will find an api.py named file. In that import your graphql files using below lines :
    from .temp.schema import TempMutations, TempQueries
  • Now, add your TempMutations to class Mutation arguments and add your TempQueries to class Query arguments.

That’s all !! You’ve successfully created one new app module inside the Saleor project.

party-time

Hit the python manage.py runserver and see the magic.

Conclusion

As Saleor e-commerce is trending in the market as it is an open source e-commerce platform and it’s code modification might be a little bit complex at the very first time.

But If you’ll do the practice and go with deep research on it at that time you’ll find that it is the best open source and powerful platform with great addons to build a user friendly environment.

We hope you have found this blog helpful.

Written By,

Python Developer at Yudiz Solutions Pvt. Ltd