The hook_commerce_product_can_delete() is called to block any products from being deleted, ie if they are referenced in line items. However, the product_ids array is never updated, so the controller still deletes all of them.

CommentFileSizeAuthor
#1 fix-product-can-delete-1293754-1.patch568 bytesrecrit

Comments

recrit’s picture

Status: Active » Needs review
StatusFileSize
new568 bytes

patch to address this issue

rszrama’s picture

Status: Needs review » Fixed

You da man. Nice catch and sweet patch.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jbeall1369’s picture

I'm new, and I cannot delete products. I get this error: "This product is referenced by a line item and therefore cannot be deleted. Disable it instead." How do I use a patch?

rszrama’s picture

You don't need a patch - that's the intended behavior of Drupal Commerce. What you need instead is to just delete the order that contains the line item. Look under your Shopping Carts tab, as it might be on an uncompleted order.

jbeall1369’s picture

There are no orders or shopping carts...

rszrama’s picture

Then you must have an orphaned line item somewhere, one that was created manually on an order add form but the order itself was never saved. It's unfortunate, but there is no way to delete these directly through the default UI. One thing you can do is simply create a View of line items and list them all out as an admin to see and possibly delete; I'm not sure how deletion would work through there without Rules + VBO... and that's getting overly complicated. Many people have just deleted the line items from the commerce_line_item table and product references from the field_commerce_product_data table (or whatever the name of it is). Make sure you clear the cache after doing that, too, and don't forget the related revision table for the field data.