Sammy J
Sammy J

Reputation: 1066

Forking shipping app has no effect in Django oscar

I had forked my shipping app into a folder called forked_apps using oscar_fork_app command and also added in settings.py get_core_apps(['forked_apps.shipping']), I just want to create two shipping methods mentioned, standard and express in the docs in this link:https://django-oscar.readthedocs.io/en/latest/howto/how_to_configure_shipping.html.

In the init.py I have this code pre-existing:

default_app_config = 'forked_apps.shipping.config.ShippingConfig'

In repository.py I have written like this:

from oscar.apps.shipping import repository
from .methods import *


class Repository(repository.Repository):

    def get_available_shipping_methods(
            self, basket, user=None, shipping_addr=None,
            request=None, **kwargs):
        methods = (Standard())
        print("\n\nFetch availble shipping methods")
        if shipping_addr:
            # Express is only available in the UK
            methods = (Standard(), Express())

        return methods

And in the methods.py I had written:

from decimal import Decimal as D
from oscar.apps.shipping import methods
from oscar.core import prices

class Standard(methods.FixedPrice):
    code = 'standard'
    name = 'Standard shipping'
    charge_excl_tax = D('5.00')

class Express(methods.FixedPrice):
    code = 'express'
    name = 'Express shipping'
    charge_excl_tax = D('10.00')

What should happen is, the shipping_methods.html page should show up, but instead, after entering the shipping address it goes to the payment details page directly; this would usually happen only if there are no shipping methods defined, but I have implemented two shipping methods, standard and Express in the above code.I can't figure out how to make this work, even the print statement isn't working. Is there any other additional code that I must write?

Can someone provide a solution with some code, if you have implemented it?

Upvotes: 2

Views: 522

Answers (2)

parodia
parodia

Reputation: 47

This section gives me error. I can't fix that.

get_available_shipping_methods(
    self, basket, user=None, shipping_addr=None,
    request=None, **kwargs):
...

Django ver. > 2.1 | Oscar ver. > Latest

I using it like this;

mkdir customapp
touch customapp/__init__.py

python manage.py oscar_fork_app shipping customapp/

Edit settings.py

from oscar import get_core_apps
INSTALLED_APPS = INSTALLED_APPS + get_core_apps(
      ['customapp.shipping'])

In our customapp/shipping directory added new file, called (repository.py)

from oscar.apps.shipping import repository
from . import methods

class Repository(repository.Repository):

    methods = (methods.Standard(),)

Then add new file in same directory, customapp/shipping, called (methods.py)

from oscar.apps.shipping import methods
from oscar.core import prices
from decimal import Decimal as D

class Standard(methods.Base):
    code = 'standard'
    name = 'Shipping (Standard)'

    def calculate(self, basket):
        return prices.Price(
            currency=basket.currency,
            excl_tax=D('5.00'), incl_tax=D('5.00'))

You can add more methods.

Then run these commands;

python manage.py makemigrations
python manage.py migrate
python manage.py runserver

Hope this helps.

Upvotes: 1

Raj Yadav
Raj Yadav

Reputation: 10788

Remove oscar apps from settings.

For example:

#oscar.apps.checkout
#oscar.apps.shipping

etc.

Upvotes: 1

Related Questions