What happened?
Description
Completed orders that contain a custom line item cannot be deleted, neither from the CP nor via Elements::deleteElement(). Order::afterDelete() loops over the line items captured in beforeDelete() and calls $lineItem->getPurchasable() on each to refresh the stock cache. getPurchasable() throws for LineItemType::Custom, so the delete transaction rolls back.
Steps to reproduce
- Complete an order that contains a custom line item.
- Delete the order from the Orders index.
Expected behavior
The order is deleted. Custom line items have no purchasable and no inventory, so they should be skipped.
Actual behavior
yii\base\InvalidConfigException: Cannot get a purchasable for a custom line item at src/models/LineItem.php:838, called from src/elements/Order.php:3816 (afterDelete).
Suggested fix:
skip custom line items in the loop, e.g. if ($lineItem->type === LineItemType::Custom) { continue; }. Same class of bug as #4337 and #3733.
Craft CMS version
5.11.1
Craft Commerce version
5.7.4
PHP version
No response
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
What happened?
Description
Completed orders that contain a custom line item cannot be deleted, neither from the CP nor via
Elements::deleteElement().Order::afterDelete()loops over the line items captured inbeforeDelete()and calls$lineItem->getPurchasable()on each to refresh the stock cache.getPurchasable()throws forLineItemType::Custom, so the delete transaction rolls back.Steps to reproduce
Expected behavior
The order is deleted. Custom line items have no purchasable and no inventory, so they should be skipped.
Actual behavior
yii\base\InvalidConfigException: Cannot get a purchasable for a custom line item at src/models/LineItem.php:838, called from src/elements/Order.php:3816 (afterDelete).
Suggested fix:
skip custom line items in the loop, e.g. if ($lineItem->type === LineItemType::Custom) { continue; }. Same class of bug as #4337 and #3733.
Craft CMS version
5.11.1
Craft Commerce version
5.7.4
PHP version
No response
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions