2

I am trying to write a shipping method base on both by country and also weight-base in Django-oscar. It seems the default shipping methods must also have these

     from oscar.apps.shipping.methods import Free, FixedPrice, NoShippingRequired

I do not required any of the above and would only provide discount for shipping through discounts.

How do I write by repository.py so I do not apply any of these oscar.apps.shipping.methods import Free, FixedPrice, NoShippingRequired

So I can just write my class Repository (CoreRepository):

Without writing

   methods += [NoShippingRequired()]

   methods += [FixedPrice()]

   methods += [Free()]

The method I have written is not code based but implemented through the shipping menu in the dashboard. I followed the following to set my shipping.

https://groups.google.com/forum/#!topic/django-oscar/H4tf20ujm8k

When testing, on the page 'Shipping Menu', both the 'HandDelivery', and my weight-based by country shipping method button is displayed to customer. Which means customer can click the HandDelivery button too even when customer is based internationally. I wished to disable that 'HandDelivery' button at the Shipping method page, so it is not an option for customers to select at all.

Another option is to attached a message to this button to make it clear to customers that clicking that button means arranging to collect item from warehouse within 1 week of reservation.

How do I display that the message to the customer? Customer is not taking onto the payment page. And an email is sent so items can be collected within 7 days? Like similar to argos, reserve, item, go to shop, pay, and collect. So I could change the discription of 'HandDelivery' to reserve. Then customer does not pay but pay upon collection. But how?

Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
evepokua
  • 51
  • 1
  • 7

1 Answers1

5

EDIT: Apparently Oscar has several ways to define shipping; updating answer to cover methods defined in the dashboard!


Once you have forked Oscar's shipping app, you can override the repository class and only return the shipping you want.

If you've defined your weight-based shipping through the dashboard, you can get it with the WeightBased model, and only return that:

forked_apps/shipping/repository.py:

from oscar.apps.shipping import repository
from oscar.core.loading import get_model
from . import methods

WeightBased = get_model('shipping', 'WeightBased')

class Repository(repository.Repository):
    def get_available_shipping_methods(self, basket, user=None,
            shipping_addr=None, request=None, **kwargs):

        if shipping_addr:
            weightbased_set =  WeightBased.objects.all()

            if weightbased_set:
                return ( list(weightbased_set), )

        # If no address was specified, or weight-based options are
        # not available, return the "Reserve" shipping option
        return ( methods.Reserve(), )

forked_apps/shipping/methods.py:

from oscar.apps.shipping import methods

class Reserve(methods.NoShippingRequired):
    code = 'RESERVE'
    name = 'Reserve'
    description = 'Items will be reserved at the warehouse for 7 days'

Delaying payment would involve forking the payment app, and would be worth its own question.

The Oscar documentation also has some good information on further customization of shipping options in the "How to configure shipping" section.

Jacob Hume
  • 1,953
  • 2
  • 13
  • 14
  • @JacobHumes I understand you explanations. I have an error. And will add more to my request so you can understand where I am. Thank you – evepokua May 08 '17 at 14:11
  • I have added more details above, could you take a look and advice? Thank you. @Jacob Hume – evepokua May 08 '17 at 20:31