question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to find/delete/invalidate DiscountCode by code?

See original GitHub issue

I want to delete one DiscountCode from the list of assigned to some PriceRule. How should I do that having only DiscountCode without ID? I don’t want to retrieve a list of all discounts (I have thousands of them), just delete or invalidate one.

Currently, the only option I see - is to find somehow ID of required DiscountCode and destroy() it.

But the question is still how to find it? In tests, I see only hardcoded ID.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
jamiemtdwyercommented, Oct 4, 2018

I actually don’t think this is going to work without patching urllib, which should probably be done in pyactiveresource.

urllib will follow 303 redirects without using a custom handler, which is not the ideal behaviour here.

In the meantime, you can use the requests library to do something like this:

import requests
import re

lookup_code = 'SUMMER1'
lookup_url = "%s/discount_codes/lookup.json?code=%s" % (shopify.ShopifyResource.site, lookup_code)

r = requests.get(lookup_url, headers=shopify.ShopifyResource.headers, allow_redirects=False)

path = re.sub(r'https://([a-zA-Z]+?-?)*.myshopify.com', '', r.headers['Location']) + '.' + shopify.ShopifyResource.format.extension
code = shopify.DiscountCode.find(from_=path)
1reaction
sameerkumar18commented, Feb 12, 2020

Thanks @jamiemtdwyer I just added shopify.DiscountCode._build_collection(code, prefix_options='') to build the respone dictionary back into the library object. Also, this issue is quite old now. Is there any better approach to achieve this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

This Website Accidentally Left Promo Codes in Their Source ...
Right-click just about anywhere on the website and select “View source.” Hit CTRL+F (or CMD+F) to search the code and type “promocode.” We...
Read more >
Discount codes FAQ - Shopify Help Center
Find answers to common questions about discount codes. ... What happens if a customer enters an invalid discount code or combination? How do...
Read more >
Delete a coupon – curl - Stripe API reference
You can delete coupons via the coupon management page of the Stripe dashboard. ... An object with the deleted coupon's ID and a...
Read more >
Fix issues with promotions - Google Store Help
Fix issues with promo codes · At the bottom of the checkout screen, find "Add a promo code." · Enter your code. ·...
Read more >
Managing discounts - Squarespace Help Center
Confirm that the discount has a unique code. Review active, scheduled, and expired discounts and change any duplicate codes. If the discount is ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found