1

I am trying to extend Magento\Sales\Block\Order\View by using preferences to get some more information into customer order view page. Everything works fine if i remove __construct. so what might be the root cause of this issue?

Have been following lot of answers from community but no luck. ( removed cache,generation and done upgrade ) link

Errors :

From report : Object DOMDocument should be created.

From log :

Recoverable Error: Argument 2 passed to Magento\Sales\Block\Order\View::__construct() must be an instance of Magento\Framework\Registry,

namespace Myvendor\Mymodule\Block\Order;

use Magento\Customer\Model\Context;
/**
 * Sales order view block
 */
class View extends \Magento\Sales\Block\Order\View
{

    // Some protected properties 

    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\App\Http\Context $httpContext,
        \Magento\Payment\Helper\Data $paymentHelper,
        array $data = []
    ) {
        $this->_paymentHelper = $paymentHelper;
        $this->_coreRegistry = $registry;
        $this->httpContext = $httpContext;
        parent::__construct($context,$paymentHelper,$registry,$httpContext, $data);
        $this->_isScopePrivate = true;
    }

Any help would be appreciated.

1

This is caused by the fact that the payment helper you inject via dependency injection is not at the right position of the original constructor.

To fix that you need to replace:

parent::__construct($context,$paymentHelper,$registry,$httpContext, $data);

With:

parent::__construct($context,$registry,$httpContext, $paymentHelper, $data);
  • Thanks for response , now am getting Argument 4 passed to Magento\Sales\Block\Order\View::__construct() must be an instance of Magento\Payment\Helper\Data. – Krishna ijjada Jun 4 '16 at 9:06
  • @krishnaijjada see my edit. By the way if you don't inject extra dependencies you don't need to add the constructor to your code ;) – Raphael at Digital Pianism Jun 4 '16 at 10:02
  • Perfect..:) It is working as charm. so the passing variables in the Constructor is important. in which order do i have to follow for inserting new dependencies. do i need to send to parent constructor? what is the core hack for this type of errors ? – Krishna ijjada Jun 4 '16 at 10:27
  • @krishnaijjada feel free to ask a new question and send it to me as it'll be hard to answer as a comment ;) – Raphael at Digital Pianism Jun 4 '16 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.