We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46718
    • 39 Posts
    If anyone else is having trouble with this, I'll let you know I didn't find the answer for the plugins not firing. I did find a work-around for email notifications when the download button is clicked. So, you don't really know if they downloaded it, but it's better than nothing, especially if the emails are going to a sales person anyways smiley

    I went with an AJAX-y option derived from other posts.

    Note: I have different tiered access levels set with an "accessLevel" TV and we didn't want notifications for tier one downloads.

    My FileDownload Snippet call ended up like this:
    [[!FileDownload? 
          &getFile=`[[*resourceFile]]`   
          &tplFile=`@CODE <a id="downloadLink" class="[[*accessLevel:isnot=`1`:then=`notify`:else=``]] btn btn-primary" data-callid="[[*id]]" href="[[+fd.url]]">Download File</a>`
          &tplWrapper=`@CODE [[+fd.fileRows]]`
     ]]
    


    My JavaScript:
    $('#downloadLink.notify').click(function(){
      var callid = $(this).data('callid');
      $.ajax({
        url: "[[~2289]]",
        data: { callid: callid },
        type: 'post'
      });
    });
    


    Contents of Resource 2289:
    [[!fileDownloadNotifier]]
    


    Code in "fileDownloadNotifier" Snippet:
    <?php
    $date = new DateTime();
    $timestamp = $date->format('Y-m-d H:i:s');
    
    $callid = $_POST["callid"];
    
    $page = $modx->getObject('modResource', $callid);
    $downloadPage = $page->get('pagetitle');
    
    $user = $modx->getUser();
    $username = $user->get('username');
    
    $message = $modx->getChunk('tpl.mail.download.notifier', array(
      'downloadPage' => $downloadPage,
      'user' => $username,
      'timestamp' => $timestamp
    ));
    
    $modx->getService('mail', 'mail.modPHPMailer');
    $modx->mail->set(modMail::MAIL_BODY,$message);
    $modx->mail->set(modMail::MAIL_FROM,'[email protected]');
    $modx->mail->set(modMail::MAIL_FROM_NAME,'MODX File Download Notifier');
    $modx->mail->set(modMail::MAIL_SUBJECT,'New File Downloaded');
    $modx->mail->address('to','[email protected]');
    $modx->mail->address('reply-to','[email protected]');
    $modx->mail->setHTML(true);
    if (!$modx->mail->send()) {
        $modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
    }
    $modx->mail->reset();
    


    And finally, the "tpl.mail.download.notifier" chunk looks like this:
    (you can pretty much do whatever you want here, I kept it super simple knowing my usernames are email addresses anyways)
    <p><b>[[+user]]</b> downloaded <b>[[+downloadPage]]</b> on [[+timestamp]].</p>
    


    I know this is a combination of other things in other posts, but hopefully this helps someone eventually.