-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31b9bd0
commit 0359b2e
Showing
11 changed files
with
62 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,63 @@ | ||
from django.shortcuts import render # noqa | ||
from django.shortcuts import get_object_or_404, redirect, render | ||
from django.views.decorators.http import require_POST | ||
from apps.shop.models import Product | ||
from apps.coupons.forms import CouponApplyForm | ||
from .cart import Cart | ||
from .forms import CartAddProductForm as CartUpdateProductForm | ||
from .forms import CartAddProductForm as CartAddProductForm | ||
|
||
# Create your views here. | ||
|
||
@require_POST | ||
def cart_add(request, product_id): | ||
cart = Cart(request) | ||
product = get_object_or_404(Product, id=product_id) | ||
form = CartAddProductForm(request.POST) | ||
if form.is_valid(): | ||
cd = form.cleaned_data | ||
cart.add( | ||
product=product, | ||
qty=cd["quantity"], | ||
) | ||
return redirect("cart:cart_detail") | ||
|
||
|
||
@require_POST | ||
def cart_update(request, product_id): | ||
cart = Cart(request) | ||
product = get_object_or_404(Product, id=product_id) | ||
form = CartUpdateProductForm(request.POST) | ||
if form.is_valid(): | ||
cd = form.cleaned_data | ||
cart.update( | ||
product=product, | ||
qty=cd["quantity"] | ||
) | ||
return redirect("cart:cart_detail") | ||
|
||
|
||
@require_POST | ||
def cart_remove(request, product_id): | ||
cart = Cart(request) | ||
product = get_object_or_404(Product, id=product_id) | ||
cart.delete(product) | ||
return redirect("cart:cart_detail") | ||
|
||
|
||
@require_POST | ||
def cart_detail(request): | ||
cart = Cart(request) | ||
|
||
for item in cart: | ||
item["update_quantity_form"] = CartAddProductForm( | ||
initial={"quantity": item["quantity"], "override": True} | ||
) | ||
coupon_apply_form = CouponApplyForm() | ||
|
||
return render( | ||
request, | ||
"cart/detail.html", | ||
{ | ||
"cart": cart, | ||
"coupon_apply_form": coupon_apply_form, | ||
} | ||
) |
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.