diff --git a/ecommerce/coupons/views.py b/ecommerce/coupons/views.py index bd0ba2cec52..75d5834b56c 100644 --- a/ecommerce/coupons/views.py +++ b/ecommerce/coupons/views.py @@ -169,20 +169,27 @@ def get(self, request): # pylint: disable=too-many-statements if not sku: return render(request, template_name, {'error': _('SKU not provided.')}) + try: + product = StockRecord.objects.get(partner_sku=sku).product + except StockRecord.DoesNotExist: + return render(request, template_name, {'error': _('The product does not exist.')}) + try: voucher = Voucher.objects.get(code=code) except Voucher.DoesNotExist: + try: + basket = prepare_basket(request, [product]) + except AlreadyPlacedOrderException: + msg = _('You have already purchased {course} seat.').format(course=product.course.name) + return render(request, template_name, {'error': msg}) + msg = 'No voucher found with code {code}'.format(code=code) messages.error(self.request, _(msg)) + redirect_url = get_payment_microfrontend_or_basket_url(self.request) + "?coupon_redeem_redirect=1" redirect_url = add_stripe_flag_to_url(redirect_url, self.request) return HttpResponseRedirect(redirect_url) - try: - product = StockRecord.objects.get(partner_sku=sku).product - except StockRecord.DoesNotExist: - return render(request, template_name, {'error': _('The product does not exist.')}) - valid_voucher, msg, hide_error_message = voucher_is_valid(voucher, [product], request) if not valid_voucher: logger.warning('[Code Redemption Failure] The voucher is not valid for this product. '