Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
fix: empty basket for new user
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Noyan Aziz authored and Muhammad Noyan Aziz committed Jul 9, 2024
1 parent 4e60085 commit 414d703
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions ecommerce/coupons/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. '
Expand Down

0 comments on commit 414d703

Please sign in to comment.