Select Page

Configure asynchronous email notifications in Magento

I am working on a new Magento ecommerce site and wanted to find out more on the Asynchronous Sending of Sales Emails feature. While digging into Adobe’s documentation, their Configuration best practices page or the Sales Emails don’t really explain how this works. Still puzzled as to why this isn’t the default behaviour although recommended by Adobe themselves, I found the Proper way to configure asynchronous email sending in Magento article which I thought it is worthy of sharing and saving in my bookmark. This article explains how it works and how to do it on an existing website which comes with a caveat (see SQL statements).

Magento customers unable to place new orders

Multiple users have reported issues with Magento 2 (see GitHub magento2/issues/23618 or magento2/issues/23908) where customers are unable to proceed with their orders during checkout due to apparent problems with their shipping address.

In those cases, the customers will see a message stating Unable to save shipping information. Please check input data. OR The shipping information was unable to be saved. Verify the input data and try again.. E.g.:

Despite the screenshot above, the address might be correct and customer can’t do anything to unlock the situation hence leading to frustration.

Looking in the logs at var/log/exception.log, multiple related `Invalid customer address id` records can be noted. E.g.:

main.CRITICAL: Invalid customer address id 691 {"exception":"[object] (Magento\\Framework\\Exception\\NoSuchEntityException(code: 0): Invalid customer address id 691 at /vendor/magento/module-quote/Model/QuoteAddressValidator.php:77)"} []

Please note that the ID above is not che customer ID but the customer address ID that can be found in the `customer_address_entity` table. E.g.:

SELECT * FROM magentoDBname.customer_address_entity WHERE entity_id = 691;

This problem appears to be due to a bug occurring when particular conditions are met (see Stack Overflow). Sadly reading from those reports in GitHub and elsewhere, Adobe don’t appear to have figured out a resolution for this edge issue which seems to still affect the most recent versions.

Some code changes have been suggested by users to fix the problem while my preferred, albeit temporary, solution is that of updating the SQL code for those affected users (so we don’t change the Magento core code).

If curious, we can find the affected customers with:

SELECT entity_id, customer_id FROM quote WHERE customer_id != 0 AND customer_is_guest = 1;

We could instead find more details with:

SELECT a.entity_id, a.customer_id, b.firstname, b.lastname, FROM quote a, customer_entity b WHERE a.customer_id != 0 AND customer_is_guest = 1 AND a.customer_id = b.entity_id;

And fix them with:

UPDATE quote SET customer_is_guest = 0 WHERE customer_id != 0 AND customer_is_guest = 1;


Collect Magento logs with Papertrail

I’ve used Papertrail before its acquisition from SolarWinds and was impressed by its simple interface and the logs scrapping capabilities. At the time, I have set Papertrail to monitor a few auth logs and trigger Slack notifications whenever SSH access occurred from a different IP than those whitelisted.

Well, years have passed since I’ve last played with it and now I have a new use case to monitor Magento errors recorded in its var/log/system.log and var/log/exception.log files. As I’ve forgotten how I did this at the time I thought I’ll put down my steps which might help later on.

First thing I’ve gone straight into reading the docs. That brought me into the app log files aggregate page.

Papertrail Setup Logging

The first step is to download the latest remote_syslog2 script from their GitHub repository. The only problem I have with this method is that you will struggle to keep things up-to-date without manually checking the repo for a new version and update. Hopefully one day we would be able to install via an OS package.
Ok, let’s download the latest current version and install. As I’m using Ubuntu I’ve done this:
sudo dpkg -i remote-syslog2_0.20_amd64.deb

The second indicated step is that of configuring and starting remote-syslog. The example only shows you how to do it with a single log so without too much fuss I’ve instead downloaded the custom config file and replaced the content of /etc/log_files.yml with:

  - /home/user/
  - /home/user/
  port: 77777
  protocol: tls
  - main.INFO
pid_file: /var/run/

Figured out that we can add multiple files just under the first example line. Also, the original /etc/log_files.yml had an exclude_patterns example which I’ve used to prevent main.INFO records from filling Papertrail as these are outside the scope.

The remote-syslog GitHub page has obviously more examples and explanations if we want to dig further into how it works.

Finally, the sudo remote_syslog command should get us set.