I see line items when viewing the order view online, but I get "No line items found." in the email receipt. Any idea why? Thanks.

Comments

eeyorr’s picture

Actually, when I email the invoice by clicking the "email" button in the order view, the line items appear, but the email triggered by the rule gives me the "No line items..." message.

najtsirk’s picture

I get the same missing line items for anonymous users. What is the problem?

scottrouse’s picture

Title: Line items missing from email » Line Items not included in emailed receipt for Anonymous users
Category: support » bug
Priority: Normal » Major

This is happening for me, too. It does appear to be tied to anonymous users. Initially, the UID in the email was showing up as 0 (anonymous user). I changed the weight of the rule to 10 so that it would be evaluated after the "Create a new account for an anonymous order" rule. The new UID now shows up in the email, but the line items show up as "No line items found."

BenStallings’s picture

Title: Line Items not included in emailed receipt for Anonymous users » Line Items missing from email

I'm changing the title back because I'm not convinced the problem is limited to anonymous users. I set the weight of the rule to 10, and the orders are getting assigned to the proper user, but regardless of whether the user is new or existing -- and regardless of whether they were logged in at time of checkout -- the emailed receipt does not show line items. The receipt I can pull up through the admin interface does show line items, and I can email that manually, but I don't want to have to do that for each and every order!

Just to try to think this through... the line items are displayed as $info['line_items'] in the template. This value is set by _commerce_invoice_receipt_get_invoice_info(), which is called by commerce_invoice_receipt_mail() using an order object it was passed, in turn, by the rule. Unless I'm missing a step.

The "No line items found." message is the No Results Behavior of the commerce_line_item_table view. So at the time the $info variable is populated, that view is returning no results. The view has no access restrictions and requires only the order number to be passed in as a parameter -- not the user ID.

So it seems to me that the weak link here is the way the rule retrieves the order (the commerce-order token) -- it may not be a problem in this module at all. But to test that theory I'm going to have to do some experimentation.

BenStallings’s picture

In order to test the hypothesis that the problem was with my Rule configuration, I added a condition to the rule to test whether the commerce-order entity has a commerce-line-item field, in order to make sure the field is available for use (since that is a common problem with Rules). That did not help -- the email still says "No line items found."

no2e’s picture

I don't know if this might help here, but I had the same problem without using 'Commerce Invoice Receipt':

I use Commerce Email (7.x-1.x-dev) with the token [commerce-order:commerce_line_items].

If anonymous orders something, the mail contains "No line items found.".
If a registered user orders something, it contains the line items table.

After giving anonymous the permission "View own orders of any type", it works for them, too.


Ah, and here is a related thread:
"No line items found." in email receipt if user is not authenticated during checkout

nasheet’s picture

Hello,
I am also having this problem. For me it does not matter if the user is anonymous or authenticated. The difference is when I enable the Payment part of the checkout. If I disable the payment part, and a user places an "order" without paying (in my case transferred to PayPal using WPS) then the email works and the line items are all displayed. If I enable the Payment pane in checkout, the user is transferred to PayPal, then the email is sent with "No line items found" instead of the order.

I don't know how this can be fixed, but thought I would add my experience to the investigation.

agoradesign’s picture

Hello,
I've the same problem, very similar to nasheet's description: user is authenticated, permission "view own orders of any type" is on. Instead of PayPal I'm using Ogone.

geodaniel’s picture

I also see this issue with just Commerce Email module (1.x-dev), and don't have Commerce Invoice Receipt module installed. I'm using the [commerce-order:commerce_line_items] token.

When you use a payment service which is externally hosted (PayPal, Ogone, etc.), it isn't the user coming back to the site which triggers the email, it's the payment provider requesting a URL in the background. As such, the request is coming from a completely different anonymous user, which won't have permissions to see the line items.

For me, giving the anonymous user 'View own orders of any type' permission didn't work, but by editing the commerce_line_item_table view and disabling SQL Query Rewriting under Advanced -> Settings I got it to work... for a while. Then it stopped working, and I haven't yet pinned down what changed in the meantime to make it stop.

nasheet’s picture

Oh thank you geodaniel, this worked for me. Seems like the invoice is working now, I haven't tested it thoroughly yet, but your explanation makes sense and modifying the view works for now!

bradhawkins’s picture

This could also be a result of the "line items" field being set to "hidden" in the display settings.

Go to:
Administration » Store » Configuration » Order settings » Manage display

...and make sure that "line items" is not hidden for the "Invoice/Receipt" display type. For me all fields were hidden by default.

stevieb’s picture

#11 was the same for me and cleared the issue

micnap’s picture

#9 fixed the issue for me.

Daglees’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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

kingandy’s picture

Re #9, "giving the anonymous user 'View own orders of any type' permission" naturally wouldn't work as the orders in question don't belong to the anonymous user :D You'd need to give them 'View any order of any type'. However this would give anonymous users permission to view any order, which is not particularly great for security, so the latter option (disabling SQL rewriting on the cart summary views) is thoroughly preferable.

francort’s picture

I've found that commerce_entity_access_query_access() is the function to be blamed on this issue.

martin74’s picture

Same issue here. ( it worked few weeks ago..) now it doesnt ?

my order emails dont hold line items

can someone help me out ?

geraldito’s picture

#9 fixed the issue for me.

ishworthapaliya’s picture

#9 worked for me also. Thanks!

Anybody’s picture

Issue summary: View changes

#9 worked and still works for me ;) But I'm still frightened, if this opens up security holes.

hockey2112’s picture

#11 fixed it for me. Thanks!

hectorelgomez’s picture

I had the same problem. For me this response solve the issue. Thanks a lot.

victor.bexelius’s picture

Hello, I would like to post the fix on this issue to whomever have problems.

1. I am using a paymentprovider which takes the user to an off-site for payment, then returns the user to the page - thus triggering the complete checkout rules

Problem: The receipt to customer did not contain the line-items.

Solution:
1. #11: geodaniel -> commerce_line_item_table -> Disable SQL rewriting

Notes: Thanks to this you may send admin order email (example a custom email that goes to admin whenever an order is complete by a customer).

AND

2. commerce_cart_summary -> Disable SQL rewriting

Notes: Thanks to this - the customer email will contain the line items.

Best regards

Victor Bexelius

RAWDESK’s picture

Hi,
Neither #9, #11 or commerce_cart_summary SQL rewriting disabling helped me solving my custom mandrill email confirmation implementation.

After some research, i finally found a solution thanks to this thread comment :
https://www.drupal.org/node/1895418#comment-9276425

Had to perform some additional tweaking since the last two instructions :

$user = $original_user;
drupal_save_session($old_state);

prevented me from successfully sending my mail to mandrill.

So here's my rather simple implementation for those who might be looking for a similar solution :

global $user;
$user = user_load($order->uid);
$html = order_confirmation_html($order); // this function is using the commerce_line_item_table view to render line_items in html format
$uri = 'https://mandrillapp.com/api/1.0/messages/send-template.json';
... and all the rest needed to post to mandrill.
GiorgosK’s picture

#9 @geodaniel's explanation and solution works for external payments (paypal)
otherwise for internal payments (Bank transfer, COD etc)
the "view own orders of any type" anonymous permission worked

localnetwork’s picture

#11 is mandatory as the product line_items needs to be displayed in Invoice Receipt while #9 is a bug in sending "Invoice Receipt" on email for anonymous order.

nattyweb’s picture

#11 wasn't an issue for me - already set that way. But #9 did the job. Thank you. Shame this is still an issue, 5 years on.
Using recommended Stable release 7.x-1.1 released 7 January 2014 and Drupal 7.56.

Dubs’s picture

The issue is around order ownership and permissions. Even though the order has a user, and the patch allows the user to switch temporarily, access checks still fail.

The workaround is #24 is good as long as that view is not accessible outside of this module's use (security).