stephenmcd/cartridge — pull request #85 by AlexHill (2013-01-24 06:24:09+00:00)
Title: Refactor checkout POST data preprocessing

Currently, `OrderForm.__init__` does some preprocessing of data - copying billing fields to shipping fields if `same_billing_shipping` is true. This change factors that preprocessing out into a class method, and passes request.POST to that method in `shop.checkout.initial_order_data` so that the order form's `initial` argument contains the preprocessed data.

I have a highly customised order form which subclasses Cartridge's. I wanted to infer the CC type from the number, and was doing so and setting `data["card_type"]` in my subclass's __init__. However because [the displayed OrderForm isn't passed a `data` argument, only `initial`](https://github.com/stephenmcd/cartridge/blob/master/cartridge/shop/views.py#L261-263), the card type never made it to the confirmation page.

You can see this same bug if you turn off JS and go through the Cartridge checkout. If you tick the `same_billing_shipping` checkbox and complete the order process, the shipping fields on the resulting order are blank.

As well as fixing this bug and making the JS redundant, this change means that you can easily add more checkout preprocessing by simply overriding `preprocess` on an OrderForm subclass.