Reputation: 1413
When a customer applies a voucher to an item in the cart and the voucher expires during the checkout process or inside the cart itself. During the checkout process, when clicked on place order
, the cart automatically empties and the customer is sent this error, You need to add some items to your basket to checkout
, this happens during the check_basket_is_not_empty method
.
Can someone help me understand which part of Django-Oscar could be modifying the cart in such drastic way. My initial thought was, that the cart was getting emptied because some oscar component was trying to remove the voucher and was removing the cart item as well. But during some more checks I find out that the voucher is successfully removed but the cart item only gets removed inside the PaymentDetailsView
, probably.
I don't have the code to PaymentDetailsView. I started the job as a Django developer a couple of days ago and I was thrown into this huge django-oscar code base, which I am completely unfamiliar with. I am not allowed to post any code online. I don't know what to do, and don't want to get fired. Any help would be highly appreciated.
Upvotes: 0
Views: 425
Reputation: 1413
I still don't know what's causing this bug, but I came up with this solution. When you click "place order", the PaymentDetailsView
class gets triggered, and the first function to deal with all the data is the submit
one. So inside that, you can manually check the vouchers you have in the request
and remove the vouchers manually.
# removing expired vouchers:
for voucher in self.request.basket.vouchers.all():
if voucher.is_expired() or not voucher.is_available_to_user(user=self.request.basket.owner)[0]:
self.request.basket.vouchers.remove(voucher)
messages.error(self.request,_("The '%(code)s' voucher has expired") % {'code': voucher.code})
Upvotes: 1