Overloading default Order Email Method

I’m currently having trouble getting my module to add (never changing) attachments to every oder email.

I am not really sure how this works in Oxid. My idea was to extend the default oxemail class, add my attachments and call parent::sendOrderEmailToUser() after that. But this doesn’t work. No attachments at all are added. The email just gets sent without them.

My guess is I have some fundamental misconception about how this works in Oxid, but I can’t figure out what it is.

Any help would be highly appreciated. I don’t know where to start, since there are no error messages or entries in the exception log.

Oxid version is 4.8.5


//FILE1 and FILE2 are defined here.
class vndr_email extends vndr_email_parent {

    public function sendOrderEmailToUser( $oOrder, $sSubject = null )
    {
		$attachment_path = __DIR__.'/';
		$this->addAttachment($attachment_path.FILE1);
		$this->addAttachment($attachment_path.FILE2);

        return parent::sendOrderEmailToUser($oOrder, $sSubject);
    }
}

Look in oxemail: parent::sendOrderEmailToUser calls _setMailParams which calls _clearMailer which calls clearAttachments, which discards your attachement.

Thanks for the information. Following that, I found a way to work around this:

//FILE1 and FILE2 are defined here.
class vndr_email extends vndr_email_parent {
    protected $aStaticAttachments = array();

    public function sendOrderEmailToUser( $oOrder, $sSubject = null )
    {
        //Only store attachments in the object, without actually using addAttachment().
        //After this call, the attachments will be cleared by core functions
		$attachment_path = __DIR__.'/';
		$this->aStaticAttachments[] = $attachment_path.FILE1;
		$this->aStaticAttachments[] = $attachment_path.FILE2;

        return parent::sendOrderEmailToUser($oOrder, $sSubject);
    }
    
    public function send() {
        
        //Add attachments before sending
        foreach ($this->aStaticAttachments as $sAttachment) {
            if ( file_exists($sAttachment) ) {
                $this->addAttachment($sAttachment);
            }
        }
        //Reset the attachment array to make sure they don't get sent again in another email by accident.
        $this->aStaticAttachments = array();
        return parent::send();
    }
}

I hope this helps someone else who runs into the same problem of having his attachments removed.

Thanks fo sharing, good way to insert attachements without duplicating the code in sendOrderEmailToUser.