cancel
Showing results for 
Search instead for 
Did you mean: 

Removing commented lines cause errors on Terminal

SOLVED

Removing commented lines cause errors on Terminal

Hello.

I am trying to remove the commented lines.

However when I remove it and compile the custom module from Terminal, it receives an error.

Errors during compilation:
Missed required argument checkoutSession in parent::__construct call.

I wonder why it happens. I only deleted unused code such as:

//use Magento\Framework\View\Result\PageFactory

This is the beginning of my class.

use \Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Controller\ResultFactory;
//use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
//use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Serialize\SerializerInterface;


class UpdatePost extends \Magento\Checkout\Controller\Cart
{

  /**
  * @var \Magento\Framework\Registry
  */
 
    protected $_registry;
    protected $eventManager;
    protected $_checkoutSession;
    protected $_logger;
    protected $_customerSession;
    protected $jsonResultFactory;
    protected $jsonHelper;
    protected $context;
    protected $resultFactory;
    protected $scopeConfig;
    protected $request;
    protected $data;
    protected $_layout;

    public function _construct(
        \Magento\Checkout\Model\Session $checkoutSession,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\Event\Manager $eventManager,
        \Magento\Checkout\Model\Cart $cart,
        \Psr\Log\LoggerInterface $logger,
        \Magento\Customer\Model\Session $customerSession,
        Context $context,
        array $data = [],
        \Magento\Framework\Json\Helper\Data $jsonHelper,
       \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
       \Magento\Framework\View\LayoutInterface $layout
    ) {
        $this->_checkoutSession = $checkoutSession;
        $this->_registry = $registry;
        $this->eventManager = $eventManager;
        $this->cart = $cart;
        $this->_logger = $logger;
        $this->_customerSession = $customerSession;
        $this->context = $context;
        $this->jsonHelper = $jsonHelper;
        $this->data = $data;
        $this->scopeConfig = $scopeConfig;
        parent::__construct($context, $data);

       $this->_layout = $layout;
    }
    
1 REPLY

Re: Removing commented lines cause errors on Terminal

@tvgarden

 

Just replace below code with your existing code and check.

 

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Serialize\SerializerInterface;


class UpdatePost extends \Magento\Checkout\Controller\Cart
{

  /**
  * @var \Magento\Framework\Registry
  */
 
    protected $_registry;
    protected $eventManager;
    protected $_checkoutSession;
    protected $_logger;
    protected $_customerSession;
    protected $jsonResultFactory;
    protected $jsonHelper;
    protected $context;
    protected $resultFactory;
    protected $scopeConfig;
    protected $request;
    protected $data;
    protected $_layout;

    public function _construct(
        \Magento\Checkout\Model\Session $checkoutSession,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\Event\Manager $eventManager,
        \Magento\Checkout\Model\Cart $cart,
        \Psr\Log\LoggerInterface $logger,
        \Magento\Customer\Model\Session $customerSession,
	\Magento\Framework\Json\Helper\Data $jsonHelper,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Framework\View\LayoutInterface $layout,
        Context $context,
        array $data = []
        
    ) {
        $this->_checkoutSession = $checkoutSession;
        $this->_registry = $registry;
        $this->eventManager = $eventManager;
        $this->cart = $cart;
        $this->_logger = $logger;
        $this->_customerSession = $customerSession;
        $this->context = $context;
        $this->jsonHelper = $jsonHelper;
	$this->scopeConfig = $scopeConfig;
        $this->data = $data;        
	$this->_layout = $layout;
        parent::__construct($context, $data);

       
    }
    

After replacing the code - run below commands :

 

  • rm -rf generated
  • php bin/magento setup:di:compile
  • php bin/magento cache:clean
  • php bin/magento cache:flush
if issue solved,Click Kudos & Accept as Solution