Skip to content

Commit

Permalink
Merge pull request #2 from anurag6569201/master
Browse files Browse the repository at this point in the history
Master
  • Loading branch information
anurag6569201 authored Feb 7, 2024
2 parents 9466212 + 996a611 commit a7ca54d
Show file tree
Hide file tree
Showing 25 changed files with 400 additions and 130 deletions.
6 changes: 6 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set -o errexit

pip install -r requirements.txt

python manage.py collectstatic --noinput
python manage.py migrate
Binary file modified core/__pycache__/models.cpython-312.pyc
Binary file not shown.
Binary file modified core/__pycache__/urls.cpython-312.pyc
Binary file not shown.
Binary file modified core/__pycache__/views.cpython-312.pyc
Binary file not shown.
36 changes: 36 additions & 0 deletions core/migrations/0016_cartorder_razor_pay_order_id_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 5.0 on 2024-02-06 17:12

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0015_alter_product_description_and_more'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.AddField(
model_name='cartorder',
name='razor_pay_order_id',
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AddField(
model_name='cartorder',
name='razor_pay_payment_id',
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AddField(
model_name='cartorder',
name='razor_pay_payment_signature',
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AlterField(
model_name='productreview',
name='user',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='review', to=settings.AUTH_USER_MODEL),
),
]
Binary file not shown.
3 changes: 3 additions & 0 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ class CartOrder(models.Model):
paid_track = models.BooleanField(default=False)
order_date = models.DateTimeField(auto_now_add=True)
product_status = models.CharField(choices=STATUS_CHOICES, max_length=30, default="processing")
razor_pay_order_id=models.CharField(max_length=100,null=True,blank=True)
razor_pay_payment_id=models.CharField(max_length=100,null=True,blank=True)
razor_pay_payment_signature=models.CharField(max_length=100,null=True,blank=True)

class Meta:
verbose_name_plural = "Cart Orders"
Expand Down
4 changes: 1 addition & 3 deletions core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
#add to cart
path("add-to-cart/",views.add_to_cart,name="add-to-cart"),
path("cart/",views.cart_view,name="cart"),
path("delete-cart/",views.delete_item_from_cart,name="delete-cart"),
path("update-cart/",views.update_from_cart,name="update-cart"),

# checkout
path("checkout/",views.checkout_view,name="checkout"),
path("checkout/success/",views.success,name="success"),
]
49 changes: 26 additions & 23 deletions core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from django.http import JsonResponse
from django.shortcuts import redirect
from django.template.loader import render_to_string
import razorpay
from django.conf import settings

@login_required(login_url='/user/sign-in')
def index(request):
Expand Down Expand Up @@ -196,27 +198,17 @@ def cart_view(request):
if 'cart_data_obj' in request.session:
for product_id,item in request.session['cart_data_obj'].items():
cart_total_amount+=int(item['qty'])*float(item['price'])
return render(request,"core/cart.html",{"cart_data":request.session['cart_data_obj'],'totalcartitems':len(request.session['cart_data_obj']),'cart_total_amount':cart_total_amount})

client=razorpay.Client(auth=(settings.KEY,settings.SECRET))
payment=client.order.create({'amount':cart_total_amount*100,'currency':'INR','payment_capture':1})
cart_order, created = CartOrder.objects.get_or_create(user=request.user)
cart_order.price = cart_total_amount # Update the total price if necessary
cart_order.save()

return render(request,"core/cart.html",{"cart_data":request.session['cart_data_obj'],'totalcartitems':len(request.session['cart_data_obj']),'cart_total_amount':cart_total_amount,'payment':payment})
else:
return render(request,"core/cart.html",{"cart_data":'','totalcartitems':len(request.session['cart_data_obj']),'cart_total_amount':cart_total_amount})

def delete_item_from_cart(request):
product_id=str(request.GET['id'])
if 'cart_data_obj' in request.session:
if product_id in request.session['cart_data_obj']:
cart_data=request.session['cart_data_obj']
del request.session['cart_data_obj'][product_id]
request.session['cart_data_obj']=cart_data

cart_total_amount=0
if 'cart_data_obj' in request.session:
for product_id,item in request.session['cart_data_obj'].items():
cart_total_amount+=int(item['qty'])*float(item['price'])

context={"core/async/cart-list.html",{"cart_data":request.session['cart_data_obj'],'totalcartitems':len(request.session['cart_data_obj']),'cart_total_amount':cart_total_amount}}

return JsonResponse({"data":context,'totalcartitems':len(request.session['cart_data_obj'])})


def update_from_cart(request):
product_id=str(request.GET['id'])
Expand All @@ -232,16 +224,27 @@ def update_from_cart(request):
for product_id,item in request.session['cart_data_obj'].items():
cart_total_amount+=int(item['qty'])*float(item['price'])

context=render_to_string("core/async/cart-list.html",{"cart_data":request.session['cart_data_obj'],'totalcartitems':len(request.session['cart_data_obj']),'cart_total_amount':cart_total_amount})
client=razorpay.Client(auth=(settings.KEY,settings.SECRET))
payment=client.order.create({'amount':cart_total_amount*100,'currency':'INR','payment_capture':1})
cart_order, created = CartOrder.objects.get_or_create(user=request.user)
cart_order.price = cart_total_amount # Update the total price if necessary
cart_order.save()


context=render_to_string("core/async/cart-list.html",{"cart_data":request.session['cart_data_obj'],'totalcartitems':len(request.session['cart_data_obj']),'cart_total_amount':cart_total_amount,'payment':payment})

return JsonResponse({"data":context,'totalcartitems':len(request.session['cart_data_obj'])})


def checkout_view(request):
def success(request):
cart_total_amount=0
if 'cart_data_obj' in request.session:
for product_id,item in request.session['cart_data_obj'].items():
cart_total_amount+=int(item['qty'])*float(item['price'])


return render(request,"core/checkout.html",{"cart_data":request.session['cart_data_obj'],'totalcartitems':len(request.session['cart_data_obj']),'cart_total_amount':cart_total_amount})

order_id=request.GET.get('order_id')
cart=CartOrder.objects.get(razor_pay_order_id=order_id)
cart.paid_track=True
cart.save()

return render(request,"core/success.html",{"cart_data":request.session['cart_data_obj'],'totalcartitems':len(request.session['cart_data_obj']),'cart_total_amount':cart_total_amount})
Binary file modified db.sqlite3
Binary file not shown.
Binary file modified ecomprj/__pycache__/settings.cpython-312.pyc
Binary file not shown.
Binary file modified ecomprj/__pycache__/urls.cpython-312.pyc
Binary file not shown.
26 changes: 18 additions & 8 deletions ecomprj/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = '[*]'
ALLOWED_HOSTS = ["anu6569.onrender.com",'127.0.0.1','localhost']


# Application definition
Expand Down Expand Up @@ -58,6 +58,9 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',

# render.com middleware
'whitenoise.middleware.WhiteNoiseMiddleware',
]

ROOT_URLCONF = 'ecomprj.urls'
Expand Down Expand Up @@ -85,12 +88,12 @@
# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases

# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': BASE_DIR / 'db.sqlite3',
# }
# }
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


# Password validation
Expand Down Expand Up @@ -133,6 +136,10 @@
MEDIA_URL='/media/'
MEDIA_ROOT=os.path.join(BASE_DIR,'media')


# renderstorage
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
# ......
# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

Expand Down Expand Up @@ -171,4 +178,7 @@
'codesnippet'
]),
}
}
}

KEY='rzp_test_LcYoGkJW1B1wMM'
SECRET='9u4i7XvFk9Oh1QnTJGXBD43V'
57 changes: 57 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
asgiref==3.7.2
attrs==23.2.0
beautifulsoup4==4.12.3
branca==0.7.0
bs4==0.0.2
certifi==2021.5.30
charset-normalizer==2.0.3
click==8.1.7
click-plugins==1.1.1
cligj==0.7.2
colorama==0.4.6
Django==5.0
django-ckeditor==6.7.0
django-crispy-forms==2.1
django-jazzmin==2.6.0
django-js-asset==2.2.0
django-paypal==2.0
django-shortuuidfield==0.1.3
django-taggit==5.0.1
fiona==1.9.5
folium==0.15.1
geographiclib==2.0
geopandas==0.14.2
geopy==2.4.1
gunicorn==21.2.0
humanfriendly==9.2
idna==3.2
Jinja2==3.1.3
joblib==1.3.2
MarkupSafe==2.1.4
networkx==3.2.1
numpy==1.26.3
osmnx==1.8.1
packaging==23.2
pandas==2.2.0
Pillow==10.1.0
pycryptodome==3.20.0
pyproj==3.6.1
pyreadline==2.1
python-dateutil==2.8.2
pytz==2021.1
razorpay==1.4.1
requests==2.31.0
scikit-learn==1.4.0
scipy==1.12.0
setuptools==69.0.3
shapely==2.0.2
shortuuid==1.0.11
six==1.16.0
soupsieve==2.5
sqlparse==0.4.4
threadpoolctl==3.2.0
tzdata==2023.3
ulid-py==1.1.0
urllib3==1.26.6
whitenoise==6.6.0
xyzservices==2023.10.1
29 changes: 1 addition & 28 deletions static/assets/css/checkout.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ input:focus::-webkit-input-placeholder
background-color: #ffffff;
padding: 2vh;
}
.checking-out .left img{
width: 2rem;
}
.checking-out .left .col-4{
padding-left: 0;
}
Expand All @@ -88,28 +85,7 @@ input:focus::-webkit-input-placeholder
.checking-out .lower{
line-height: 2;
}
.checking-out .btn{
background-color: rgb(23, 4, 189);
border-color: rgb(23, 4, 189);
color: white;
width: 100%;
font-size: 0.7rem;
margin: 4vh 0 1.5vh 0;
padding: 1.5vh;
border-radius: 0;
}
.checking-out .btn:focus{
box-shadow: none;
outline: none;
box-shadow: none;
color: white;
-webkit-box-shadow: none;
-webkit-user-select: none;
transition: none;
}
.checking-out .btn:hover{
color: white;
}

.checking-out input[type=checkbox]{
width: unset;
margin-bottom: unset;
Expand All @@ -120,6 +96,3 @@ input:focus::-webkit-input-placeholder
background-position-x: 95%;
background-position-y: center;
}
#cvv:hover{

}
13 changes: 13 additions & 0 deletions static/assets/css/success.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.invoice-page{
margin-top: 60px;
text-align: center;
}
.a4-paper{
background-color: #f4f6f9;
width: 21cm;
height: 29.7cm;
padding: 2em;
}
.invoice-item-price{
font-size: 1.4em;
}
22 changes: 0 additions & 22 deletions static/assets/js/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,6 @@ $(document).ready(function(){
})
})

$(".close").on('click', function() {
let product_id=$(this).attr("data-product");
let this_val=$(this);
console.log(product_id);
console.log(this_val);
$.ajax({
url:'/update-cart',
data:{
'id':product_id,
},
datatype:"json",
beforeSend:function(){
this_val.hide()
},
success:function(res){
this_val.show()
$(".cart-items-count").text(res.totalcartitems)
$("#cart-list").html(res.data)
}
})
})

$(".update-cart").on('click', function() {
let product_id=$(this).attr("data-product");
let this_val=$(this);
Expand Down
Loading

0 comments on commit a7ca54d

Please sign in to comment.