2014-11-02 73 views
1

任何人都可以請解釋如何通過重寫django oscar的送貨應用程序的標準運費?我已經嘗試使用文檔中給出的配方來做它,但它沒有顯示任何可用的運輸方法。這是我做了什麼:Django oscar添加標準送貨方式

應用/運輸/ admin.py:

from oscar.apps.shipping.admin import * 

應用/運輸/ config.py:

from django.apps import AppConfig 


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

應用/運輸/ methods.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) 

應用/運輸/ models.py:

from oscar.apps.shipping.models import * 

應用/運輸/ 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()) 

回答

2

你有added your shipping app to your settings.py

應該看起來有點像這樣:

# settings.py 

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

希望這是蜱:)

相關問題