所以我正在使用带有 satchmo 商店的礼券模块,为了发送多个礼券代码等于购买的商品数量,我需要添加一个循环
“而数量大于零循环”
这是代码,循环被添加到“price=order_item.unit_price”之前
def order_success(self, order,
order_item):
log.debug("Order success called, creating gift certs on order:
%s", order)
message = ""
email = ""
for detl in order_item.orderitemdetail_set.all():
if detl.name == "email":
email = detl.value
elif detl.name == "message":
message = detl.value
price=order_item.unit_price
log.debug("Creating gc for %s", price)
gc = GiftCertificate(
order = order,
start_balance= price,
purchased_by = order.contact,
valid=True,
message=message,
recipient_email=email
)
gc.save()