【问题标题】:django-shop skipping shippingdjango-shop 跳过发货
【发布时间】:2023-04-08 17:57:01
【问题描述】:

我正在使用 django-shop,但我不知道如何跳过发货,因为我不需要它。 我尝试了几种方法,但没有发现问题。

有人有想法吗?

我试图复制 flate_rate 运费来自己做,但我遇到了没有反向匹配的问题。

这是我的文件:

# -*- coding: utf-8 -*-
from decimal import Decimal
from django.conf.urls import patterns, url
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.utils.translation import ugettext_lazy as _
from shop.util.decorators import on_method, shop_login_required, order_required


class PostShipping(object):
"""
This is just an example of a possible flat-rate shipping module, that
charges a flat rate defined in settings.SHOP_SHIPPING_FLAT_RATE
"""
    url_namespace = 'post'
    backend_name = 'La Poste'
    backend_verbose_name = _('La Poste')

    def __init__(self, shop):
        self.shop = shop  # This is the shop reference, it allows this backend
        # to interact with it in a tidy way (look ma', no imports!)
        self.rate = 0

@on_method(shop_login_required)
@on_method(order_required)
def view_process_order(self, request):
    """
    A simple (not class-based) view to process an order.

    This will be called by the selection view (from the template) to do the
    actual processing of the order (the previous view displayed a summary).

    It calls shop.finished() to go to the next step in the checkout
    process.
    """
    self.shop.add_shipping_costs(self.shop.get_order(request),
                                 'la poste',
                                 Decimal(self.rate))
    return self.shop.finished(self.shop.get_order(request))
    # That's an HttpResponseRedirect

@on_method(shop_login_required)
@on_method(order_required)
def view_display_fees(self, request):
    """
    A simple, normal view that displays a template showing how much the
    shipping will be (it's an example, alright)
    """
    ctx = {}
    ctx.update({'shipping_costs': Decimal(self.rate)})
    return render_to_response('shop/shipping/flat_rate/display_fees.html',
        ctx, context_instance=RequestContext(request))

def get_urls(self):
    urlpatterns = patterns('',
        url(r'^$', self.view_display_fees, name='flat'),
        url(r'^process/$', self.view_process_order, name='flat_process'),
    )
    return urlpatterns

【问题讨论】:

    标签: django python-2.7 django-shop


    【解决方案1】:

    看了一眼github repo,似乎没有禁用运输的设置。但是,您可以定义自己的运输后端来自定义事物(让运输静默通过)。

    如果您只是销售数字产品,我建议您编写自己的代码,it's not that hard.

    【讨论】:

    • 我做到了,但我遇到了一个错误。我以 flat_rate shipping 为例,但它会生成一个错误:NoReverseMatch at /shop/checkout/ship/ Reverse for 'post' with arguments '()' and keyword arguments '{}' not found。是因为self.shop的问题
    • 您缺少一个 urlpattern 'post'。请参阅 get_urls 函数如何设置。
    • 我修好了!十分感谢 !我只需要在 url_patterns 中添加帖子
    猜你喜欢
    • 2013-02-08
    • 1970-01-01
    • 1970-01-01
    • 2014-09-19
    • 2016-10-21
    • 1970-01-01
    • 1970-01-01
    • 2020-04-04
    • 1970-01-01
    相关资源
    最近更新 更多