Install Saleor e-commerce

Posted by Toguko on Tue 12 September 2017

I decide to create one e-commerce to sell my wife artisan's products directly and stop to depends on third party platforms that take a big part of the earns.

We are fu***ed in terms of an Open Source e-commerce platform written in Python + Django. We have many options, but this options or are abandoned, or is not easy to set up, or are not easy to customize, or don't have a good and updated documentation.

I choose Saleor after days looking for a good and easy to use Python + Django e-commerce and not find one. Saleor was the easiest to install, even with a very bad and old documentation. So let's go over by one step-by-step how to install locally, setting up and deploy the app at Heroku. After these steps I will try to adapt to the Brazilian Environment like Payment options, Shipping Cost, etc.

To start, let's check our npm and yarn versions, Saleor uses npm version 6.x and yarn 0.20.x

To easily switch between npm versions we'll use NVM. NVM.

Installing NVM dependencies:

$sudo apt-get update
$sudo apt-get install build-essential libssl-dev

Downloading the NVM install script and Installing it:

$curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.sh
$bash install_nvm.sh

List the npm versions available:

$nvm ls-remote

Output
...
    v6.7.0
    v6.8.0
    v6.8.1
->  v6.9.0
    v6.9.1
    v6.9.2
    v6.9.3
    v6.9.4
    v6.9.5
    v6.10.0
    v6.10.1
    v6.10.2
    v6.10.3
    v6.11.0
    v6.11.1
    v6.11.2
    v6.11.3
    v7.0.0
    v7.1.0
...

Now install the version to be used with Saleor:

$nvm install 6.0.0
$nvm use 6.0.0
$node -v

If you have several Nodejs versions, you can see which version are installing using this command:

$nvm ls

Now clone the Saleor app, and the Python Virtual Env:

$git clone https://github.com/mirumee/saleor.git MYAPP
$python3 -m venv .venv
$source .venv/bin/activate
$pip install pip --upgrade
$pip install -r requirements.txt

Debian and Ubuntu users who install Node.js using system packages, will need to install the nodejs-legacy package as well. $sudo apt-get install nodejs-legacy

Install Webpack Module Bundler and Yarn globally with:

$npm i webpack -g
$npm i yarn -g

Install PostgreSQL version 9.4 or above following this tutorial of Digital Ocean Don't forget to set the user and password of the postgress user that you create in the settings.py at the line bellow:

DATABASES = {
    'default': dj_database_url.config(
        default='postgres://USER:PASS@localhost:5432/saleor',
        conn_max_age=600)}

The original docs ask you to create a variable at your environment with $ export SECRET_KEY='<mysecretkey>'. I'll not do this, I'm putting the SECRET_KEY directly at settings.py at this time because in the near future I'll use the python-decouple to do a full separation of the config files. So, with you want to do this, go to you settings.py comment the line below:

# SECRET_KEY = os.environ.get('SECRET_KEY') # Original Saleor SECRET_KEY Config

And set a new one as SECRET_KEY = 'PUT_SOME_BIG_AND_COMPLICATED_SECRET_KEY'

Prepare the database:

$python manage.py makemigrations
$python manage.py migrate

Now everything with the Django and Database is fine, and began my nightmares with the frontend parts... Let's install the front-end dependencies with:

$yarn

I received this error:

yarn install v1.0.1
[1/5] Validating package.json...
error saleor@0.0.0: The engine "yarn" is incompatible with this module. Expected version "0.20.x".
error Found incompatible module
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

I decide to go at package.json file and remove the version of the package yarn of "yarn": "0.20.x" to "yarn": "", save and run yarn again. Everything was installed without problems, only one warning warning "ajv-keywords@1.5.0" has incorrect peer dependency "ajv@>=4.10.0". that I decide to check later.

Now lets prepare front-end assets with:

$yarn run build-assets

Everything was ok, but with a lot of warnings to check later...

Now Run python manage.py populatedb to populate the database, so we can test the app with some images and contents.

And finally we reach our goal, let's test with: python manage.py runserver

Open a web browser at localhost:8000 to check your new Saleor e-commerce up and running.

In the next post, I will show how to deploy the app at Heroku.