django-oscar / django-oscar

Domain-driven e-commerce for Django

Home Page:http://oscarcommerce.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cash on delivery feature is missing, please add this feature.

polow opened this issue · comments

commented

The old cash on delivery app created by @SalahAdDin is not working anymore, if anyone can add this feature in the checkout that would be great.

Hi!

It's not very difficult to add this feature, we use this code for testing purposes:

Because the "payment event" is after delivery, there is no need to handle payment in PaymentDetailView, you can just redirect to preview.

  • add a PaymentSourceType:

$ ./manage.py shell

>>> from oscar.core.loading import get_model
>>> SourceType = get_model('payment', 'SourceType')
>>> SourceType.objects.create(name='Cash on delivery')
  • fork checkout app:
    $ ./manage.py fork_app checkout <yourapp>

  • edit <yourapp>/checkout/views.py to redirect from PaymentMethodView directly to preview, if selected payment method is cash-on-delivery:

from django.shortcuts import redirect
from django.urls import reverse
from oscar.apps.checkout.views import PaymentMethodView as OscarPaymentMethodView

class PaymentMethodView(OscarPaymentMethodView):

    def form_valid(self, form):
        """
        redirect to preview if payment_method == cash-on-delivery
        """
        payment_method = form.cleaned_data["payment_method"]
        self.checkout_session.pay_by(payment_method.code)
        if payment_method.code == 'cash-on-delivery':
            return redirect(reverse("checkout:preview"))
        return super().form_valid(form)

With this, after choosing "Cash on delivery", the user is redirected to preview page where he can finally submit his order.