我需要为 satchmo 中的加拿大邮政模块添加“如果购买超过 100 美元则免运费”功能。这可以开箱即用,还是我需要制作一个新的运输模块?
问问题
313 次
1 回答
0
好的,为此,我执行了以下操作:
from product.models import Discount
class AutoDiscount(Discount):
pass
这允许我在管理区域定义不同的折扣,然后执行以下操作:
def check_automatic_discounts(sender, form=None, **kwargs):
"""
"""
if sender in (CreditPayShipForm, SimplePayShipForm,
PaymentContactInfoForm):
# I probably need to sort these in some specific order
for discount in AutoDiscount.objects.all():
if discount.isValid(cart=form.cart,)[0]:
form.order.discount_code = discount.code
form.order.save()
return
signals.form_postsave.connect(check_automatic_discounts)
如果我需要更详细地控制应用哪些折扣,我可以将字段添加到AutoDiscount
模型并覆盖该isValid
方法
于 2011-10-06T21:59:34.690 回答