0

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.

  • What about field_revision_commerce_line_items? – Clive Nov 19 '14 at 16:54
  • Changed the request, but not much enlightment comes from it :( – werfu Nov 19 '14 at 17:01
1

This typically happens when an administrator adds a line item to an existing order via the order edit form and doesn't submit the form. The line item has already been created, but the order hasn't been updated to reference it. We refer to these as orphaned line items, and they're safe to delete as needed.

I implemented a much better approach with Inline Entity Form, which defers any write action for referenced entities until the form is submitted, but last I tried its line item support wasn't fully functional for the site I was working on. May be better now.

| improve this answer | |
  • Thanks for the answer, I'll try to validate if the site administrators did add such line. – werfu Nov 20 '14 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.