1

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

3 Answers 3

1

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>
1

You are wrong in the aspect of how templates in modules works. You are trying to override template of module A in B by creating it in module's B view/../.. path. It will not work.

If you want to override phtml template from a module you must do at least two things:

  1. Create desired template in module as you actually did.
  2. In layout xml file inside of your module set your template for a given block with some variation of the following snippet:

    <referenceBlock name="REF_BLOCK">
        <action method="setTemplate">
           <argument name="template" xsi:type="string">Vendor_Module::path/to/template/file.phtml</argument>
        </action>
    </referenceBlock>
    

Simple putting template in custom module along with setting sequence is not enough. That approach is only for custom designs where you can actually put your template in appropriate path in custom design package and it will override original template automatically if custom design is enabled. But that is not a case with custom modules.

0

app/code/Bensupply/DisplaySupplierNameAdmin/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"></module>

</config>

Bensupply/DisplaySupplierNameAdmin/view/adminhtml/layout/sales_order_view.xml

<?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">Bensupply_DisplaySupplierNameAdmin::items/column/name.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

app/code/Bensupply/DisplaySupplierNameAdmin/view/adminhtml/templates/items/column/name.phtml

<?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>

    <?php if ($block->getOrderOptions()): ?>
        <dl class="item-options">
            <?php foreach ($block->getOrderOptions() as $_option): ?>
                <dt><?php /* @escapeNotVerified */ echo $_option['label'] ?>:</dt>
                <dd>
                    <?php if (isset($_option['custom_view']) && $_option['custom_view']): ?>
                        <?php /* @escapeNotVerified */ echo $block->getCustomizedOptionValue($_option); ?>
                    <?php else: ?>
                        <?php $_option = $block->getFormattedOption($_option['value']); ?>
                        <?php /* @escapeNotVerified */ echo $_option['value']; ?><?php if (isset($_option['remainder']) && $_option['remainder']): ?><span id="<?php /* @escapeNotVerified */ echo $_dots = 'dots' . uniqid()?>"> ...</span><span id="<?php /* @escapeNotVerified */ echo $_id = 'id' . uniqid()?>"><?php /* @escapeNotVerified */ echo $_option['remainder'] ?></span>
                            <script>
                                require(['prototype'], function() {
                                    $('<?php /* @escapeNotVerified */ echo $_id ?>').hide();
                                    $('<?php /* @escapeNotVerified */ echo $_id ?>').up().observe('mouseover', function(){$('<?php /* @escapeNotVerified */ echo $_id ?>').show();});
                                    $('<?php /* @escapeNotVerified */ echo $_id ?>').up().observe('mouseover', function(){$('<?php /* @escapeNotVerified */ echo $_dots?>').hide();});
                                    $('<?php /* @escapeNotVerified */ echo $_id ?>').up().observe('mouseout',  function(){$('<?php /* @escapeNotVerified */ echo $_id ?>').hide();});
                                    $('<?php /* @escapeNotVerified */ echo $_id ?>').up().observe('mouseout',  function(){$('<?php /* @escapeNotVerified */ echo $_dots ?>').show();});
                                });
                            </script>
                        <?php endif; ?>
                    <?php endif; ?>
                </dd>
            <?php endforeach; ?>
        </dl>
    <?php endif; ?>
    <?php echo $block->escapeHtml($_item->getDescription()) ?>
<?php endif; ?>

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.