add of checkout form
This commit is contained in:
parent
ccee783a98
commit
59073ad8c2
|
@ -68,7 +68,9 @@ class AddToCartForm(forms.Form):
|
||||||
|
|
||||||
|
|
||||||
class CartForm(forms.Form):
|
class CartForm(forms.Form):
|
||||||
|
print('CartForm')
|
||||||
def ChangeAmount(self):
|
def ChangeAmount(self):
|
||||||
|
print('CartForm.ChangeAmount')
|
||||||
article = OrderPosition.objects.filter(pk=self.id)
|
article = OrderPosition.objects.filter(pk=self.id)
|
||||||
amountfield = forms.IntegerField(
|
amountfield = forms.IntegerField(
|
||||||
label='pce',
|
label='pce',
|
||||||
|
@ -76,3 +78,10 @@ class CartForm(forms.Form):
|
||||||
initial=article.amount
|
initial=article.amount
|
||||||
)
|
)
|
||||||
return amountfield
|
return amountfield
|
||||||
|
|
||||||
|
|
||||||
|
class CheckoutForm(forms.Form):
|
||||||
|
|
||||||
|
checkout = forms.BooleanField(
|
||||||
|
required=True,
|
||||||
|
label='Yes. I have read the General Terms and Conditions.')
|
||||||
|
|
|
@ -23,7 +23,14 @@
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td scope="col">{{ article.article.stock }}</td>
|
<td scope="col">{{ article.article.stock }}</td>
|
||||||
<td scope="col">{{ article.amount }}</td>
|
<td scope="col">
|
||||||
|
<form id="amountfield" action="" method="POST" novalidate>
|
||||||
|
{{ CartForm }}
|
||||||
|
<input type="submit" value="change" />
|
||||||
|
{% csrf_token %}
|
||||||
|
</form>
|
||||||
|
<!-- {{ article.amount }} -->
|
||||||
|
</td>
|
||||||
<td scope="col">
|
<td scope="col">
|
||||||
{{ article.article.price_in_chf }}
|
{{ article.article.price_in_chf }}
|
||||||
{{ currency_name }}
|
{{ currency_name }}
|
||||||
|
@ -37,9 +44,22 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
<form id="checkout" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ checkout_form.as_p }}
|
||||||
|
<input type="submit" value="checkout ->" />
|
||||||
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p class="alert">
|
<p class="alert alert-danger">
|
||||||
There are currently no articles in your cart.
|
<strong>
|
||||||
|
This cart seams to lack some Items.
|
||||||
|
Go get some in the store!
|
||||||
|
<strong>
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<p class="alert text-danger">
|
||||||
|
<strong>
|
||||||
|
{{ message }}
|
||||||
|
<strong>
|
||||||
|
</p>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -5,7 +5,7 @@ from django.shortcuts import get_object_or_404, render
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.auth.forms import UserCreationForm
|
from django.contrib.auth.forms import UserCreationForm
|
||||||
|
from django.db import transaction
|
||||||
from webshop.models import (Article,
|
from webshop.models import (Article,
|
||||||
Category,
|
Category,
|
||||||
ArticleStatus,
|
ArticleStatus,
|
||||||
|
@ -16,7 +16,8 @@ from webshop.models import (Article,
|
||||||
ShoppingCart)
|
ShoppingCart)
|
||||||
from webshop.forms import (RegistrationForm,
|
from webshop.forms import (RegistrationForm,
|
||||||
AddToCartForm,
|
AddToCartForm,
|
||||||
CartForm)
|
CartForm,
|
||||||
|
CheckoutForm)
|
||||||
from webshop.utils import (get_categories,
|
from webshop.utils import (get_categories,
|
||||||
get_hidden_status_id,
|
get_hidden_status_id,
|
||||||
process_article_prices)
|
process_article_prices)
|
||||||
|
@ -208,6 +209,7 @@ def cart(request):
|
||||||
currency = request.session['currency']
|
currency = request.session['currency']
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
print(request.POST)
|
||||||
# here we react to a currency dropdown change:
|
# here we react to a currency dropdown change:
|
||||||
if 'currencies' in request.POST:
|
if 'currencies' in request.POST:
|
||||||
currencies_form = CurrenciesForm(request.POST)
|
currencies_form = CurrenciesForm(request.POST)
|
||||||
|
@ -221,8 +223,8 @@ def cart(request):
|
||||||
else:
|
else:
|
||||||
request.session['currency'] = None
|
request.session['currency'] = None
|
||||||
# here we react to a change of amount per item in the Cart:
|
# here we react to a change of amount per item in the Cart:
|
||||||
if 'amount' in request.POST:
|
if 'amount_in_cart' in request.POST:
|
||||||
print(request.POST)
|
print('yes amount post')
|
||||||
amount = CartForm.ChangeAmount(request.POST)
|
amount = CartForm.ChangeAmount(request.POST)
|
||||||
if amount.is_valid():
|
if amount.is_valid():
|
||||||
amount = amount.cleaned_data['amount']
|
amount = amount.cleaned_data['amount']
|
||||||
|
@ -240,8 +242,18 @@ def cart(request):
|
||||||
)
|
)
|
||||||
cart_position.save()
|
cart_position.save()
|
||||||
amount = CartForm.ChangeAmount()
|
amount = CartForm.ChangeAmount()
|
||||||
|
|
||||||
|
if 'checkout' in request.POST:
|
||||||
|
checkout_form = CheckoutForm(request.POST)
|
||||||
|
if checkout_form.is_valid():
|
||||||
|
checkout_form = checkout_form.cleaned_data['checkout']
|
||||||
|
print('views checkout checkout_form', checkout_form)
|
||||||
|
if checkout_form is True:
|
||||||
|
# add to order
|
||||||
|
order = ''
|
||||||
else:
|
else:
|
||||||
amount = AddToCartForm()
|
message = 'Plese accept our General Terms and Conditions!'
|
||||||
|
checkout_form = CheckoutForm()
|
||||||
# if the cart_id is set the user has already added items to cart.
|
# if the cart_id is set the user has already added items to cart.
|
||||||
try:
|
try:
|
||||||
cart_id = ShoppingCart.objects.get(user=request.user)
|
cart_id = ShoppingCart.objects.get(user=request.user)
|
||||||
|
@ -249,11 +261,11 @@ def cart(request):
|
||||||
message = "You have no items in the Basket"
|
message = "You have no items in the Basket"
|
||||||
|
|
||||||
if cart_id:
|
if cart_id:
|
||||||
|
print(cart_id)
|
||||||
articles = CartPosition.objects.filter(cart=cart_id)
|
articles = CartPosition.objects.filter(cart=cart_id)
|
||||||
articles_list = list(articles)
|
articles_list = list(articles)
|
||||||
# scrap out the details to calculate Total of item and Summ of All:
|
# scrap out the details to calculate Total of item and Summ of All:
|
||||||
for idx, article in enumerate(articles_list):
|
for idx, article in enumerate(articles_list):
|
||||||
print(article, idx)
|
|
||||||
article.calculate_position_price()
|
article.calculate_position_price()
|
||||||
if currency:
|
if currency:
|
||||||
article.price_in_chf = rate.exchange(
|
article.price_in_chf = rate.exchange(
|
||||||
|
@ -275,6 +287,7 @@ def cart(request):
|
||||||
'totalprice_list': totalprice_list,
|
'totalprice_list': totalprice_list,
|
||||||
'total': total,
|
'total': total,
|
||||||
'currencies_form': currencies_form,
|
'currencies_form': currencies_form,
|
||||||
|
'checkout_form': checkout_form,
|
||||||
'article_view': article_view,
|
'article_view': article_view,
|
||||||
'currency_name': currency_name,
|
'currency_name': currency_name,
|
||||||
'category_list': category_list,
|
'category_list': category_list,
|
||||||
|
|
Loading…
Reference in New Issue