Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add a coupon in my order? #38

Open
zedin27 opened this issue Nov 16, 2018 · 5 comments
Open

How to add a coupon in my order? #38

zedin27 opened this issue Nov 16, 2018 · 5 comments

Comments

@zedin27
Copy link
Contributor

zedin27 commented Nov 16, 2018

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?

@ggrammar
Copy link
Owner

@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.

@zedin27
Copy link
Contributor Author

zedin27 commented Dec 22, 2018

@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.

@ggrammar
Copy link
Owner

@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.

zedin27 added a commit to zedin27/pizzapi that referenced this issue Feb 28, 2019
@zedin27
Copy link
Contributor Author

zedin27 commented Feb 28, 2019

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

@bryceswarm
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants