72 lines
2.4 KiB
PHP
Executable File
72 lines
2.4 KiB
PHP
Executable File
<?php
|
|
namespace IpSupply\Prology\Api\Controller;
|
|
|
|
use Magento\Framework\App\Helper\Context;
|
|
use IpSupply\Prology\Api\Interface\PriceSuggestionInterface;
|
|
use Magento\Framework\Translate\Inline\StateInterface;
|
|
use Magento\Framework\Escaper;
|
|
use Magento\Framework\Mail\Template\TransportBuilder;
|
|
|
|
|
|
class PriceSuggestionApi extends \Magento\Framework\App\Helper\AbstractHelper implements PriceSuggestionInterface
|
|
{
|
|
protected $request;
|
|
protected $inlineTranslation;
|
|
protected $escaper;
|
|
protected $transportBuilder;
|
|
|
|
public function __construct(
|
|
Context $context,
|
|
StateInterface $inlineTranslation,
|
|
Escaper $escaper,
|
|
TransportBuilder $transportBuilder,
|
|
\Magento\Framework\Webapi\Rest\Request $request
|
|
) {
|
|
$this->request = $request;
|
|
$this->inlineTranslation = $inlineTranslation;
|
|
$this->escaper = $escaper;
|
|
$this->transportBuilder = $transportBuilder;
|
|
parent::__construct($context);
|
|
}
|
|
|
|
/**
|
|
* POST for test api
|
|
* @param string[] $data
|
|
* @return string
|
|
*/
|
|
public function sendEmail($data)
|
|
{
|
|
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
|
|
$scopeConfig = $objectManager->create('\Magento\Framework\App\Config\ScopeConfigInterface');
|
|
$email_contact = $scopeConfig->getValue('trans_email/ident_general/email',\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
|
|
try {
|
|
$this->inlineTranslation->suspend();
|
|
$sender = [
|
|
'name' => $this->escaper->escapeHtml($data['first_name'].' '.$data['last_name']),
|
|
'email' => $this->escaper->escapeHtml($data['email']),
|
|
];
|
|
$transport = $this->transportBuilder
|
|
->setTemplateIdentifier('email_price_suggestion_template')
|
|
->setTemplateOptions(
|
|
[
|
|
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
|
|
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
|
|
]
|
|
)
|
|
->setTemplateVars([
|
|
'data' => $data
|
|
])
|
|
->setFrom($sender)
|
|
->addTo($email_contact)//admin@apactech.io
|
|
->getTransport();
|
|
$transport->sendMessage();
|
|
$this->inlineTranslation->resume();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
}
|