Discount code field missing on invoice

I frequently offer free digital downloads to friends and charitable organizations. Prior to BL5 I was able to offer a free digital download with a price set to $0. A couple of updates ago, I started receiving the following error message –

As a result, I revised the price to $1 and then created a discount code called “free” – discounting the order at 100%. This worked until the latest update. Now, the discount field no longer appears on the invoice during check-out. It would be great to have this functionality back as it was in BL4 (i.e. price of $0 and/or discount code field)? In the meantime, is there any known workaround?

Hi @ServiceDude, thanks for the access. I’ll have a look in the next day or so and let you know what I find.
FYI, we haven’t actively removed any functionality from the Cart. If anything isn’t working as it did previously then it may be an unintended regression. I’ll see what I can find.

Hi @ServiceDude, I’ve found the issue with the Discount Code. This was caused by some of the many changes needed for PHP 8.2 compatibility.
I’ve made a silent update to the cart. Can you visit the Backlight Modules page and click Reinstall for module-cart? If you then try the cart in a new browser window, then you should be able to see the Discount Code field again.

Hi Ben, I reinstalled the Cart Module, cleared the browser cache, and created a new discount code. I’m now seeing the discount code at checkout! When I applied the code, I’m now seeing the following error message –

Too few arguments to function DiscountManager::setDiscountCode(), 1 passed in /home/kg2vzzg43i3o/public_html/josephzphotography.com/backlight/modules/module-cart/application/models/ShoppingCart.php on line 143 and exactly 2 expected|#0 /home/kg2vzzg43i3o/public_html/josephzphotography.com/backlight/modules/module-cart/application/models/ShoppingCart.php(143): DiscountManager->setDiscountCode() #1 /home/kg2vzzg43i3o/public_html/josephzphotography.com/backlight/modules/module-cart/application/controllers/CartController.php(264): ShoppingCart->setDiscountCode() #2 /home/kg2vzzg43i3o/public_html/josephzphotography.com/backlight/modules/module-cart/application/controllers/CartController.php(151): CartController->applyDiscountCode() #3 /home/kg2vzzg43i3o/public_html/josephzphotography.com/backlight/modules/module-framework/controllers/Controller.php(58): CartController->updateCart() #4 /home/kg2vzzg43i3o/public_html/josephzphotography.com/backlight/modules/module-framework/models/Dispatchable.php(136): Controller->dispatch() #5 /home/kg2vzzg43i3o/public_html/josephzphotography.com/backlight/modules/module-framework/Framework.php(78): Dispatchable->dispatch() #6 /home/kg2vzzg43i3o/public_html/josephzphotography.com/backlight/index.php(32): Framework->route() #7 {main}|URL: /backlight/index.php

Hi @ServiceDude, can you try to reinstall the module again and try it again?

Hi Ben, Great news! The discount code is back and working. Thank-you!

With the changes needed for PHP 8.2 compatibility, is possible that the ability to offer a free digital download ($0 base price) inadvertently disappeared along with the discount field? In the past, I was able to set the price at $0 and then my customer didn’t need a discount code.

$0 pricing is working for me with the latest Backlight (I’m still on php 8.1 though)

The error message in your first post implies an error in the “base price”. Digital Downloads don’t use a base price.
Could it be that in your Digital Download product, you’ve chosen Physical Product rather than Digital Download?

Strange. I’m also on PHP 8.1 but am still getting the error. I verified that the product was setup as a digital download. To test, I deleted the products and pricing schemes and recreated a product called Free Digital Download with a single base pricing. I then created a pricing scheme called Free Digital Download and set the minimum order amount and the price to $0. I then updated the album and index files, cleared the template cache, reset the customer’s cart in the browser and finally, cleared the browser cache. Unfortunately, I’m still getting the following error message –

Have you tried looking in a different browser? When I was testing, my test album wasn’t reflecting the changes I made to the product/pricing. I tried clearing browser and template cache and resetting the cart, but that wasn’t working. So I tried in a different browser and the changes were there.

It was working correctly in the first browser a couple hours later

Interesting. I just gave it a try in four different browsers (Chrome, Brave, Safari, & Edge). Unfortunately, I had no luck. So on a whim, I set the price to a negative value ($-1.00) and the error message didn’t appear. The invoice detail line for each item shows $-1.00 and the calculated total shows $0.00 USD. As a result, the photo download link became available for the user to download photos free-of-charge.

Hi Joe, I’ve looked further into this. It’s a bit complicated. Your cart is working as it’s been coded to - it’s designed to reject a $0 price. The quirk is that on my test server and presumably @rod_barbee’s, 0 is being seen as “0.0” and PHP has decided that isn’t the same thing as 0 and allowing it to go through.

Quirk aside, it looks like I need to change that check to allow zero prices regardless of whether PHP thinks it’s 0 or “0.0”. An easy fix but I need to see if there are any repercussions for other scenarios that we really shouldn’t be allowing.