This commit is contained in:
Martin Quarda 2024-10-14 10:16:31 +02:00
parent f2dc359c8e
commit 8b29bbab64
3 changed files with 5 additions and 3 deletions

View File

@ -83,7 +83,7 @@ class Cart(models.Model):
class CartProduct(models.Model):
product = models.ForeignKey(Product, on_delete=models.RESTRICT)
cart = models.ForeignKey('Cart', on_delete=models.RESTRICT)
cart = models.ForeignKey('Cart', on_delete=models.CASCADE)
class Meta:
unique_together = ('product', 'cart')
quantity = models.IntegerField()

View File

@ -427,11 +427,13 @@ def cart_buy(request):
result = parse_qs(result.text)
if result['code'][0] != '0':
racer.delete()
for ip in InvoiceProduct.objects.filter(invoice=invoice):
ip.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')
invoice.trans_id = result['transId'][0]
cart.delete()
invoice.save()
return HttpResponse('{"success":"", "redirect":"' + result['redirect'][0] + '"}', content_type='application/json')

View File

@ -338,7 +338,7 @@ class Main extends Component {
<td>Celkem</td>
<td></td>
<td>{this.calculateTotalPrice()} </td>
<td><form action='/api/cart/buy' onSubmit={(e) => this.onSubmit(e)}><button type="submit">Koupit</button></form></td>
<td><form id="form" action='/api/cart/buy' onSubmit={(e) => this.onSubmit(e)}><button class="btn btn-primary" type="submit">Koupit</button></form></td>
</tr>
</tbody>
</table>