Вызов Magento 2 Api - PullRequest
       13

Вызов Magento 2 Api

0 голосов
/ 26 мая 2019

Здравствуйте, я новичок в magento 2, так что спасибо за вашу снисходительность.Я только что создал модуль, который позаботится о замене части «свяжитесь с нами» в magento очень простой формой.Я получаю электронные письма, но хотел бы, чтобы ими управлял api rest.Я не знаю, как поблагодарить вас за ваше возвращение.Вот мой php код для отправки.

const XML_PATH_EMAIL_RECIPIENT_NAME = 'trans_email/ident_support/name';
const XML_PATH_EMAIL_RECIPIENT_EMAIL = 'trans_email/ident_support/email';

protected $_inlineTranslation;
protected $_transportBuilder;
protected $_scopeConfig;
protected $_logLoggerInterface;


public function __construct(
    \Magento\Framework\App\Action\Context $context,
    \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation,
    \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder,
    \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
    \Psr\Log\LoggerInterface $loggerInterface,
    array $data = []

    )
{
    $this->_inlineTranslation = $inlineTranslation;
    $this->_transportBuilder = $transportBuilder;
    $this->_scopeConfig = $scopeConfig;
    $this->_logLoggerInterface = $loggerInterface;
    $this->messageManager = $context->getMessageManager();

    parent::__construct($context);     
}

public function execute()
{
    $post = $this->getRequest()->getPost();
    try
    {

        $this->_inlineTranslation->suspend();
        $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;

        $sender = [
            'name' => $post['name'],
            'email' => $post['email'],
            ''
        ];

        $sentToEmail = $this->_scopeConfig ->getValue('trans_email/ident_general/email',\Magento\Store\Model\ScopeInterface::SCOPE_STORE);

        $sentToName = $this->_scopeConfig ->getValue('trans_email/ident_general/name',\Magento\Store\Model\ScopeInterface::SCOPE_STORE);


        $transport = $this->_transportBuilder
        ->setTemplateIdentifier('testemail_email_template')
        ->setTemplateOptions(
            [
                'area' => 'frontend',
                'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
            ]
            )
            ->setTemplateVars([
                'name'  => $post['name'],
                'email'  => $post['email']
            ])
            ->setFrom($sender)
            ->addTo($sentToEmail,$sentToName)
            ->addTo('abderrahmane.mammeri@technology-everywhere.fr','owner')
            ->getTransport();

            $transport->sendMessage();

            $this->_inlineTranslation->resume();
            $this->messageManager->addSuccess('Votre mail a bien été envoyé');
            $this->_redirect('testemail/index/index');

    } catch(\Exception $e){
        $this->messageManager->addError($e->getMessage());
        $this->_logLoggerInterface->debug($e->getMessage());
        exit;
    }

}

}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...