def create_order(self, request, *args, **kwargs): self.process_request() request.basket.status = OrderStatus.objects.get_default_initial() errors = [] for error in request.basket.get_validation_errors(): errors.append({"code": error.code, "message": "%s" % error.message}) if len(errors): return Response({"errors": errors}, status=status.HTTP_400_BAD_REQUEST) order_creator = get_basket_order_creator() customer_id = request.POST.get("customer_id") if not customer_id: customer_id = request.data.get("customer_id") if customer_id: is_staff = (not self.request.shop or not self.request.user.is_staff or self.request.user.pk not in self.request.shop.staff_members.all().values_list("pk", flat=True)) is_superuser = self.request.user.is_superuser if is_superuser or is_staff: from shuup.core.models import PersonContact customer = PersonContact.objects.get(pk=customer_id) request.basket.customer = customer order = order_creator.create_order(request.basket) request.basket.finalize() return Response(data=OrderSerializer(order).data, status=status.HTTP_201_CREATED)
def create_order(self, request, *args, **kwargs): self.process_request() request.basket.status = OrderStatus.objects.get_default_initial() errors = [] for error in request.basket.get_validation_errors(): errors.append({"code": error.code, "message": "%s" % error.message}) if len(errors): return Response({"errors": errors}, status=status.HTTP_400_BAD_REQUEST) order_creator = get_basket_order_creator() customer_id = request.POST.get("customer_id") if not customer_id: customer_id = request.data.get("customer_id") if customer_id: # staff and superuser can set custom customer to the basket is_staff = self.is_staff_user(self.request.shop, self.request.user) is_superuser = self.request.user.is_superuser if is_superuser or is_staff: from shuup.core.models import PersonContact customer = PersonContact.objects.get(pk=customer_id) request.basket.customer = customer order = order_creator.create_order(request.basket) request.basket.finalize() return Response(data=OrderSerializer(order).data, status=status.HTTP_201_CREATED)
def create_order(self, request, *args, **kwargs): self.process_request() request.basket.status = OrderStatus.objects.get_default_initial() errors = [] for error in request.basket.get_validation_errors(): errors.append({"code": error.code, "message": "%s" % error.message}) if len(errors): return Response({"errors": errors}, status=status.HTTP_400_BAD_REQUEST) order_creator = get_basket_order_creator() order = order_creator.create_order(request.basket) request.basket.finalize() return Response(data=OrderSerializer(order).data, status=status.HTTP_201_CREATED)
def create_order(self, request, *args, **kwargs): self.process_request() request.basket.status = OrderStatus.objects.get_default_initial() errors = [] for error in request.basket.get_validation_errors(): errors.append({"code": error.code, "message": "%s" % error.message}) if len(errors): return Response({"errors": errors}, status=status.HTTP_400_BAD_REQUEST) order_creator = get_basket_order_creator() order = order_creator.create_order(request.basket) request.basket.finalize() return Response(data=OrderSerializer(order).data, status=status.HTTP_201_CREATED)