Building a Dynamic E-commerce Website for Small Businesses

Penny Penny Jun 06, 2021 · 9 mins read
Building a Dynamic E-commerce Website for Small Businesses

The ongoing COVID-19 pandemic has brought about a seismic shift in consumer behavior, driving an unprecedented surge in online shopping. With an increasing preference for online shopping over in-person experiences, small business owners find themselves presented with a unique opportunity to expand their customer base and boost revenue by establishing a robust e-commerce presence. In this blog post, we’ll explore the transformative potential of setting up a simple yet dynamic website with a database for small businesses. This strategic move not only enables businesses to adapt to the changing landscape but also empowers them to thrive in the digital world.

1. Plan and Design: Crafting a Roadmap to Success

Before diving into the development process, it’s crucial to meticulously plan and design your e-commerce platform. Small businesses need to outline their goals, target audience, and unique selling propositions. A well-thought-out plan ensures that the subsequent steps align with the business’s objectives, providing a roadmap for success. To be more specific, consider the features you want to incorporate, such as color themes, payment gateway integration, and more. Popular payment gateways like PayPal, Stripe, Braintree, and Square offer API access, allowing for seamless integration and backtesting.

2. Set up coding environment

Initiate your project by establishing a virtual environment using tools like virtualenv, helps to keep project dependencies organized and prevents conflicts between different projects. Additionally, it simplifies the process of transitioning projects to different laptops or computers and enables project reproduction across different devices. Once you have created a virtual environment, you can activate it by running the command.

virtualenv -p python3 <desired-path>
source <venv>/bin/activate

3. Building the project

Building a shopping site involves a multifaceted approach that encompasses various aspects, from designing the front end for user interaction to implementing a robust backend and database system. The front end is what users see in their browsers, while the back end is responsible for fulfilling user requests on the server side. You can either design the layout and animations yourself using CSS and JavaScript or utilize tools like Bootstrap, which expedites the front end creation of a page.

When it comes to the backend, Flask stands out as an excellent choice for beginners. Its user-friendly nature, coupled with examples readily available on platforms like GitHub, makes it an ideal starting point. The micro-framework of Flask offers flexibility, allowing businesses to tailor their web applications to meet specific project needs. You can have a website up and displaying “hello world!” within seconds by utilizing the following code.

import os
from flask import Flask
def create_app(test_config=None):
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(
        SECRET_KEY='dev',
        DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
    )

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile('config.py', silent=True)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    # a simple page that says hello
    @app.route('/hello')
    def hello():
        return 'Hello, World!'

    return app
flask --app flaskr run --debug

The database is the backbone of a shopping site, storing valuable information such as product details, customer data, and transaction history. Ask yourself a few questions before start.

  1. Product Attributes:
    • What attributes of the product do we need to showcase to customers?
    • Consider aspects like product images, descriptions, prices, and any other relevant details.
  2. Customer Information:
    • What information needs to be collected from customers?
    • Think about user registration details, shipping addresses, and any additional data relevant to your business model.

Drawing a clear and concise database schema is a critical step in visualizing the data model and establishing relationships between different entities. A standard schema typically includes tables representing various aspects of your website. Consider the following example:

In this example, the grey lines depict how tables are linked. Notice the “order_detail” table sharing a common key, “order_id,” with the “orders” table. This linkage allows for accurate tracking of inventory levels and updating product availability as items are sold. Taking the time to design a well-structured database schema sets the foundation for a robust and scalable shopping website.

Below is a simple example of a Flask application with a SQL database. In this example, we’ll create a basic shopping sites with products and orders. SQLite is used for simplicity, but you can replace it with a more robust database like PostgreSQL or MySQL based on your needs.

from flask import Flask, render_template, request, redirect, url_for
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///shop.db'  # Use SQLite for simplicity
db = SQLAlchemy(app)

# Define Product and Order models
class Product(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    price = db.Column(db.Float, nullable=False)

class Order(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    product_id = db.Column(db.Integer, db.ForeignKey('product.id'), nullable=False)
    quantity = db.Column(db.Integer, nullable=False)

Reference:

Flask-login document

Flask-login github demo

Organzing Flask Apps with Blueprints

As the website expands, consider enhancing the user experience with additional features and functionalities. Integration of payment gateways, search functionality, product reviews, wish lists, and social media integration can significantly boost user engagement and drive sales. Flask’s modular design and scalability allow you to seamlessly incorporate these features. Online tutorials from reputable sources, such as PayPal’s official guide on integrating PayPal Checkout for online payments, and various programming tutorials on building a shopping cart using JavaScript, provide valuable resources for developers.

Reference:

Paypal integration

JavaScript Shopping Cart Tutorial

4. Testing

Testing is a crucial phase in website development, involving various tests like unit tests, integration tests, and end-to-end tests to verify different components’ functionality. Frameworks like Pytest and unittest can be employed for testing purposes, and debugging is essential to ensure smooth website functionality.

5. Deploy

Once testing is complete, the next step is to deployment. Hosting services like Heroku, AWS, and Google Cloud Platform provide platforms for deploying websites. You will need to configure the hosting environment, set up the database and server, and deploy your code to the server. It’s also vital to consider factors like scalability, security, and availability during deployment. I used pythoneverywhere.com to host my website. It is affordable and Python friendly. With a paid account, you can host up to three web applications for $5 per month.

Security is paramount when handling sensitive customer information. It is our responsibility to protect user information from potential hackers and other security threats. An essential key is to use encryption to protect the data when transmitted between client and server. First, you’ll need to obtain an SSL (Secure Sockets Layer) certificate, which verifies the identity of your website and encrypts all data transmitted between the server and the client. You can obtain a SSL certificate from a trusted certificate authority such as Let’s Encrypt (FREE !!!) Once you have the certificate, configure the web server to use HTTPS instead of HTTP. HTTPS is a secure version of the HTTP protocol that encrypts all data transmitted between the client and server.

In addition to using encryption, you should also take other security measures such as regularly updating your software and plugins, using strong passwords, and implementing measures such as two-factor authentication to protect your website from potential threats. It’s also a good idea to regularly back up your website to protect against data loss in the event of a security breach or other issue.

Ensuring visibility on Google search results is pivotal for the success of your website. Google Search Console provides tools for verification and indexing. Purchasing a domain name, completing DNS verification, and submitting the index request are steps to ensure visibility in Google search results.

  1. Verify the domain on google search console. You can open the console by typing in google

    site:xxx.com
    
  2. Complete the DNS verification as google requested

  3. Buy a domain name.

  4. Edit CNAME record in the DNS manage section. Here I used goDaddy as an example.

host: www
points to: yourwebsitename.com
  1. Then go back to google console, search for your url in the URL inspection section and submit the index request. Google will perform several test on the website and if passed, you will receive a confirmation email from google.

In conclusion, Flask proves to be a flexible and lightweight web framework that simplifies database integration and offers built-in features for creating dynamic websites. By following a comprehensive development and deployment process, you can build a secure, feature-rich shopping site that meets user needs and stands out in the competitive online marketplace.

Penny
Written by Penny
Data scienctist, love to explore new ideas