4

Error When i load my Helper Class Magento2. it shows

1 exception(s): Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Wac\DropPin\Helper\Data

app/code/Wac/DropPin/view/frontend/templates/cart/item/default.phtml

 echo $this->helper('Wac\DropPin\Helper\Data')->productWeight('Test');

app/code/Wac/DropPin/Helper/Data.php

<?php
namespace Wac\DropPin\Helper;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
        protected $_productRepository;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,       
        \Magento\Catalog\Model\ProductRepository $productRepository,
        array $data = []
    )
    {
        $this->_productRepository = $productRepository;
        parent::__construct($context, $data);
    }



    public function productWeight($id)
    {
        return $id;
    }

}
4
  • What is the exact error you are getting? The posted error or some more lines there? Commented Jun 27, 2019 at 8:59
  • Sir ,Please Check Screenshot Commented Jun 27, 2019 at 9:02
  • Did you run di compile? Commented Jun 27, 2019 at 9:05
  • 1
    You have injected block context which is not needed. Commented Jun 27, 2019 at 9:10

1 Answer 1

5

What about this

namespace Wac\DropPin\Helper;

use Magento\Framework\App\Helper\AbstractHelper;

class Data extends AbstractHelper
{

    /**
     * @param \Magento\Framework\App\Helper\Context $context
     */
    public function __construct(
        \Magento\Framework\App\Helper\Context $context
    ) {
        parent::__construct($context);
    }

    // custom method
}

Remember to di compile

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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