At first thank you for your helps. I have found way how can i call helper in override block in magento 2
In my case i have override block \Magento\Sales\Block\Adminhtml\Order\View\Items
in my module and want to access helper function of my module.
First we need to check if their is constructor in main class i.e. \Magento\Sales\Block\Adminhtml\Order\View\Items.php
in my case their is no constructor defined in Items.php
so i have checked class Items
from which it is extending and found that its extending from \Magento\Sales\Block\Adminhtml\Items\AbstractItems.php
their is constructor defined i have copied that constructor in my override class i.e. Company\Module\Block\Adminhtml\Order\View\Items.php
and set all original constructor arguments to parent constructor here is code
constructor code of \Magento\Sales\Block\Adminhtml\Items\AbstractItems
class which is extended by \Magento\Sales\Block\Adminhtml\Order\View\Items.php
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry,
\Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration,
\Magento\Framework\Registry $registry,
array $data = []
) {
$this->stockRegistry = $stockRegistry;
$this->stockConfiguration = $stockConfiguration;
$this->_coreRegistry = $registry;
parent::__construct($context, $data);
}
constructor code of override block i.e. Company\Module\Block\Adminhtml\Order\View\Items.php
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry,
\Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration,
\Magento\Framework\Registry $registry,
\Company\Module\Helper\Data $helper,
array $data = []
) {
$this->_helper = $helper;
parent::__construct($context, $stockRegistry, $stockConfiguration, $registry, $data);
}
Cleared cache and generations from var folder and its working fine.
\Magento\Sales\Block\Adminhtml\Order\View\Items
& past into your custom class (extended class Company\Module\Block\Adminhtml\Order\View\Items ;`) now add your helper class into the constructor it should work.. – Mohammad Mujassam Mar 12 '17 at 19:00constructor
invendor/magento/module-sales/Block/Adminhtml/Order/View/Items.php
@MohammadMujassam – Aman Alam Mar 12 '17 at 23:17