我已经使用oscar_fork_app命令将我的发货应用程序分叉到一个名为forked_apps的文件夹中,并且还添加了settings.py get_core_apps(['forked_apps.shipping']),我只想创建两个在本文档中提到的标准和快递方式链接:https://django-oscar.readthedocs.io/en/latest/howto/how_to_configure_shipping.html。
在init.py中我有这个代码预先存在:
default_app_config = 'forked_apps.shipping.config.ShippingConfig'
在repository.py中我写的是这样的:
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
在methods.py中我写过:
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')
应该发生的是,shipping_methods.html页面应该显示,而是在输入送货地址后直接进入付款详情页面;这通常只发生在没有定义运输方法的情况下,但我在上面的代码中实现了两种运输方法,标准和Express。我无法弄清楚如何使这项工作,即使print语句不起作用。还有其他必须编写的附加代码吗?
如果你实现了某些代码,有人可以提供解决方案吗?
从设置中删除oscar应用程序。
例如:
#oscar.apps.checkout
#oscar.apps.shipping
等等
这部分给了我错误。我无法解决这个问题。
get_available_shipping_methods(
self, basket, user=None, shipping_addr=None,
request=None, **kwargs):
...
Django ver。 > 2.1 |奥斯卡版>最新
我像这样使用它;
mkdir customapp
touch customapp/__init__.py
python manage.py oscar_fork_app shipping customapp/
编辑settings.py
from oscar import get_core_apps
INSTALLED_APPS = INSTALLED_APPS + get_core_apps(
['customapp.shipping'])
在我们的customapp / shipping目录中添加了一个名为(repository.py)的新文件
from oscar.apps.shipping import repository
from . import methods
class Repository(repository.Repository):
methods = (methods.Standard(),)
然后在同一目录中添加新文件,customapp / shipping,调用(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'))
您可以添加更多方法。
然后运行这些命令;
python manage.py makemigrations
python manage.py migrate
python manage.py runserver
希望这可以帮助。