Notice: Undefined property: Eaglerocket\Customquote\Controller\Index\Index\Interceptor::$storeManager in Index.php on line 138

<?php
/**
 *
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Eaglerocket\Customquote\Controller\Index;


use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Framework\Translate\Inline\StateInterface;



class Index extends Action
{
    private $dataPersistor;
    /**
     * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page
     */

    protected $context;
  //  private $fileUploaderFactory;
    private $fileSystem;


    /**
     * @var \Magento\Framework\Mail\Template\TransportBuilder
     */
    protected $_transportBuilder;

    /**
     * @var \Magento\Framework\Translate\Inline\StateInterface
     */
    protected $inlineTranslation;

    /**
     * @var \Magento\Framework\App\Config\ScopeConfigInterface
     */
    protected $scopeConfig;

    /**
     * @var \Magento\Store\Model\StoreManagerInterface
     */
    protected $storeManager;


    /**
     * @param \Magento\Framework\App\Action\Context $context
     * @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
     * @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
     * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
     */

     public function __construct(
        \Magento\Framework\App\Action\Context $context,
       // Filesystem $fileSystem,
        //\Magento\MediaStorage\Model\File\UploaderFactory $fileUploaderFactory,
        \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder,
        \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation,
      //  \Eaglerocket\Customquote\Helper\Data $helper,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Store\Model\StoreManagerInterface $storeManager

    ) {
        parent::__construct($context );
      //  $this->fileUploaderFactory = $fileUploaderFactory;
       // $this->fileSystem          = $fileSystem;,$transportBuilder,$inlineTranslation, $scopeConfig
                $this->_context = $context;

        $this->_transportBuilder = $transportBuilder;
        $this->inlineTranslation = $inlineTranslation;
    //    $this->helper = $helper;
        $this->scopeConfig = $scopeConfig;
        $this->_storeManager = $storeManager;

    }

    public function execute()
    {

        $post = $this->getRequest()->getPostValue();
       // $filesData = $this->getRequest()->getFiles('upload_document');

       

        $txt='<table>';

       
        if($post['comment1']){
            $txt.='<tr><td><strong>Comment</strong>:'.$post['comment1'].'</td></tr>';
        }
        if($post['comment2']){
            $txt.='<tr><td><strong>Comment</strong>:'.$post['comment2'].'</td></tr>';
        }if($post['comment3']){
            $txt.='<tr><td><strong>Comment</strong>:'.$post['comment3'].'</td></tr>';
        }
        $txt.='</table>';
      




$templateOptions = array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $this->storeManager->getStore()->getId());
$templateVars = array(
                    'store' => $this->storeManager->getStore(),
                    'customer_name' => 'John Doe',
                    'message'   => 'Hello Auriga!!.'
                );
$from = array('email' => "[email protected]", 'name' => 'Name of Sender');
$this->inlineTranslation->suspend();
$to = array('[email protected]');

$storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
$templateId = $this->scopeConfig->getValue ( 'eaglerocket/customquote/email_template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId );

$transport = $this->_transportBuilder->setTemplateIdentifier($templateId, $storeScope)->setTemplateOptions($templateOptions)
            ->setTemplateVars($templateVars)
            ->setFrom($from)
            ->addTo($to)
            ->getTransport();
$transport->sendMessage();
$this->messageManager->addSuccess(__('Mail Sent Successfully'));
$this->inlineTranslation->resume();




        $this->inlineTranslation->resume();

        $this->messageManager->addSuccess(__('Form successfully submitted'));

        $this->_redirect('post_requirements');
    }

}

Answers 1

  • You didn't inject storeManager in construct. Add like this in your construct :

    protected $storeManager;
    
    public function __construct(
        .....
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        .....
    ) {
        $this->storeManager = $storeManager;
    }
    

    Now remove generated and clean cache.


Related Questions