While fixing a bug in uc_addresses, I ran into one in Ubercart. I disabled uc_addresses to make sure the bug could be replicated without it.

Create a product that requires no shipping. Add that product to your cart and place the order. Unless you've set uc_cart_delivery_not_shippable to FALSE, you should be asked only for the billing address. Fill out the billing address and place the order.

When I try this, I get a watchdog error of type 'ca': 'Attempt to e-mail invoice for order XX to failed.'. As best I can tell, the system tries to email to the shipping address, which has no recipient.

There is a test at line 840 in uc_order.ca.inc that is not working:

  if (empty($recipients)) {

I am guessing that the array $recipients is not empty, but it contains one element which is empty.

Also, when I view the order, the shipping address is listed but is mostly blank (says ", UNKNOWN").

I'm not sure what the right fix is. One possibility would be to mark whether an order contains a shipping address. The rule might be that if a shipping address was not displayed to the customer, then the order has none. Trying to scan the products on the order to see if they are shippable (the equivalent of uc_cart_is_shippable()) is probably not a good idea as the shipping status of a product might change. Also the display of the shipping address is influenced by uc_cart_delivery_not_shippable, which could also change.

The admin might need to add a shipping address, so maybe the flag that the order has no shipping address might be editable by the admin.

Comments

rszrama’s picture

Status: Active » Postponed (maintainer needs more info)

Hmm... I'm not entirely sure the shipping address is the issue. The e-mail action uses the e-mail address entered for the order, which is not tied to any particular address. If possible, it would be interesting to find out the actual PHP/Apache error that prevented the e-mail from being sent. Is it apparent from your error logs?

freixas’s picture

I'm sorry if I wasn't clear. The error is that you can't send email without a recipient. As I said, The $recipients array contains one item, a recipient with an empty name.

This is also reflected in the error message: "Attempt to e-mail invoice for order XX to failed.". There should be an email address between "to" and "failed".

I see your point about the e-mail address not being tied to the billing or delivery address. So I made the product shippable and tried it (without uc_addresses enabled). I got the same error so it's not tied to not having a shipping address.

I chased this down for a while and finally found the problem in admin/store/ca/uc_checkout_email_notification/edit/actions: I had no recipients for "Send an e-mail to the administrator(s)".

So I guess this all breaks down into a number of separate problems:

  1. The test at line 840 in uc_order.ca.inc is not sufficient to catch empty recipient lists. Of course, the system catches this problem later, but checking for it in the uc_order code could lead to a better error message.
  2. Either the action should fill in the administrator emails automatically or the admin/store page should warn that the admin recipient addresses are not filled in. Or is there some other mechanism that avoids this problem? It took me a while to track down where the missing address might be.
  3. Finally, while not critical, it still might be good to not display a shipping address as ", UNKNOWN" when one wasn't actually entered.

All of these seem less serious than the original problem I reported.

TR’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)

Even though this was the initial report, I'm going to mark it as "duplicate" of #455888: Unable to send e-mail. Please contact the site administrator if the problem persists. because that issue discusses your item 2) and proposes patches to avoid this problem altogether. I think your item 3) is a good point too.