cancel
Showing results for 
Search instead for 
Did you mean: 

Error in compilation

SOLVED

Error in compilation

I am trying to install this extension. When I tried to run `php bin/magento setup:di:compile` command I got `Missed required argument resultPageFactory in parent::__construct call.` error.

 

How can I pass more arguments ? What is the solution ?


Here is Place.php

<?php

/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Ccavenuepay\Controller\Ccavenuepay;

use Magento\Ccavenuepay\Controller\Ccavenuepay;
use Magento\Ccavenuepay\Helper\DataFactory;
use Magento\Checkout\Model\Type\Onepage;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Response\Http;
use Magento\Framework\Json\Helper\Data as JsonHelper;
use Magento\Framework\DataObject;
use Magento\Framework\Registry;
use Magento\Payment\Model\IframeConfigProvider;
use Magento\Quote\Api\CartManagementInterface;

/**
 * Class Place
 *
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
 */
class Place extends Ccavenuepay {

    /**
     * @var \Magento\Quote\Api\CartManagementInterface
     */
    protected $cartManagement;

    /**
     * @var \Magento\Framework\Event\ManagerInterface
     */
    protected $eventManager;

    /**
     * @var \Magento\Checkout\Model\Type\Onepage
     */
    protected $onepageCheckout;

    /**
     * @var \Magento\Framework\Json\Helper\Data
     */
    protected $jsonHelper;
    protected $logger;

    /**
     * @param Context $context
     * @param Registry $coreRegistry
     * @param DataFactory $dataFactory
     * @param CartManagementInterface $cartManagement
     * @param Onepage $onepageCheckout
     * @param JsonHelper $jsonHelper
     */
    public function __construct(
        Context $context,
        Registry $coreRegistry,
        DataFactory $dataFactory,
        CartManagementInterface $cartManagement,
        Onepage $onepageCheckout,
        \Magento\Checkout\Model\Session $csession,
        JsonHelper $jsonHelper,

        \Magento\Checkout\Model\Session $checkoutSession,
        \Magento\Sales\Model\OrderFactory $orderFactory,
        \Magento\Ccavenuepay\Model\Ccavenuepay $ccavenuepay,
        \Magento\Ccavenuepay\Helper\Checkout $checkoutHelper,
        \Psr\Log\LoggerInterface $logger

    ) {
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
        $this->logger = new \Zend\Log\Logger();
        $this->logger->addWriter($writer);
        $this->logger->info("Place extends Ccavenuepay=====");

        $this->eventManager = $context->getEventManager();
        $this->cartManagement = $cartManagement;
        $this->onepageCheckout = $onepageCheckout;
        $this->jsonHelper = $jsonHelper;
        parent::__construct($context, $checkoutSession, $orderFactory, $ccavenuepay, $checkoutHelper, $logger);
    }

    /**
     * Send request to authorize.net
     *
     * @return string
     */
    public function execute() {
        $this->logger->info("Place extends Ccavenuepay=====execute");
        $paymentParam = $this->getRequest()->getParam('payment');
        $controller = $this->getRequest()->getParam('controller');
        $response = $this->getResponse();

        if (isset($paymentParam['method'])) {
            $this->_getDirectPostSession()->setQuoteId($this->_getCheckout()->getQuote()->getId());
            /**
             * Current workaround depends on Onepage checkout model defect
             * Method Onepage::getCheckoutMethod performs setCheckoutMethod
             */
            $this->onepageCheckout->getCheckoutMethod();

            if ($controller == IframeConfigProvider::CHECKOUT_IDENTIFIER) {
                return $this->placeCheckoutOrder();
            }

            $params = $this->dataFactory
                    ->create(DataFactory::AREA_FRONTEND)
                    ->getSaveOrderUrlParams($controller);
            $this->_forward(
                    $params['action'], $params['controller'], $params['module'], $this->getRequest()->getParams()
            );
        } else {
            $result = ['error_messages' => __('Please choose a payment method.'), 'goto_section' => 'payment'];
            if ($response instanceof Http) {
                $response->representJson($this->jsonHelper->jsonEncode($result));
            }
        }
    }

    /**
     * Place order for checkout flow
     *
     * @return string
     */
    protected function placeCheckoutOrder() {
        $this->logger->info("Place extends Ccavenuepay=====placeCheckoutOrder");
        $result = new DataObject();
        $response = $this->getResponse();
        try {
            $this->cartManagement->placeOrder($this->_getCheckout()->getQuote()->getId());
            $result->setData('success', true);
            $this->eventManager->dispatch(
                    'checkout_ccavenuepay_placeOrder', [
                'result' => $result,
                'action' => $this
                    ]
            );
        } catch (\Exception $exception) {
            $result->setData('error', true);
            $result->setData('error_messages', __('Cannot place order.'));
        }
        if ($response instanceof Http) {
            $response->representJson($this->jsonHelper->jsonEncode($result));
        }
    }

}

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Error in compilation

Hi @foysal,

 

Please replace constructor code with below code:

public function __construct(
        Context $context,
        Registry $coreRegistry,
        DataFactory $dataFactory,
        CartManagementInterface $cartManagement,
        Onepage $onepageCheckout,        \Magento\Checkout\Model\Session $csession,
        JsonHelper $jsonHelper,        \Magento\Checkout\Model\Session $checkoutSession,        \Magento\Sales\Model\OrderFactory $orderFactory,        \Magento\Ccavenuepay\Model\Ccavenuepay $ccavenuepay,        \Magento\Ccavenuepay\Helper\Checkout $checkoutHelper,        \Psr\Log\LoggerInterface $logger,
\Magento\Framework\View\Result\PageFactory $resultPageFactory, \Magento\Sales\Api\OrderRepositoryInterface $orderRepository, \Magento\Sales\Model\Service\InvoiceService $invoiceService, \Magento\Framework\DB\Transaction $transaction, \Magento\Sales\Model\Order\Email\Sender\InvoiceSender $invoiceSender
){
$writer
= new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
$this
->logger = new \Zend\Log\Logger();
$this
->logger->addWriter($writer);
$this
->logger->info("Place extends Ccavenuepay=====");
$this
->eventManager = $context->getEventManager();
$this->cartManagement = $cartManagement;
$this
->onepageCheckout = $onepageCheckout;
$this
->jsonHelper = $jsonHelper;
parent
::__construct($context, $checkoutSession,
$orderFactory
, $ccavenuepay, $checkoutHelper, $logger,
$resultPageFactory,$orderRepository,$invoiceService,
$transaction
,$invoiceSender);

Change in the file and run below commands again.

php bin/magento setup:upgrade

php bin/magento setup:di:compile

 

Hope this helps you!

Problem Solved! Click Kudos & Accept as Solution!

View solution in original post

5 REPLIES 5

Re: Error in compilation

Hi @foysal 

 

It may be possible some one fogot to inject the argument from the parent. $context and $data are mandatory

 

Please check with your file, and try to pass as below:

public function __construct(
    \Magento\Framework\View\Element\Template\Context $context, // parent argument
    ......
    array $data = [] // parent argument
) {
    ......
    parent::__construct($context, $data);
}

It may help!
Problem Solved? Please click on 'Kudos' & Accept as Solution!

Problem solved? Click Accept as Solution!

Re: Error in compilation

Hi @foysal ,

 

Please check below controller file constructor

Magento\Ccavenuepay\Controller\Ccavenuepay

and cross check how many arguments are passed to the constructor.

 

As we are passing, 6 arguments to the parent constructor. Error shows there is mismatch in the parent constructor.

parent::__construct($context, $checkoutSession, $orderFactory, $ccavenuepay, $checkoutHelper, $logger);

 

Hope this helps you!

Problem Solved! Click Kudos & Accept as Solution!

Re: Error in compilation

Thanks @Nishu Jindal .  Here is the Parent class  Ccavenuepay.php .

<?php

/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Ccavenuepay\Controller;

use Magento\Ccavenuepay\Helper\Data;

/**
 * Payflow Checkout Controller
 */
abstract class Ccavenuepay extends \Magento\Framework\App\Action\Action {

    /**
     * @var \Magento\Checkout\Model\Session
     */
    protected $_checkoutSession;

    /**
     * @var \Magento\Sales\Model\OrderFactory
     */
    protected $_orderFactory;

    /**
     * @var \Psr\Log\LoggerInterface
     */
    protected $_logger;
    protected $logger;

    /**
     * @var \Magento\Ccavenuepay\Model\Ccavenuepay
     */
    protected $_ccavenuepay;

    /**
     * @var \Magento\Ccavenuepay\Helper\Checkout
     */
    protected $_checkoutHelper;

    /**
     * @var \Magento\Ccavenuepay\Helper\data
     */
    protected $_ccavenuepayHelper;

    /**
     * Redirect block name
     * @var string
     */
    protected $_redirectBlockName = 'ccavenuepay.iframe';

    /**
     * @var \Magento\Sales\Api\OrderRepositoryInterface
     */
    protected $_orderRepository;

    /**
     * @var \Magento\Sales\Model\Service\InvoiceService
     */
    protected $_invoiceService;
 
    /**
     * @var \Magento\Framework\DB\Transaction
     */
    protected $_transaction;

    /**
     * @var \Magento\Sales\Model\Order\Email\Sender\InvoiceSender
     */
    protected $_invoiceSender;

    /**
     * @param \Magento\Framework\App\Action\Context $context
     * @param \Magento\Checkout\Model\Session $checkoutSession
     * @param \Magento\Sales\Model\OrderFactory $orderFactory
     * @param \Magento\Ccavenuepay\Model\PayflowlinkFactory $ccavenuepay
     * @param \Magento\Ccavenuepay\Helper\Checkout $checkoutHelper
     * @param \Psr\Log\LoggerInterface $logger
     */
    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Checkout\Model\Session $checkoutSession,
        \Magento\Sales\Model\OrderFactory $orderFactory,
        \Magento\Ccavenuepay\Model\Ccavenuepay $ccavenuepay,
        \Magento\Ccavenuepay\Helper\Checkout $checkoutHelper,
        \Psr\Log\LoggerInterface $logger,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory,
        \Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
        \Magento\Sales\Model\Service\InvoiceService $invoiceService,
        \Magento\Framework\DB\Transaction $transaction,
        \Magento\Sales\Model\Order\Email\Sender\InvoiceSender $invoiceSender
    ) {

        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
        $this->logger = new \Zend\Log\Logger();
        $this->logger->addWriter($writer);

        $this->_checkoutSession = $checkoutSession;
        $this->_orderFactory = $orderFactory;
        $this->_logger = $logger;
        $this->_ccavenuepay = $ccavenuepay;
        $this->_checkoutHelper = $checkoutHelper;
        $this->_orderRepository = $orderRepository;
        $this->_invoiceService = $invoiceService;
        $this->_transaction = $transaction;
        $this->_invoiceSender = $invoiceSender;
        parent::__construct($context);
    }

    /**
     * Cancel order, return quote to customer
     *
     * @param string $errorMsg
     * @return false|string
     */
    protected function _cancelPayment($errorMsg = '') {
        $errorMsg = trim(strip_tags($errorMsg));

        $gotoSection = false;
        $this->_checkoutHelper->cancelCurrentOrder($errorMsg);
        if ($this->_checkoutSession->restoreQuote()) {
            //Redirect to payment step
            $gotoSection = 'paymentMethod';
        }

        return $gotoSection;
    }

    public function errorAction() {
        $this->_redirect('checkout/onepage/');
    }

    /**
     * Check if email is registered at Moneybookers
     */
    protected function _getCheckout() {
        return $this->_objectManager->get('Magento\Checkout\Model\Session');
    }

    /**
     * Get session model
     *
     * @return \Magento\Ccavenuepay\Model\Ccavenuepay\Session
     */
    protected function _getCcavenuepayPostSession() {
        return $this->_objectManager->get('Magento\Ccavenuepay\Model\Ccavenuepay\Session');
    }

    protected function _getHelper() {
        return $this->_ccavenuepay->getHelper();
    }

    protected function _createInvoice($orderId)
    {
        $order = $this->_orderRepository->get($orderId);
        if($order->canInvoice()) {
            $invoice = $this->_invoiceService->prepareInvoice($order);
            $invoice->setRequestedCaptureCase(\Magento\Sales\Model\Order\Invoice::CAPTURE_OFFLINE);
            $invoice->register();
            $invoice->getOrder()->setCustomerNoteNotify(false);
            $invoice->getOrder()->setIsInProcess(true);
            $invoice->save();
            $transactionSave = $this->_transaction->addObject( $invoice )->addObject( $invoice->getOrder() );
            $transactionSave->save();
            $order->addStatusHistoryComment('Automatically INVOICED.', false)->save();
            $this->_invoiceSender->send($invoice);
        }
    }
}



Could you please help me now ? What will be the code ? Thanks.

 

Re: Error in compilation

Hi @foysal,

 

Please replace constructor code with below code:

public function __construct(
        Context $context,
        Registry $coreRegistry,
        DataFactory $dataFactory,
        CartManagementInterface $cartManagement,
        Onepage $onepageCheckout,        \Magento\Checkout\Model\Session $csession,
        JsonHelper $jsonHelper,        \Magento\Checkout\Model\Session $checkoutSession,        \Magento\Sales\Model\OrderFactory $orderFactory,        \Magento\Ccavenuepay\Model\Ccavenuepay $ccavenuepay,        \Magento\Ccavenuepay\Helper\Checkout $checkoutHelper,        \Psr\Log\LoggerInterface $logger,
\Magento\Framework\View\Result\PageFactory $resultPageFactory, \Magento\Sales\Api\OrderRepositoryInterface $orderRepository, \Magento\Sales\Model\Service\InvoiceService $invoiceService, \Magento\Framework\DB\Transaction $transaction, \Magento\Sales\Model\Order\Email\Sender\InvoiceSender $invoiceSender
){
$writer
= new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
$this
->logger = new \Zend\Log\Logger();
$this
->logger->addWriter($writer);
$this
->logger->info("Place extends Ccavenuepay=====");
$this
->eventManager = $context->getEventManager();
$this->cartManagement = $cartManagement;
$this
->onepageCheckout = $onepageCheckout;
$this
->jsonHelper = $jsonHelper;
parent
::__construct($context, $checkoutSession,
$orderFactory
, $ccavenuepay, $checkoutHelper, $logger,
$resultPageFactory,$orderRepository,$invoiceService,
$transaction
,$invoiceSender);

Change in the file and run below commands again.

php bin/magento setup:upgrade

php bin/magento setup:di:compile

 

Hope this helps you!

Problem Solved! Click Kudos & Accept as Solution!

Re: Error in compilation

Thanks @Nishu Jindal . Your solution is working. Thanks.