stephenmcd/cartridge — Issue #17: Check if field exists in session before deleting
Author: k4ml
Created: 2012-02-19 08:26:33+00:00
State: open

With the settings SHOP_CHECKOUT_FORM_CLASS, user might be removing some of the fields such as the cc in their custom checkout form. This would raise KeyError when cartridge try to remove the field in the session:-

--- a/cartridge/shop/views.py
+++ b/cartridge/shop/views.py
@@ -192,7 +192,8 @@ def checkout_steps(request):
sensitive_card_fields = ("card_number", "card_expiry_month",
"card_expiry_year", "card_ccv")
for field in sensitive_card_fields:
- del request.session["order"][field]
+ if field in request.session["order"]:
+ del request.session["order"][field]

# FIRST CHECKOUT STEP - handle shipping and discount code.
if step == checkout.CHECKOUT_STEP_FIRST: