This commit is contained in:
Martin Quarda 2024-10-14 10:22:09 +02:00
parent 8b29bbab64
commit d024860a59

View File

@ -394,8 +394,10 @@ def cart_buy(request):
invoice = Invoice( invoice = Invoice(
user=user, user=user,
address=user.profile.address, address=user.profile.address,
invoice_id=Invoice.next_invoice_id() invoice_id=Invoice.next_invoice_id(),
total_price=0,
) )
total_price = 0
invoice.save() invoice.save()
for cp in cart_products: for cp in cart_products:
@ -407,12 +409,13 @@ def cart_buy(request):
) )
cp.product.quantity -= cp.quantity cp.product.quantity -= cp.quantity
cp.product.save() cp.product.save()
total_price += cp.quantity * cp.product.price
ip.save() ip.save()
payment_data = { payment_data = {
'merchant': COMGATE_MERCHANT, 'merchant': COMGATE_MERCHANT,
'test': 'true' if COMGATE_TEST else 'false', 'test': 'true' if COMGATE_TEST else 'false',
'price': invoice.calculate_total_price() * 100, 'price': total_price * 100,
'curr': 'CZK', 'curr': 'CZK',
'method': 'ALL', 'method': 'ALL',
'label': 'Merch Alkátor Race', 'label': 'Merch Alkátor Race',
@ -432,6 +435,7 @@ def cart_buy(request):
invoice.delete() invoice.delete()
return HttpResponse('{"reason":"Chyba na straně platební brány: ' + result['message'][0] + ', zkuste prosím nákup později."}', status=400, content_type='application/json') return HttpResponse('{"reason":"Chyba na straně platební brány: ' + result['message'][0] + ', zkuste prosím nákup později."}', status=400, content_type='application/json')
invoice.total_price = total_price
invoice.trans_id = result['transId'][0] invoice.trans_id = result['transId'][0]
cart.delete() cart.delete()
invoice.save() invoice.save()