1

I am trying to override vendor/magento/module-sales/view/adminhtml/templates/items/column/name.phtml to add some custom value under sku. I created a module (it is installed properly). In this I have created sales_order_invoice_view.xml at app/code/Custom/Sales/view/adminhtml/layout/sales_order_invoice_view.xml. In this I wrote:

 <?xml version="1.0"?>
 <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
 <body>
    <referenceContainer name="left">            
        <referenceBlock name="invoice_items">
            <block class="Custom\Sales\Block\Adminhtml\Items\Column\Name\Seller" name="column_name" template="Custom_Sales::items/column/name.phtml" group="column"/>
        </referenceBlock>
    </referenceContainer>
   </body>
</page>

Next I created app/code/Custom/Sales/view/adminhtml/templates/items/column/name.phtml. In this I just copied code from original file and added a text like:

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

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

<!-- My Custom text here -->
CUSTOM TEXT: asdfasdf;
<!-- end -->
</div>

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

Please Some one tell me what mistake I have done here ?

  • What errors exactly appeared ? – Jsparo30 Feb 20 '18 at 8:39
  • Did you try module <module name="Magento_Sales"/> in di.xml – Jsparo30 Feb 20 '18 at 8:44
  • i am not getting any error. but my custom code is not getting displayed there. I have added.<module name="Magento_Sales"/> in module.xml. do i need to add it in di.xml?? – Priti Rathee Feb 20 '18 at 9:08
  • also if i add <block class="Magento\Sales\Block\Adminhtml\Items\Column\Name" name="column_name" template="Custom_Sales::items/column/name.phtml" group="column"/> in core sales_order_view.xml. it shows my custom code.exactly how i need – Priti Rathee Feb 20 '18 at 9:11
  • It worked after cleaning cache. – Priti Rathee Mar 5 '18 at 10:32
1

Try following way:

Custom/Sales/view/adminhtml/layout/sales_order_invoice_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="column_name">
            <action method="setTemplate">
                <argument name="template" translate="true" xsi:type="string">Custom_Sales::items/column/name.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

Copy original file into following location:

Custom/Sales/view/adminhtml/templates/items/column/name.phtml
| 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.