Skip to content

Commit 539231e

Browse files
committed
fix php error
1 parent eda40e0 commit 539231e

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes for Digital Products
22

3+
## Unreleased
4+
5+
- Fixed a PHP error that could occur when paying for a completed order that contains deleted digital products.
6+
37
## 4.0.3 - 2025-02-03
48

59
- Fixed a bug where users with “Manage licenses” permission weren’t allowed to edit licenses. ([#105](https://github.com/craftcms/digital-products/issues/105))

src/services/Licenses.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,17 @@ public static function handleCompletedOrder(Event $event): void
4646
$lineItems = $order->getLineItems();
4747

4848
foreach ($lineItems as $lineItem) {
49-
$itemId = $lineItem->purchasableId;
50-
$element = Craft::$app->getElements()->getElementById($itemId);
51-
$quantity = $lineItem->qty;
49+
// Could be deleted line item
50+
if($itemId = $lineItem->purchasableId) {
5251

53-
if ($element instanceof Product) {
54-
/** @var Product $element */
55-
for ($i = 0; $i < $quantity; $i++) {
56-
DigitalProducts::getInstance()->getLicenses()->licenseProductByOrder($element, $order);
52+
$element = Craft::$app->getElements()->getElementById($itemId);
53+
$quantity = $lineItem->qty;
54+
55+
if ($element instanceof Product) {
56+
/** @var Product $element */
57+
for ($i = 0; $i < $quantity; $i++) {
58+
DigitalProducts::getInstance()->getLicenses()->licenseProductByOrder($element, $order);
59+
}
5760
}
5861
}
5962
}

0 commit comments

Comments
 (0)