106 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
			
		
		
	
	
			106 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
| <?php
 | |
| 
 | |
| namespace IpSupply\AssetRecovery\Controller\Index;
 | |
| use Magento\Framework\Translate\Inline\StateInterface;
 | |
| use Magento\Framework\Escaper;
 | |
| use Magento\Framework\Mail\Template\TransportBuilder;
 | |
| 
 | |
| use Magento\Framework\App\Action\Context;
 | |
| use Magento\Framework\View\Result\PageFactory;
 | |
| use Magento\Framework\Controller\ResultFactory;
 | |
| 
 | |
| class Index extends \Magento\Framework\App\Action\Action {
 | |
| 
 | |
|     protected $pageFactory;
 | |
|     protected $_messageManager;
 | |
|     protected $resultFactory;
 | |
|     protected $inlineTranslation;
 | |
|     protected $escaper;
 | |
|     protected $transportBuilder;
 | |
|     protected $logger;
 | |
| 
 | |
| 
 | |
|     public function __construct(
 | |
|         Context $context, 
 | |
|         PageFactory $pageFactory, 
 | |
|         \Magento\Framework\Message\ManagerInterface $messageManager,
 | |
|         StateInterface $inlineTranslation,
 | |
|         Escaper $escaper,
 | |
|         TransportBuilder $transportBuilder,
 | |
|         \Magento\Framework\App\Helper\Context $helperContext
 | |
|     )
 | |
|     {
 | |
|         $this->pageFactory = $pageFactory;
 | |
|         $this->messageManager = $messageManager;
 | |
|         $this->resultFactory = $context->getResultFactory();
 | |
|         $this->inlineTranslation = $inlineTranslation;
 | |
|         $this->escaper = $escaper;
 | |
|         $this->transportBuilder = $transportBuilder;
 | |
|         $this->logger = $helperContext->getLogger();
 | |
|         parent::__construct($context);
 | |
|     }
 | |
| 
 | |
| 
 | |
|     public function execute()
 | |
|     {
 | |
|         $page = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
 | |
|         $data = $this->getRequest()->getPostValue();
 | |
|         if (!empty($data)) {
 | |
|             if (!array_key_exists("name", $data)) {
 | |
|                 $this->messageManager->addError(__("The field name is invalid"));
 | |
|             } else if (!array_key_exists("company_name", $data)) {
 | |
|                 $this->messageManager->addError(__("The field company name is invalid"));
 | |
|             } else if (!array_key_exists("email", $data)) {
 | |
|                 $this->messageManager->addError(__("The field email is invalid"));
 | |
|             } else if (!array_key_exists("phone", $data)) {
 | |
|                 $this->messageManager->addError(__("The field phone is invalid"));
 | |
|             } else if (!array_key_exists("date", $data)) {
 | |
|                 $this->messageManager->addError(__("The field date is invalid"));
 | |
|             } else if (!array_key_exists("items", $data)) {
 | |
|                 $this->messageManager->addError(__("The field items is invalid"));
 | |
|             }else {
 | |
|                 $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);
 | |
|                 $customerSession = $objectManager->create('Magento\Customer\Model\Session');
 | |
|                 try {
 | |
|                     $this->inlineTranslation->suspend();
 | |
|                     $sender = [
 | |
|                         'name' => $this->escaper->escapeHtml($data["name"]),
 | |
|                         'email' => $this->escaper->escapeHtml($data["email"]),
 | |
|                     ];
 | |
|                     $transport = $this->transportBuilder
 | |
|                         ->setTemplateIdentifier('email_asset_recovery_template')
 | |
|                         ->setTemplateOptions(
 | |
|                             [
 | |
|                                 'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
 | |
|                                 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
 | |
|                             ]
 | |
|                         )
 | |
|                         ->setTemplateVars([
 | |
|                             'name'  => $data["name"],
 | |
|                             'email'  => $data["email"],
 | |
|                             'company_name'  => $data["company_name"],
 | |
|                             'phone'  => $data["phone"],
 | |
|                             'date'  => $data["date"],
 | |
|                             'items'  => nl2br($data["items"]),
 | |
| 
 | |
|                         ])
 | |
|                         ->setFrom($sender)
 | |
|                         ->addTo($email_contact)
 | |
|                         ->getTransport();
 | |
|                     $transport->sendMessage();
 | |
|                     $this->inlineTranslation->resume();
 | |
|                     $this->messageManager->addSuccess(__("Thanks you. We'll respond to you very soon."));
 | |
|                 } catch (\Exception $e) {
 | |
|                     $this->logger->debug($e->getMessage());
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|         }
 | |
|         return $page;
 | |
| 
 | |
|     }
 | |
| 
 | |
| }
 |