Magento: Fixing Bug in Freelunch Labs Mailgun Search

Published by John on December 17, 2018 Under Magento

Recently, I was contacted by someone to look at an issue that was breaking one of the pages in the admin section of their Magento website. They use Mailgun for sending transactional emails developed by FreelunchLabs and when they did a search in the backend under the Customers->Email Tracking page, it was generating an error report whenever they tried to search by ‘latest status’.

The error generated in the report was:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'current_status' in 'where clause', query was: SELECT COUNT(*) FROM `mailgun_email_tracking` AS `main_table`  LEFT JOIN `mailgun_email_tracking_event` AS `me1` ON main_table.id = me1.email_id LEFT JOIN `mailgun_email_tracking_event` AS `me2` ON (main_table.id = me2.email_id AND (me1.timestamp < me2.timestamp OR me1.timestamp = me2.timestamp AND me1.id < me2.id)) WHERE (me2.id IS NULL) AND (`current_status` LIKE '%clicked%')

I did a little digging and found that the current_status was actually the event_type column in the me1 table:

File: ~/public_html/app/code/community/FreeLunchLabs/MailGun/Model/Resource/Email/Collection.php

        $this->getSelect()->joinLeft(
            array('me1' => Mage::getResourceModel('freelunchlabs_mailgun/event')->getMainTable()),
            'main_table.id = me1.email_id',
            'event_type as current_status'
        );

The Fix

As a quick fix, I preformed the following steps:

  • Created a copy of the Grid.php folder in the local directory of Magento
  • Edited Grid.php to explicitly set the name/index of the column, rather than using current_status

This seems to have fixed it and since this edit is only in the adminhtml section, I do not believe it will have any impact on the front end or transactional email portion of the site, so should be fairly safe.

Steps to fix(you may need to change ‘~/public_html/’ to the directory of your webserver’s Magneto installation) :

//Create a folder in the /app/code/local/ directory, so we do not edit the main plugins files 
mkdir -p ~/public_html/app/code/local/FreeLunchLabs/MailGun/Block/Adminhtml/Global/

//copy the Grid.php file from the community directory to the newly created local directory, so we can safely override it
cp ~/public_html/app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Global/Grid.php ~/public_html/app/code/local/FreeLunchLabs/MailGun/Block/Adminhtml/Global/

//edit Grid.php as follows...the change is the 'filter_index' around line 41 in the file:

        $this->addColumn('current_status', array(
            'header' => 'Latest Status',
            'index' => 'current_status',
            'renderer'  => 'FreeLunchLabs_MailGun_Block_Adminhtml_Event_Renderer_Type',
            'filter_index' => 'me1.event_type'
        ));

Note in the above, that we change the column definition for ‘current_status’ to explicitly use the actual column name, with mysql table name: me1.event_type


No Comments |

Add a Comment