Siz tutorial - Online shopping cart (part 2)

in Steem Infinity Zone3 years ago


Hey steemit people!!

Hope you're fine and doing well here and as well as in your personal life. It's been a while I haven't shared anything or any tutorial with you. Today I am discussing the project that I made recently that was an online shopping cart. The project is made using the python language and completely on CLI. In this post, I will be covering only the class of all products and class of add to cart method while another or remaining portions of this project will be discussed in another post as a continuation. You won't get the code this way because I made a file named function where the functions are saved and I am recalling the functions from that file in the entire code. Stay tuned for the complete project.


PROBLEM DESCRIPTION:

Online shopping cart is a virtual shopping trolley, where shoppers can put all of
their want-to-buy products in, review to make adjustments in quantity, product
attributes, etc., and remove it before or during the checkout if they change their
mind.

FEATURES OF OUR SHOPPING CART:

• We used database SQLite which helps in maintaining the records easily and properly as
well.
• It has permanent storage of the users.
• Our shopping cart displays the products.
• It can export from cart.
• You can delete the items that you don’t want from cart.
• You can delete the history.
• It displays the entire history as well along with the time.

FILES IMPORTED

import functions
from datetime import datetime
import sys
import time
from abc import ABC, abstractmethod

CLASS ALL_PRODUCTS:

We have assigned all the products with a unique code. And search that code in the saved
products. If found any then proceed with that product and if not then shows an appropriate
message.



class all_product:
 def pick(self):
 print("PICK PRODUCT BY CODE: ")
 try:
 self.choice=input("ENTER CODE: ")
9
 flag=0
 for i in self.all:
 if i[0] == self.choice:
 print(i)
 print(flag)
 self.item_lst = i
 flag = 1

 if flag == 0:
 raise ValueError
 else:
 print("MOVING PRODUCT TO CART: ")
 c=add_to_cart()
 c.store_in_cart(self.item_lst)
 except ValueError:
 print("ENTER CORRECT CODE")
 self.pick()
 def __init__(self):
 elements=self.all=functions.show_all("user.db","product")
 for element in elements:
 print(element)
 self.pick()


CLASS ADD_TO_CART:

If the user selected the option of add to cart, then this will add the products to the cart. It will
update the database and add the selected items to the list. It stores the data as well.


class add_to_cart:
 def export(self):
 all_data=functions.show_all("user.db","cart")
 total=0
 lst=[]
 for i in all_data:
 print(i)
 if i[3]==username:
 total+=i[2]
 lst.append(i[1])
10
 print("TOTAL AMOUNT",total)
 s=shopping_history()
 s.add_to_history(total,lst)
 def choice(self):
 print("YOU HAVE MAKE ONE OF THE FOLLOWING : ")
 print("1.export for payment: ")
 print("2.Continue Shopping: ")
 print("3.Exit")
 try:
 self.choice=input("ENTER NUMBER: ")
 if self.choice=="1":
 self.export()
 elif self.choice=="2":
 p=all_product()
 elif self.choice=="3":
 sys.exit()
 else:
 raise ValueError
 except:
 print("ENTER CORRECT VALUE")
 def store_in_cart(self,ele_lst):
 self.lst=ele_lst
 functions.add_one_data("user.db","cart",(self.lst[0],self.lst[1],self.lst
[2],username))
 self.choice()
 def __init__(self)



THANK YOU FOR VISITING
CATCH YOU ON ANOTHER POST!
WITH BEST REGARDS
COUNTRY REPRESENTATIVE PAKISTAN


You can delegate your SP to @siz-official and take benefit of our Delegation Rewards Offer of getting up to 200% Curation Rewards

You can also use these quick delegation links. Just click on the desired amount of SP you want to delegate, and it will be done in the process of 1 minute.

Quick Delegation to SIZ
50 100 200 300 400 500 1000
2000 3000 4000 5000 10000

Divider 2.png

Steem Infinity Zone Team
@cryptokraze | @arie.steem | @qasimwaqar | @vvarishayy | @suboohi

Footer.png

Click Here to Join Official SIZ Discord Channel

Discord
Twitter
Facebook

Divider 2.png

Sort:  

Plz verify my Achievement 2
Achievement2 Basic security on steemit by @huzaiz1(19/10/2021)
It is going to expiring

 3 years ago 

You forgot to switch the account. It's suspecious, you're saying to verify your account and the achievement is of someone's else.

Coin Marketplace

STEEM 0.19
TRX 0.14
JST 0.030
BTC 60189.57
ETH 3204.49
USDT 1.00
SBD 2.44