-
Notifications
You must be signed in to change notification settings - Fork 174
Description
What happened?
Description
After updating to the latest version of Craft Commerce 4.x, we were getting an error on a client's site after the user had successfully completed an order.
We are pretty much using the default templates, so we were using the same conditional as you can see in /vendor/craftcms/commerce/example-templates/dist/shop/customer/order.twig template, at line 35:
| {% if order.pdfUrl and craft.commerce.pdfs.hasEnabledPdf %} |
We don't have a default PDF set up (or any PDFs) for this site, and so this exception was being triggered in src/services/Pdfs.php at line 450:
commerce/src/services/Pdfs.php
Lines 440 to 450 in 704df90
| public function getPdfUrl(Order $order, string $option = null, string $pdfHandle = null, bool $inline = false): string | |
| { | |
| // Load the PDF to get its link expiry setting | |
| if ($pdfHandle) { | |
| $pdf = $this->getPdfByHandle($pdfHandle); | |
| } else { | |
| $pdf = $this->getDefaultPdf(); | |
| } | |
| if (!$pdf) { | |
| throw new \InvalidArgumentException("Can not find a PDF to generate URL."); |
I guess it was silently passing over it before, but the updated code in services/Pdfs.php is now expecting/requiring a PDF?
To get around the issue I've simply commented out that code in the orders.twig template
Steps to reproduce
- Install Craft CMS v4 and Commerce v4.
- Use default templates
- Do not create a default PDF in Commerce's settings.
- Go through the order/checkout process.
- Exception mentioned above is thrown.
Expected behavior
Order page is shown, but without a 'Download PDF' link.
Actual behavior
Exception mentioned above is thrown.
Thanks. Please let me know if there's something I am missing, or if you require further information.
Craft CMS version
Craft Pro 4.16.17
Craft Commerce version
4.10.0
PHP version
8.2
Operating system and version
Linux 6.1.0-35-amd64
Database type and version
MySQL 28.1
Image driver and version
Imagick 3.7.0 (ImageMagick 7.1.1-41)
Installed plugins and versions
Relevant plugins:
Craft Commerce 4.10.0
PayPal Checkout for Craft Commerce 2.1.5
Stripe for Craft Commerce 4.1.8
Other plugins omitted.