from django.shortcuts import render from oscar.checkout.views import (ShippingMethodView as CoreShippingMethodView, PaymentMethodView as CorePaymentMethodView, PaymentDetailsView as CorePaymentDetailsView, OrderPreviewView as CoreOrderPreviewView, prev_steps_must_be_complete) from oscar.payment.forms import BankcardForm, BillingAddressForm from oscar.services import import_module shipping_models = import_module('shipping.models', ['Method']) payment_models = import_module('payment.models', ['Source', 'SourceType']) class ShippingMethodView(CoreShippingMethodView): def get_available_shipping_methods(self): codes = ['royal-mail-first-class'] for line in self.basket.lines.all(): if line.product.stockrecord.partner_id == 2: codes.append('parcel-force') return shipping_models.Method.objects.filter(code__in=codes) class PaymentMethodView(CorePaymentMethodView): template_file = 'checkout/payment_method.html' def handle_GET(self): return render(self.request, self.template_file, self.context) def handle_POST(self): method = self.request.POST['method_code']
from django.forms import ModelForm, CharField, HiddenInput from oscar.checkout.forms import ShippingAddressForm as CoreShippingAddressForm from oscar.services import import_module address_models = import_module('address.models', ['Country']) order_models = import_module('order.models', ['ShippingAddress']) class ShippingAddressForm(CoreShippingAddressForm): # Overriding form widgets (and labels) line4 = CharField(label='County', required=False) postcode = CharField(label='Postcode') class Meta: model = order_models.ShippingAddress exclude = ('title', 'user', 'notes') def set_country_queryset(self): self.fields['country'].queryset = address_models.Country.objects.filter(is_shipping_country=True)
from django.shortcuts import render from oscar.checkout.views import (ShippingMethodView as CoreShippingMethodView, PaymentMethodView as CorePaymentMethodView, PaymentDetailsView as CorePaymentDetailsView, OrderPreviewView as CoreOrderPreviewView, prev_steps_must_be_complete) from oscar.payment.forms import BankcardForm, BillingAddressForm from oscar.services import import_module shipping_models = import_module('shipping.models', ['Method']) payment_models = import_module('payment.models', ['Source', 'SourceType']) class ShippingMethodView(CoreShippingMethodView): def get_available_shipping_methods(self): codes = ['royal-mail-first-class'] for line in self.basket.lines.all(): if line.product.stockrecord.partner_id == 2: codes.append('parcel-force') return shipping_models.Method.objects.filter(code__in=codes) class PaymentMethodView(CorePaymentMethodView): template_file = 'checkout/payment_method.html' def handle_GET(self): return render(self.request, self.template_file, self.context) def handle_POST(self):