We have a strange situation here where some Commerce Line Items exist in the database, referencing orders through their order_id property, but that aren't referenced by the order through it's field line_items (field_data_commerce_line_items table). Views listing line items show these although when looking at their respective orders they aren't appearing. It is causing wrong calculation of these view.
Is there any explanation as why these line items still exist and can they be deleted safely?
I can display these line using the following SQL request :
SELECT * FROM `commerce_line_item` cli
LEFT OUTER JOIN field_data_commerce_line_items fdcli on fdcli.entity_id = cli.order_id AND fdcli.`commerce_line_items_line_item_id` = cli.line_item_id
LEFT JOIN field_revision_commerce_line_items frcli ON frcli.`commerce_line_items_line_item_id` = cli.line_item_id
WHERE fdcli.entity_id IS NULL;
[EDIT] I changed the the request to reference to revision table. It does happens that some lines are referenced in a revision, but most are not.
field_revision_commerce_line_items
?