我创建了一个母产品泰姬陵茶,在其中创建了其子产品1公斤泰姬陵茶,并给出了价格(不含税)和零售价,您可以在此图像中看到。

python - 无法获得django oscar的零售价-LMLPHP

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

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')})


任何帮助都将得到极大的重视。

最佳答案

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

默认策略(我想这是您使用的策略)仅使用价格排除。税,这就是您所看到的。

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

另外,由于这一行,您发布的代码实际上应该失败并带有异常:

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


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

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

关于python - 无法获得django oscar的零售价,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56723930/

10-09 16:08