【问题标题】:Access basket/shipping address in django oscar pricing strategy在 django oscar 定价策略中访问购物篮/送货地址
【发布时间】:2020-03-12 10:59:15
【问题描述】:

在定价策略中获取送货地址的最佳做法是什么?根据所选国家/地区,我是否要申请税费。

我的Selector 中有一个CheckoutSessionData 的实例,Selector 继承自CheckoutSessionMixin。但是,CheckoutSessionMixin 需要一个篮子来进行许多操作,尤其是获取送货地址。而且,BasketMiddleware 首先得到它的策略,然后才根据当前请求设置篮子。

那么,之前如何获取收货地址?有什么最佳做法吗?

奥斯卡版本是1.6.3

【问题讨论】:

    标签: django django-oscar


    【解决方案1】:

    我认为您的问题已在文档的这一部分 - how to address US taxes 中得到解决。你基本上需要:

    1. 使用DeferredTax 策略,返回不含税的价格。

    2. 覆盖并调整结帐视图以在已知税款后应用:

      def build_submission(self, **kwargs):
         submission = super().build_submission(**kwargs)
      
          if submission['shipping_address'] and submission['shipping_method']:
              tax.apply_to(submission)
      
              # Recalculate order total to ensure we have a tax-inclusive total
              submission['order_total'] = self.get_order_totals(
                  submission['basket'],
                  submission['shipping_charge'])
      
          return submission
      

    tax.apply_to 是您定义的函数,用于确定交货国家/地区的适当税费(文档中有一个示例)。

    【讨论】:

    • 这仅用于结帐,对吗?我想要一个整体解决方案,即使在产品详细信息页面上也是如此。我在另一个答案中添加了我当前的解决方案......不确定是否有任何缺点(例如离线处理,不提供请求......)
    • 我看不出你的方法有任何问题,除了用户必须已经开始结帐并提供他们的地址才能工作(即,离结帐不远了)只要)。我仍然会使用上面链接到的逻辑来确保在创建订单之前正确设置/重置策略。
    • 是的。对于当前的解决方案来说确实如此。 Planned 是一个进一步增强的版本,使用 maxminds geoip,在提供地址之前向用户显示它的“估计”价格和运输成本。感谢您的反馈!
    【解决方案2】:

    目前,我正在使用此解决方案,使我能够在整个网站中应用或不征税,其中SwissStrategy 包括税,InternationalStrategy 不包括税。很高兴收到任何反馈。

    class Selector(CheckoutSessionMixin):
        """
        Responsible for returning the appropriate strategy class for a given
        user/session.
    
        This can be called in three ways:
    
        #) Passing a request and user.  This is for determining
           prices/availability for a normal user browsing the site.
    
        #) Passing just the user.  This is for offline processes that don't
           have a request instance but do know which user to determine prices for.
    
        #) Passing nothing.  This is for offline processes that don't
           correspond to a specific user.  Eg, determining a price to store in
           a search index.
    
        """
    
        def strategy(self, request=None, user=None, **kwargs):
    
            # TODO: if request, decide based on location/geoip,
            # if to use swiss or international strategy
            country_id = request.session.get(
                'checkout_data', {}).get('shipping', {}).get('new_address_fields', {}).get('country_id', None)
            try:
                country = Country.objects.get(iso_3166_1_a2=country_id)
            except ObjectDoesNotExist:
                country = None
            if not country or country.iso_3166_1_a2 == 'CH':
                return SwissStrategy(request)
            else:
                return InternationalStrategy(request)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-24
      • 2015-03-24
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多