0

I got this file:

module-sales/Block/Adminhtml/Order/Create/Shipping/Method/Form.php

I want to override this in a custom module.

How can I do that? Thanks!

2

For Block use the below code in your module's di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Sales\Block\Adminhtml\Order\Create\Shipping\Method\Form" type="[VendorName]\[ModuleName]\Block\Adminhtml\Order\Create\Shipping\Method\Form"/>
</config>

For phtml override create a xml file with name sales_order_create_load_block_shipping_method.xml on your module's layout folder and set template for this "order.create.shipping.method.form" and use your template file location as per the requirement.

| improve this answer | |
  • Thanks! Where should I put the di.xml? – k33n Jun 19 '18 at 13:13
  • yes, added etc/di.xml – Magento Developer Jun 19 '18 at 13:14
1

Try this.

app/code/Namespace/ModuleName/etc/

<?xml version="1.0"?>
  <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
  <module name="Magenticians_Modulecontact" setup_version="1.0.1">
  </module>
</config>

app/code/Namespace/ModuleName/registration.php

<?php
    \Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Magenticians_Modulecontact',
    __DIR__
);

app/code/Namespace/ModuleName/etc/di.xml file

<?xml version="1.0"?>
   <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Sales\Block\Adminhtml\Order\Create\Shipping\Method\Form" type="[Namespace]\[ModuleName]\Block\Adminhtml\Order\Create\Shipping\Method\Form" />
</config>

Run : php bin/magento setup:upgrade

Run : php bin/magento c:c

| improve this answer | |

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.