Skip to main content
 首页 » 编程设计

python之fork 运输应用程序在 Django oscar 中没有效果

2024年09月07日39TianFang

我已经使用 oscar_fork_app 命令将我的运输应用程序 fork 到一个名为 forked_apps 的文件夹中,并且还在 settings.py get_core_apps(['forked_apps.shipping']) 中添加,我只想创建提到的两种运输方式,标准和 express 此链接中的文档: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 运输方式。我不知道如何进行这项工作,即使打印语句也不起作用。 我还必须编写任何其他附加代码吗?

有人可以提供一些代码的解决方案吗?如果你已经实现了它?

请您参考如下方法:

从设置中删除 oscar 应用。

例如:

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

等等