Django oscar添加了一种标准的运输方式



有人能解释一下如何通过覆盖django-oscar的运费应用程序来收取标准运费吗?我试过用文档中给出的配方来做,但没有显示任何可用的运输方法。这就是我所做的:

apps/shipping/admin.py:

from oscar.apps.shipping.admin import *

apps/shipping/config.py:

from django.apps import AppConfig

class ShippingConfig(AppConfig):
    name = 'apps.shipping'

应用程序/运输/方法.py:

from decimal import Decimal as D
from django.template.loader import render_to_string
from oscar.apps.shipping import methods
from oscar.core import prices

class Standard(methods.Base):
    code = 'standard'
    name = 'Standard shipping'
    charge_per_item = D('0.99')
    threshold = D('12.00')
    description = render_to_string(
        'shipping/standard.html', {
            'charge_per_item': charge_per_item,
            'threshold': threshold})
    def calculate(self, basket):
        # Free for orders over some threshold
        if basket.total_incl_tax > self.threshold:
            return prices.Price(
                currency=basket.currency,
                excl_tax=D('0.00'),
                incl_tax=D('0.00'))
        # Simple method - charge 0.99 per item
        total = basket.num_items * self.charge_per_item
        return prices.Price(
            currency=basket.currency,
            excl_tax=total,
            incl_tax=total)

class Express(methods.Base):
    code = 'express'
    name = 'Express shipping'
    charge_per_item = D('1.50')
    description = render_to_string(
        'shipping/express.html', {'charge_per_item': charge_per_item})
    def calculate(self, basket):
        total = basket.num_items * self.charge_per_item
        return prices.Price(
            currency=basket.currency,
            excl_tax=total,
            incl_tax=total)

应用程序/运输/模型.py:

from oscar.apps.shipping.models import *

apps/shipping/repository.py:

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

# Override shipping repository in order to provide our own two
# custom methods
class Repository(repository.Repository):
    methods = (methods.Standard(), methods.Express())

您是否已将发货应用程序添加到您的设置.py中?

应该看起来有点像这样:

# settings.py
from oscar import get_core_apps
# ...
INSTALLED_APPS = [
    # all your non-Oscar apps
] + get_core_apps(['yourproject.shipping'])

希望是这样:)

相关内容

最新更新