Any e-commerce vendor who is selling a competitive product online, would want their sales to be maximum. One of the important factor that users see in buying a competitive product is the selling price that the vendor is offering. In order to sell maximum products a vendor would need to give the product at best selling price in the market, without compromising on the desired profits.
In this code pattern, we will develop an interactive UI integrated with custom backend that will help the e-commerce vendors decide on an optimal selling price such that their chances of sales will increase and at the same time maintain their desired profits.
- User launches the application.
- Product details are retrieved from MongoDB.
- List of products being sold are displayed.
- User enters
Profit Margin
andMinimum Requied Profit
for the product being sold. - This information is sent to the backend cloud functions.
- Cloud Functions scrapes the competitors product details from their websites.
- Custom algorithm computes the optimal price and sends itback to the application.
- An interacive tool is displayed to the user on the UI.
- User uses the tool and information on the UI to set a competitive price.
- IBM Cloud account: Create an IBM Cloud account.
- Python 3: Install python 3.
Please follow the below to setup and run this code pattern.
- Clone the repo
- Setup MongoDB on IBM Cloud
- Host competitors webpage on cloud
- Setup IBM Cloud Function
- Run the application
- Analyze the results
Clone this git repo. Else, in a terminal, run:
$ git clone https://github.com/IBM/analyze_ecommerce_websites_and_recommend_optimal_price
-
Create a MongoDB service on IBM Cloud.
-
Set the Admin Password for your deployment.
-
From the resources open Databases for MongoDB instance, and select Overview in the left panel as shown.
-
Scroll down to the Endpoints section and click on MongoDB, copy the
Endpoint
in a notepad and replace the$USERNAME
and$PASSWORD
with admin and password that you created previously. -
Scroll further down and download the
ssl
certificate and rename the file asssl4mongodb
as shown.
Note: this Endpoint
and ssl
certificate will be used in step 5.
-
Before you proceed, make sure you have installed IBM Cloud CLI in your deployment machine.
-
From the cloned repo, goto competitors-websites directory in terminal, and run the following commands to deploy the Application to IBM Cloud Foundry.
$ cd competitors-websites/
- Log in to your IBM Cloud account, and select an API endpoint.
$ ibmcloud login
NOTE: If you have a federated user ID, instead use the following command to log in with your single sign-on ID.
$ ibmcloud login --sso
- Target a Cloud Foundry org and space:
$ ibmcloud target --cf
- From within the competitors-websites directory push your app to IBM Cloud.
$ ibmcloud cf push competitors-websites
-
The manifest.yml file will be used here to deploy the application to IBM Cloud Foundry.
-
On Successful deployment of the application you will see something similar on your terminal as shown.
Invoking 'cf push'...
Pushing from manifest to org [email protected] / space dev as [email protected]...
...
Waiting for app to start...
name: competitors-websites
requested state: started
routes: competitors-websites.xx-xx.mybluemix.net
last uploaded: Sat 16 May 18:05:16 IST 2020
stack: cflinuxfs3
buildpacks: python
type: web
instances: 1/1
memory usage: 256M
start command: python app.py
state since cpu memory disk details
#0 running 2020-05-16T12:36:15Z 25.6% 116.5M of 256M 796.2M of 1
- Once the app is deployed you can visit the
routes
to launch the application.
Example:
Note: Since this is an open source project it is restricted to extract information from private ecommerce websites. Hence we are showcasing the pattern with custom websites.
- Copy the URL in this step, eg:
http://competitors-websites.xx-xx.mybluemix.net/
.This will be used in the next step.
IBM Cloud Function is a Serverless Architecture where in a user can write a snippet of code and run it as API's without worrying about deploying it. A code snippet can easily be attached to an already existing deployment to add more Functionality.
- Goto IBM Cloud Resources, and click on the hamburger menu and select Functions > Actions as shown.
- In Cloud Actions page, click on Create to get started.
- A Single entities list with Actions, Triger, Sequence, Quickstart Templates and Installable Packages will be presented. Select the Action to proceed.
- Enter a
name
for the action, you can either create a custom package or leave it asdefault package
and lastly select theRuntime
asPython 3.7
and click on Create.
- An IDE with Hello World code written in python will be presented, replace everything from the IDE with the code present in the file
pricing-tool.py
.
- After adding the code, update the URL from 3rd step as shown below. Click on the Save button to save the cloud function.
- Once the Cloud Function is code ready, you need to expose an API so that the Backend server can interact with the written code. Click on Endpoints and Enable as Web Action and finally click on Save button as shown.
- After you have enabled as Web Action you will see a
URL
, copy theURL
as it will be used in the next step.
- At this point, you have successfully setup a serverless cloud function.
- Add the Web Action URL copied in Step 4 and paste it on line number
47
in static/javascript/script.js
var url = "Enter the cloud functions url here";
-
Replace the
ENDPOINT-URL
on line number18
in app.py with the endpoint copied in step 2. -
Place the
ssl4mongodb
file downloaded in step 2 inside static/ssl/ directory. -
Now you can run the code in your local machine in one of the two ways mentioned below.
With Docker Installed
- change directory to repo parent folder :
$ cd analyze_ecommerce_websites_and_recommend_optimal_price/
- Build the Dockerfile as follows :
$ docker image build -t recommend_optimal_price .
- once the dockerfile is built run the dockerfile as follows :
$ docker run -p 8080:8080 recommend_optimal_price
- The Application will be available on http://localhost:8080
Without Docker
-
Install the python libraries as follows:
- change directory to repo parent folder
$ cd analyze_ecommerce_websites_and_recommend_optimal_price
- use
python pip
to install the libraries
$ pip install -r requirements.txt
-
Finally run the application as follows:
$ python app.py
- The Application will be available on http://localhost:8080
- After you launch the application, you will see a list of products the user/vendor is selling.
- Enter details as shown below and click on
Update Price
.
NOTE: Since the vendor gets the product directly from the manufacturer, he/she would be getting the product for a very low price compared to retail price.This difference in retail price and the price that the vendor bought is profit margin.
Enter profit margin
field takes in the total profit margin the user/vendor has on the product.Enter minimum required profit
field takes in the minimum profit the user/vendor is planning to make the product.
- Application gets the prices of the competitors who are selling this product online. Based on the data given, the application compares the prices of the competitors and returns an optimal selling price which could improve user's chances of selling the product and at the same time maintain the desired profits.
âšī¸ Refer to the below information to understand the terminology used on the UI tool. |
|
- After you set your price click on the
Update Price
button. This updates the price online on your e-commerce website.
This code pattern is licensed under the Apache License, Version 2. Separate third-party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 and the Apache License, Version 2.