Fix redirect after purchase to check for digital products properly
- Add check for is_physical=False in addition to has_product_file - Add detailed logging to diagnose redirect issues - Physical products should always redirect to invoice - Digital products without files should redirect to invoice - Only digital products with files should redirect to product page
This commit is contained in:
parent
3289702d50
commit
dc092d920d
1 changed files with 21 additions and 2 deletions
|
|
@ -48,15 +48,34 @@ def get_smart_purchase_redirect_url(invoices):
|
|||
- Invoice URL if multiple products or physical products
|
||||
- General purchases page as fallback
|
||||
"""
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Handle single invoice with single digital product
|
||||
if len(invoices) == 1:
|
||||
invoice = invoices[0]
|
||||
line_items = list(invoice.line_items)
|
||||
|
||||
logger.info(f"Smart redirect check - Invoice {invoice.id} has {len(line_items)} line items")
|
||||
|
||||
# Single digital product - redirect to download page
|
||||
if len(line_items) == 1 and line_items[0].product.has_product_file:
|
||||
if len(line_items) == 1:
|
||||
product = line_items[0].product
|
||||
return f"/p/{product.id}/{product.slug}"
|
||||
logger.info(f"Single product: {product.title} (ID: {product.id})")
|
||||
logger.info(f"Is physical: {product.is_physical}")
|
||||
logger.info(f"Has product file: {product.has_product_file}")
|
||||
logger.info(f"Product extensions: {product.extensions}")
|
||||
|
||||
# Check if it's a digital product with a file
|
||||
if not product.is_physical and product.has_product_file:
|
||||
redirect_url = f"/p/{product.id}/{product.slug}"
|
||||
logger.info(f"Redirecting to product page: {redirect_url}")
|
||||
return redirect_url
|
||||
else:
|
||||
if product.is_physical:
|
||||
logger.info(f"Product is physical, redirecting to invoice")
|
||||
else:
|
||||
logger.info(f"Digital product has no file, redirecting to invoice")
|
||||
|
||||
# Multiple products or physical products - redirect to invoice
|
||||
return f"/invoice/{invoice.id}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue