What happened?
This bug report was created with the help of AI, but I have encountered and had to fix it with a small module myself on one of the current commerce sites we have.
Pdfs::getPdfUrl() resolves the PDF against the current store instead of the order's store:
https://github.com/craftcms/commerce/blob/5.x/src/services/Pdfs.php#L472-L479
if ($pdfHandle) {
$pdf = $this->getPdfByHandle($pdfHandle); // no $storeId → current store
} else {
$pdf = $this->getDefaultPdf(); // no $storeId → current store
}
In the control panel the current store is the primary store. OrdersController::_registerJavascript() correctly lists getAllEnabledPdfs($order->storeId), but then calls $order->getPdfUrl(null, $pdf->handle) for each, so any PDF that only exists on a non-primary store is looked up in the wrong store and the order edit page throws:
InvalidArgumentException: Can not find a PDF to generate URL.
DownloadsController::actionPdf() already passes $order->storeId to both lookups, so the fix is to do the same in getPdfUrl():
$pdf = $pdfHandle
? $this->getPdfByHandle($pdfHandle, $order->storeId)
: $this->getDefaultPdf($order->storeId);
Steps to reproduce
- Multi-store install with a primary store and a second store.
- Create a PDF on the second store only (no PDFs on the primary store).
- Open any order belonging to the second store in the control panel.
- The page throws "Can not find a PDF to generate URL."
Also affects order.getPdfUrl() in front-end templates whenever the current site's store differs from the order's store.
Craft CMS version
5.11.x
Craft Commerce version
5.7.4
PHP version
8.4
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
What happened?
This bug report was created with the help of AI, but I have encountered and had to fix it with a small module myself on one of the current commerce sites we have.
Pdfs::getPdfUrl()resolves the PDF against the current store instead of the order's store:https://github.com/craftcms/commerce/blob/5.x/src/services/Pdfs.php#L472-L479
In the control panel the current store is the primary store. OrdersController::_registerJavascript() correctly lists getAllEnabledPdfs($order->storeId), but then calls $order->getPdfUrl(null, $pdf->handle) for each, so any PDF that only exists on a non-primary store is looked up in the wrong store and the order edit page throws:
InvalidArgumentException: Can not find a PDF to generate URL.
DownloadsController::actionPdf() already passes $order->storeId to both lookups, so the fix is to do the same in getPdfUrl():
Steps to reproduce
Also affects order.getPdfUrl() in front-end templates whenever the current site's store differs from the order's store.
Craft CMS version
5.11.x
Craft Commerce version
5.7.4
PHP version
8.4
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions