diff --git a/alkator/urls.py b/alkator/urls.py index df354cc..672c92d 100644 --- a/alkator/urls.py +++ b/alkator/urls.py @@ -24,7 +24,7 @@ from alkatorapi.views import ( invoice, upload_files, login_status, change_racer, products, cart_add, cart, cart_delete, - cart_decrease, cart_buy + cart_decrease, cart_buy, select_delivery, ) urlpatterns = [ @@ -46,5 +46,6 @@ urlpatterns = [ path('api/cart', cart), path('api/cart/delete', cart_delete), path('api/cart/decrease', cart_decrease), - path('api/cart/buy', cart_buy) + path('api/cart/buy', cart_buy), + path('api/cart/select_delivery', select_delivery), ] diff --git a/alkatorapi/models.py b/alkatorapi/models.py index fd4e812..36221bc 100644 --- a/alkatorapi/models.py +++ b/alkatorapi/models.py @@ -79,6 +79,7 @@ class Product(models.Model): class Cart(models.Model): user = models.OneToOneField(DjangoUser, on_delete=models.RESTRICT, related_name='cart') items = models.ManyToManyField(Product, through='CartProduct') + address = models.CharField(max_length=120, null=True, blank=True) class CartProduct(models.Model): diff --git a/alkatorapi/views.py b/alkatorapi/views.py index 7088bc1..82eb03f 100644 --- a/alkatorapi/views.py +++ b/alkatorapi/views.py @@ -375,7 +375,10 @@ def cart_add(request): def select_delivery(request): - pass + user.cart.address = request.GET['delivery'] + user.cart.save() + return HttpResponse('{"status":"success", "reason":"Úspěšně vybraná zásilkovna."}', status=200) + @csrf_exempt @@ -392,7 +395,7 @@ def cart_buy(request): invoice = Invoice( user=user, - address=user.profile.address, + address=cart.address if cart.adress else user.profile.address, invoice_id=Invoice.next_invoice_id(), total_price=0, ) diff --git a/frontend/src/scripts/index.js b/frontend/src/scripts/index.js index 4c1cea9..4a6e3ad 100644 --- a/frontend/src/scripts/index.js +++ b/frontend/src/scripts/index.js @@ -195,7 +195,19 @@ class Main extends Component { })); }; selectDeliveryCallback(point){ - console.log(point) + fetch(addr_prefix + '/api/cart/select_delivery?delivery='+point.name).then(resp => resp.json()).then(json => { + if(json.status == "failed"){ + this.setState({ + status_text: json.reason, + status: "failed", + }) + }else{ + this.setState({ + status_text: json.reason, + status: "success", + }) + } + }); } selectDelivery = () => { Packeta.Widget.pick("8599115769fd895b", this.selectDeliveryCallback.bind(this)) @@ -318,7 +330,6 @@ class Main extends Component { } {this.state.page == "#cart" &&
-