pizzapi icon indicating copy to clipboard operation
pizzapi copied to clipboard

How to add a coupon in my order?

Open zedin27 opened this issue 7 years ago • 5 comments

I tried to use one of the coupons from the list. In this case, I'm using the coupon number 9175 which is "Any Large Specialty Pizza". The number is supposed to retrieve the product code; but, in the function, add_coupon from the object class Order says missing 1 required positional argument: 'code'

What am I missing in here?

zedin27 avatar Nov 16 '18 02:11 zedin27

@zedin27 Could you share some code that would let me reproduce your issue? Everything you need to do from from pizzapi import * to Order.add_coupon() would be very helpful.

ggrammar avatar Dec 20 '18 03:12 ggrammar

@gamagori sure thing. I knew what was my mistake after realizing I missed one tiny line in the code. I forgot to have an order variable to store what I'm supposed to order before adding the coupon. However, I encountered another error after trying to add the coupon by doing order.add_coupon(9103), which display a KeyError: 9013. This is what I have in my python file (this is my first time playing with python lol):

from pizzapi import *

def ordertest():
	zeid = Customer('Zeid', 'Tisnes', '[email protected]', '5555555555')
	address = Address('ur address here', 'ur city', 'UR', '00000')
	local_dominos = address.closest_store(zeid)
	menu = local_dominos.get_menu()
	order = Order(local_dominos, zeid, address)

	order.add_coupon(9103) #1 Medium 3 Topping Pizza (here is where it complains)

Error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ztisnes/Desktop/pizzapi/pizzapi/order.py", line 52, in add_coupon
    item = self.menu.variants[code]
KeyError: 9103

You can remove ordertest and just write everything I have from that function in the interpreter.

zedin27 avatar Dec 22 '18 01:12 zedin27

@zedin27 I see what's going on - this is a code issue, not a usage issue.

In the add_coupon() function, the item = self.menu.variants[code] is looking for the coupon ID that you're passing it, but it's looking for it in the 'variants' part of the menu, rather than the 'coupons' part of the menu.

You should be able to fix this locally by changing that line to item = self.menu.coupons[code]. I need to get some other things in place before I can fix and test this properly, but I'll be sure to let you know once it's good to go.

ggrammar avatar Feb 27 '19 20:02 ggrammar

I made a PR for that specifically. Let me know when it is all good :). Thank you!

zedin27 avatar Feb 28 '19 01:02 zedin27

That still wont work as menu.coupons just returns a list of the coupon objects...

bryceswarm avatar Mar 01 '19 00:03 bryceswarm