1

I want to override this file vendor/magento/module-sales/Controller/Adminhtml/Shipment/AbstractShipment/View.php

So I can change line 49 from setModule('adminhtml') to setModule('adminhtml')

Any help is very appreciated

I've tried creating app/code/MyCompany/ModuleName/Controller/Adminhtml/Shipment/AbstractShipment/View.php with this in the file:

namespace             
MyCompany\MyModule\Controller\Adminhtml\Shipment\AbstractShipment;


class View extends \Magento\Sales\Controller\Adminhtml\Shipment\AbstractShipment\View {

public function execute()
{
        /** @var \Magento\Backend\Model\View\Result\Forward $resultForward */
        $resultForward = $this->resultForwardFactory->create();
        if ($this->getRequest()->getParam('shipment_id')) {
            $resultForward->setController('order_shipment')
                ->setModule('adminhtml')
                ->setParams(['come_from' => 'shipment'])
                ->forward('view');
            return $resultForward;
        } else {
            return $resultForward->forward('noroute');
        }
    }
}

module.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="MyCompany_MyModule" setup_version="0.0.1"/>
</config>

di.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Sales\Controller\Adminhtml\Shipment\AbstractShipment\View" type="MyCompany\MyModule\Controller\Adminhtml\Shipment\AbstractShipment\View"/>
</config>
0

whenever you extend class you have to pass value of parent counstruct so please add below code in your file

public function __construct(
    \Magento\Backend\App\Action\Context  $context,
    \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
) {
    parent::__construct($context, $resultForwardFactory);
    $this->resultForwardFactory = $resultForwardFactory;
}
  • Doesn't work. But thanks for the suggestion. – VirtusO Jul 27 '18 at 10:07
  • I need to change line 49 from setModule('adminhtml') to setModule('adminhtml') otherwise I get a 404 error when I try to view a shipment – VirtusO Jul 27 '18 at 10:07
  • what is the diff between setModule('adminhtml') and setModule('adminhtml')? – Rutvee Sojitra Jul 27 '18 at 10:09
  • ok got it you mean setModule('admin') to setModule('adminhtml'). ok so what's the error are you facing? Have made above changes and clear your generated folder and cache? – Rutvee Sojitra Jul 27 '18 at 10:11
  • Yes, I cleared cache and generated everything. I get a "404 Not Found" error when I try to view a shipment in admin panel under Sales. If I change 'admin' to 'adminhtml' then it works, but I can't get the override to work. The GitHub issue is here: github.com/magento/magento2/issues/16567 – VirtusO Jul 27 '18 at 10:20

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.