alesdotio / django-shop-multiplecurrencies

Multiple currencies for Django Shop
6 stars 2 forks source link

Changing the currency on the ThankYouView causes the order to change currencies without recalculating prices #1

Open alesdotio opened 12 years ago

alesdotio commented 12 years ago

This allows users to change the currency on a completed order while maintaining the same price values. Ouch.

Overriding the default ThankYouView fixes the problem:

class FixedThankYouView(ThankYouView):
    template_name = 'shop/checkout/thank_you.html'

    def get_context_data(self, **kwargs):
        ctx = super(ShopTemplateView, self).get_context_data(**kwargs)

        # Set the order status:
        order = get_order_from_request(self.request)

        # check if the order is completed, otherwise changing the currency causes the 
        # order to be saved again without recalculating new currency prices !!!!!
        if order and not order.status == Order.COMPLETED:
            order.status = Order.COMPLETED
            order.save()
            completed.send(sender=self, order=order)
        else:
            order = Order.objects.get_latest_for_user(self.request.user)
            #TODO: Is this ever the case?
        ctx.update({'order': order, })

        # Empty the customers basket, to reflect that the purchase was
        # completed
        cart_object = get_or_create_cart(self.request)
        cart_object.empty()

        return ctx
alesdotio commented 12 years ago

this fix will not be needed in shop > 0.0.13