Skip to content

[5.x]: Deleting a completed order with a custom line item throws InvalidConfigException #4371

Description

@denisyilmaz

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

  1. Complete an order that contains a custom line item.
  2. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions