【问题标题】:Could not get Retail Price in django oscar无法在 django oscar 中获得零售价
【发布时间】:2019-06-23 12:34:43
【问题描述】:

我创建了一个父产品 taj mahal tea,我在其中创建了它的子产品 taj mahal tea 1 kg 变体,并给出了价格(不含税)和零售价,您可以在这张图片中看到。

但是当我尝试访问价格对象时,我无法在其中获得零售价格属性。 这是我的示例代码:

from oscar.core.loading import get_class, get_model
from oscar.apps.partner.strategy import Selector

Product = get_model('catalogue', 'Product')
product = Product.objects.filter(id=11).first()
strategy = Selector().strategy()

info = strategy.fetch_for_product(product)
print(info.price)

输出:

FixedPrice({'currency': 'INR', 'excl_tax': Decimal('400.00'), 'tax': Decimal('0.00')})

这是我的测试代码及其输出:

>>> strategy = Selector().strategy()
>>> info = strategy.fetch_for_product(product)
>>> info
PurchaseInfo(price=FixedPrice({'currency': 'INR', 'excl_tax': Decimal('400.00'), 'tax': Decimal('0.00')}), availability=<oscar.apps.partner.availability.StockRequired object at 0x7f2db2324e80>, stockrecord=<StockRecord: Partner: Aapnik, product: Taj mahal 1 kg (xyz)>)
>>> info.price
FixedPrice({'currency': 'INR', 'excl_tax': Decimal('400.00'), 'tax': Decimal('0.00')})

任何帮助将不胜感激。

【问题讨论】:

    标签: python django django-oscar


    【解决方案1】:

    这是意料之中的,如果有些令人困惑的行为。股票记录上的零售价字段在 Oscar 核心中的任何地方都没有使用 - 它只是作为数据字段存在,实际上在 Oscar 1.6 中已弃用。

    默认策略(我猜是您正在使用的)仅使用不包括价格。税,这就是你所看到的。

    如果您想使用零售价,您需要提供自己的策略类来执行此操作。请记住,该字段已被弃用,并且将来会从 Oscar 核心中移除。

    另外说明,您发布的代码实际上应该因异常而失败,因为这行:

    product = Product.objects.filter(id=11)
    

    product 在这种情况下不是Product 对象,而是一个queryset,它不是Strategy.fetch_for_product() 的有效参数。

    你可能想改用Product.objects.get(id=11)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-03
      • 2018-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-21
      • 1970-01-01
      相关资源
      最近更新 更多