Discussions

Can delete a Product because its referenced by a mystery line item

I've got a problem with Drupal commerce where I cant delete a product it says "This product is referenced by a line item and therefore cannot be deleted. Disable it instead."
I cant find any reference for a line item. How can I find out what is referencing the product

Posted: Apr 2, 2012

Comments

guaka on May 15, 2012

Same here. No orders, no line items. Still getting "This product is referenced by a line item and therefore cannot be deleted. Disable it instead."

yanniboi on October 1, 2012

I am working on the clone of a site and have deleted ALL orders/custommer profiles/baskets everything and am still getting that error on a few of my products...

yanniboi on October 1, 2012

After checking the commerce_line_item table it turns out that there are several line items that are referencing orders that no longer exist. (strange..)
Is there any way of getting these in the UI? (future development?)

Truncated the table and cleared cache.
(really weird now:) Problem still persists...

I repeat the line item table is empty and I'm still getting that error :S Is there any commerce cache that need clearing or is this unrelated?

yanniboi on October 1, 2012

I went into mysql and used:

USE 'database_name';
DELETE FROM commerce_product WHERE product_id=2;

for all the product ids that I wanted to delete.

Tim Jones on November 20, 2012

I had to find the Commerce_product table in the database and delete all items with the commerce_product_product_id that i didnt want anymore. To explain further i found the product id number by hovering over the product name and in the lower left corner of firefox a url will show up stating the product name/id number.

I also had some inefficiencies with other database stuff and drupal commerce that i think should get fixed in later releases. there were alot of left over info within the field_commerce_.... tables that were causing errors during checkout. I am not sure what the prblem was but i had to delete alot of info within those tables to get the confusion to stop.

It seems it would be a good idea to have the drupal admin UI delete the correct table information when changes are being made to the products (sku numbers, names etc...)

Norbert Arends on January 17, 2015

For what it's worth...
You may find some records in the table field_data_commerce_product containing references to the product you intend to delete. Remove those records manually and try again to delete the product from the UI.

Tamas Amon on March 12, 2015

I made a view with Commerce line item. After it I added a new field Commerce Line Item: Delete button (Delete button). I saved it but when I try to delete i get the following errors:

Notice: Undefined index: order in commerce_line_item_handler_field_edit_delete->views_form_submit() (line 56 of sites/all/modules/commerce/modules/line_item/includes/views/handlers/commerce_line_item_handler_field_edit_delete.inc).
Notice: Trying to get property of non-object in commerce_line_item_handler_field_edit_delete->views_form_submit() (line 56 of sites/all/modules/commerce/modules/line_item/includes/views/handlers/commerce_line_item_handler_field_edit_delete.inc).
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 173 of /includes/entity.inc).
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalCommerceEntityController->buildQuery() (line 44 of sites/all/modules/commerce/includes/commerce.controller.inc).
EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityDrupalWrapper->set() (line 737 of sites/all/modules/entity/includes/entity.wrapper.inc).

I like to change something in the price, but I can not...