Magento – How to override vendor module in magento 2 via code

adminhtmlmagento2override-model

Following is the code
– override is not working

app/code/Bensupply/DisplaySupplierName/etc/module.xml

<?xml version="1.0"?>
<!--
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="Bensupply_DisplaySupplierNameAdmin" setup_version="2.0.3" active="true">
        <sequence>
            <module name="Magento_Sales"/>           
        </sequence>
    </module>
</config>

app/code/Bensupply/DisplaySupplierName/view/adminhtml/templates/items/column/name.phtml to override

<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php
/**
 * @see \Magento\Sales\Block\Adminhtml\Items\Column\Name
 */
?>

<?php if ($_item = $block->getItem()): ?>
    <div id="order_item_<?php /* @escapeNotVerified */ echo $_item->getId() ?>_title"
         class="product-title">
        <?php echo $block->escapeHtml($_item->getName()) ?>
    </div>

    <div class="product-sku-block">
        <span><?php /* @escapeNotVerified */ echo __('SKU---') ?>:</span> <?php echo implode('<br />', $this->helper('Magento\Catalog\Helper\Data')->splitSku($block->escapeHtml($block->getSku()))); ?>
    </div>

Main File to is in the vendor folder
vendor/magento/module-sales/view/adminhtml/templates/items/column(name.phtml)

Expected output should display in the Admin Pannel near SKU
https://www.screencast.com/t/DJu3qjdw8d

Best Answer

To add SKU create a layout file sales_order_view.xml under Vendor/Module/view/adminhtml/layout

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <body>
        <referenceBlock name="column_name">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Vendor_Module::items/column/name.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>
Related Topic