0

So I am using a gift certificate module with satchmo store and in order to send multiple gift certificate codes equal to the number of items purchased I need to add a loop doing

"while quantity is greater than zero loop"

Here is the code, the loop is being added to right before "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()
Wesley
  • 1
  • 1

1 Answers1

0

I am not sure I understand the question, but maybe something like

for ix in range(0, order_item.quantity):
  ... do stuff

might do the trick. You don't have to use the ix anywhere inside the loop, it is just (arguably) the standard way to do something n times in Python.