diff --git a/make_post_sell/views/cart.py b/make_post_sell/views/cart.py index ae6b245..06ae3a9 100644 --- a/make_post_sell/views/cart.py +++ b/make_post_sell/views/cart.py @@ -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}"