Giter Club home page Giter Club logo

Comments (5)

leonhelmus avatar leonhelmus commented on July 30, 2024

This is how the file should look like to me.

<?php
/**
 * Ebizmarts_Mandrill Magento JS component
 *
 * @category    Ebizmarts
 * @package     Ebizmarts_Mandrill
 * @author      Ebizmarts Team <[email protected]>
 * @copyright   Ebizmarts (http://ebizmarts.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

namespace Ebizmarts\Mandrill\Model;

class Transport implements \Magento\Framework\Mail\TransportInterface
{
    /**
     * @var \Ebizmarts\Mandrill\Model\Message
     */
    private $message;

    /**
     * @var Api\Mandrill
     */
    private $api;

    /**
     * @param \Magento\Framework\Mail\MessageInterface $message
     * @param \Psr\Log\LoggerInterface $logger
     * @param \Ebizmarts\Mandrill\Helper\Data $helper
     */
    public function __construct(
        \Ebizmarts\Mandrill\Model\Message $message,
        \Ebizmarts\Mandrill\Model\Api\Mandrill $api
    ) {
    
        $this->message = $message;
        $this->api     = $api;
    }
    public function sendMessage()
    {
        $mandrillApiInstance = $this->getMandrillApiInstance();

        if ($mandrillApiInstance === null) {
            return false;
        }

        $message    = array(
            'subject' => $this->message->getSubject(),
            'from_name' => $this->message->getFromName(),
            'from_email'=> $this->message->getFrom(),
        );
        foreach ($this->message->getTo() as $to) {
            $message['to'][] = array(
                'email' => $to
            );
        }
        foreach ($this->message->getBcc() as $bcc) {
            $message['to'][] = array(
                'email' => $bcc,
                'type' => 'bcc'
            );
        }
        if ($att = $this->message->getAttachments()) {
            $message['attachments'] = $att;
        }
        if ($headers = $this->message->getHeaders()) {
            $message['headers'] = $headers;
        }
        switch ($this->message->getType()) {
            case \Magento\Framework\Mail\MessageInterface::TYPE_HTML:
                $message['html'] = $this->message->getBody();
                break;
            case \Magento\Framework\Mail\MessageInterface::TYPE_TEXT:
                $message['text'] = $this->message->getBody();
                break;
        }

        $result = $mandrillApiInstance->messages->send($message);

        $this->processApiCallResult($result);

        return true;
    }

    private function processApiCallResult($result)
    {
        $currentResult = current($result);

        if (array_key_exists('status', $currentResult) && $currentResult['status'] == 'rejected') {
            throw new \Magento\Framework\Exception\MailException(
                new \Magento\Framework\Phrase("Email sending failed: %1", [$currentResult['reject_reason']])
            );
        }
    }

    /**
     * @return \Mandrill
     */
    private function getMandrillApiInstance()
    {
        return $this->api->getApi();
    }

    /**
     * Needed to be added otherwise during setup:di:compile you'll get an error.
     *
     * @return string
     */
    public function getMessage(){return;}
}

from magento2-mandrill.

centerax avatar centerax commented on July 30, 2024

Thanks Leon. 2.2 is not stable yet so do not expect the current stable release to be compatible with it. We will release a compatible version of this extension shortly.

from magento2-mandrill.

leonhelmus avatar leonhelmus commented on July 30, 2024

Can you please add that function. All the other function do work, but this one not, because you implement an interface that got that function in it. it needs to be added to transport otherwise i cant use mandrill on magento 2 and i need to make a core change to your module. is it possible to make a new branch for 2.2 where you add that function?

from magento2-mandrill.

Silarn avatar Silarn commented on July 30, 2024

#51 is a fix for this - and it actually returns the message object like it's supposed to.

from magento2-mandrill.

centerax avatar centerax commented on July 30, 2024

#52

from magento2-mandrill.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.