I am currently adding a link to download the order PDF in the confirmation email with {{ order.getPdfUrl() }} but also want this to be an attachment.


Currently (Craft Commerce 1.1) there is no way to attach the PDF in an order status email, it can only be a link to download the PDF. For now, I suggest you make a feature request here: http://feedback.craftcms.com/forums/295386-commerce/filters/top


You can send an email via your plugin's init() function like so:

craft()->on( 'email.onBeforeSendEmail', function( Event $event ){
    $email = $event->params['emailModel'];
    $attachment = array(
        'path'     => '/var/www/public/assets/downloads/filename.pdf',
        'name'     => 'File Title',
        'encoding' => 'base64',
        'type'     => 'application/pdf'
    $email->addAttachment($attachment['path'], $attachment['name'], $attachment['encoding'], $attachment['type']);

Obviously, you'll want to do some checks on the Event and pass that off to a service to determine the logic for what should actually be attached.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.