0

I have overridden the core layout and template files using custom theme in Magento 2

And I have my block file at Netenrich\Oms\Block\Adminhtml\Order\View

template file at serge.beraud@alphanova.com.sg.Template has sample text

So I have sales_order_view.xml and i have added this code snippet at the end of sales_order_view.xml

    <referenceContainer name="content">
        <block class="Magento\Sales\Block\Adminhtml\Order\View" name="sales_order_edit"/>
    </referenceContainer>
    <referenceContainer name="left">
        <block class="Magento\Sales\Block\Adminhtml\Order\View\Tabs" name="sales_order_tabs">
            <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Info" name="order_tab_info" template="order/view/tab/info.phtml">
                <block class="Magento\Sales\Block\Adminhtml\Order\View\Messages" name="order_messages"/>
                <block class="Netenrich\Oms\Block\Adminhtml\Order\View\View" name="sales_order_view_custom" template="order/view/custom.phtml" />
                <block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="order/view/info.phtml"/>
                <block class="Magento\Sales\Block\Adminhtml\Order\View\Items" name="order_items" template="order/view/items.phtml">
                    <arguments>
                        <argument name="columns" xsi:type="array">
                            <item name="product" xsi:type="string" translate="true">Product</item>
                            <item name="status" xsi:type="string" translate="true">Item Status</item>
                            <item name="price-original" xsi:type="string" translate="true">Original Price</item>
                            <item name="price" xsi:type="string" translate="true">Price</item>
                            <item name="ordered-qty" xsi:type="string" translate="true">Qty</item>
                            <item name="subtotal" xsi:type="string" translate="true">Subtotal</item>
                            <item name="tax-amount" xsi:type="string" translate="true">Tax Amount</item>
                            <item name="tax-percent" xsi:type="string" translate="true">Tax Percent</item>
                            <item name="discont" xsi:type="string" translate="true">Discount Amount</item>
                            <item name="total" xsi:type="string" translate="true">Row Total</item>
                        </argument>
                    </arguments>
                    <block class="Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer" as="default" template="order/view/items/renderer/default.phtml">
                    <arguments>
                        <argument name="columns" xsi:type="array">
                            <item name="product" xsi:type="string" translate="false">col-product</item>
                            <item name="status" xsi:type="string" translate="false">col-status</item>
                            <item name="price-original" xsi:type="string" translate="false">col-price-original</item>
                            <item name="price" xsi:type="string" translate="false">col-price</item>
                            <item name="qty" xsi:type="string" translate="false">col-ordered-qty</item>
                            <item name="subtotal" xsi:type="string" translate="false">col-subtotal</item>
                            <item name="tax-amount" xsi:type="string" translate="false">col-tax-amount</item>
                            <item name="tax-percent" xsi:type="string" translate="false">col-tax-percent</item>
                            <item name="discont" xsi:type="string" translate="false">col-discont</item>
                            <item name="total" xsi:type="string" translate="false">col-total</item>
                        </argument>
                    </arguments>
                    </block>
                    <block class="Magento\Sales\Block\Adminhtml\Items\Column\Qty" name="column_qty" template="items/column/qty.phtml" group="column"/>
                    <block class="Magento\Sales\Block\Adminhtml\Items\Column\Name" name="column_name" template="items/column/name.phtml" group="column"/>
                    <block class="Magento\Framework\View\Element\Text\ListText" name="order_item_extra_info"/>
                </block>

                <container name="payment_additional_info" htmlTag="div" htmlClass="order-payment-additional" />
                <block class="Magento\Sales\Block\Adminhtml\Order\Payment" name="order_payment"/>
                <block class="Magento\Sales\Block\Adminhtml\Order\View\History" name="order_history" template="order/view/history.phtml"/>
                <block class="Magento\Backend\Block\Template" name="gift_options" template="Magento_Sales::order/giftoptions.phtml">
                    <block class="Magento\Sales\Block\Adminhtml\Order\View\Giftmessage" name="order_giftmessage" template="order/view/giftmessage.phtml"/>
                </block>
                <block class="Magento\Sales\Block\Adminhtml\Order\Totals" name="order_totals" template="order/totals.phtml">
                    <block class="Magento\Sales\Block\Adminhtml\Order\Totals\Tax" name="tax" template="order/totals/tax.phtml"/>
                </block>
            </block>
            <action method="addTab">
                <argument name="name" xsi:type="string">order_info</argument>
                <argument name="block" xsi:type="string">order_tab_info</argument>
            </action>
            <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Invoices" name="sales_order_invoice.grid.container"/>
            <action method="addTab">
                <argument name="name" xsi:type="string">order_invoices</argument>
                <argument name="block" xsi:type="string">sales_order_invoice.grid.container</argument>
            </action>
            <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Creditmemos" name="sales_order_creditmemo.grid.container"/>
            <action method="addTab">
                <argument name="name" xsi:type="string">order_creditmemos</argument>
                <argument name="block" xsi:type="string">sales_order_creditmemo.grid.container</argument>
            </action>
            <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Shipments" name="sales_order_shipment.grid.container"/>
            <action method="addTab">
                <argument name="name" xsi:type="string">order_shipments</argument>
                <argument name="block" xsi:type="string">sales_order_shipment.grid.container</argument>
            </action>
            <action method="addTab">
                <argument name="name" xsi:type="string">order_history</argument>
                <argument name="block" xsi:type="string">Magento\Sales\Block\Adminhtml\Order\View\Tab\History</argument>
            </action>
            <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Transactions" name="sales_transactions.grid.container"/>
            <action method="addTab">
                <argument name="name" xsi:type="string">order_transactions</argument>
                <argument name="block" xsi:type="string">sales_transactions.grid.container</argument>
            </action>
        </block>
    </referenceContainer>
    <referenceBlock name="head.components">
        <block class="Magento\Framework\View\Element\Js\Components" name="sales_page_head_components" template="Magento_Sales::page/js/components.phtml"/>
    </referenceBlock>
    <referenceBlock name="sales_order_invoice.grid.container">
        <uiComponent name="sales_order_view_invoice_grid"/>
    </referenceBlock>
    <referenceBlock name="sales_order_creditmemo.grid.container">
        <uiComponent name="sales_order_view_creditmemo_grid"/>
    </referenceBlock>
    <referenceBlock name="sales_order_shipment.grid.container">
        <uiComponent name="sales_order_view_shipment_grid"/>
    </referenceBlock>

    <referenceBlock name="order_info">
        <block class="Netenrich\Oms\Block\Adminhtml\Order\View\View" name="sales_order_view_custom" template="order/view/custom.phtml" />
    </referenceBlock>


    <referenceContainer name="left">
       <referenceContainer name="payment_additional_info">
        <block class="Netenrich\Oms\Block\Adminhtml\Order\View\Custom" name="sales_order_view_ad" template="Magento_Sales:/order/view/custom.phtml"/>
         </referenceContainer>
    </referenceContainer>

</body>

=> custom.php

namespace Netenrich\Oms\Block\Adminhtml\Order\View;
class View extends \Magento\Backend\Block\Template
{
    //
}

app/design/adminhtml/Netenrich/oms/Magento_Sales/templates/order/view/custom.phtml

<h>hi..hello</>
  • are you overriding or trying to inserting your custom new block? – Bojjaiah Mar 9 '17 at 10:09
  • NO..where we have to create di.xml for what purpose. – vijay b Mar 9 '17 at 10:11
  • are you overriding or trying to inserting your custom new block? – Bojjaiah Mar 9 '17 at 10:12
  • i haved overridden the layout file already and trying to add new custom block to the overridden layout – vijay b Mar 9 '17 at 10:14
  • post your full of code, so that we will update you where you went wrong? – Bojjaiah Mar 9 '17 at 10:16
8

try this

Learning/RewriteSales/Block/Adminhtml/Order/View/Custom.php

<?php
namespace Learning\RewriteSales\Block\Adminhtml\Order\View;
class Custom extends \Magento\Backend\Block\Template
{

}

Learning/RewriteSales/view/adminhtml/layout/sales_order_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>      
        <referenceBlock name="order_additional_info">
            <block class="Learning\RewriteSales\Block\Adminhtml\Order\View\Custom" name="sales_order_view_custom" template="order/view/custom.phtml" />
        </referenceBlock>
    </body>
</page>

Learning/RewriteSales/view/adminhtml/templates/order/view/custom.phtml

<h1>Hi, I am here!</h1>

app/design/adminhtml/Netenrich/oms/Magento_Sales/templates/order/view/info.phtml‌​

<?php echo $block->getChildHtml('sales_order_view_custom') ?>

after completing this try to execute setup:upgrade and setup:static-content:deploy and Open any order.

  • change app/design/adminhtml/Netenrich/oms/Magento_Sales/templates/order/view/custom.phtml into app/design/adminhtml/Netenrich/oms/Magento_Sales/templates/order/view/info.phtml. – vijay b Mar 9 '17 at 11:47
  • Yes I missed it. – Bojjaiah Mar 9 '17 at 12:10
  • how can we get the customer id in our Learning/RewriteSales/Block/Adminhtml/Order/View/Custom.php.If we could get the order id or customer id in this custom.php .we can insert any data of respective customer dynamically – vijay b Mar 9 '17 at 12:15
  • i got the answer .. extend the \Magento\Sales\Block\Adminhtml\Order\View\Info in custom.php.-->class View extends \Magento\Sales\Block\Adminhtml\Order\View\Info..So we can use the core methods from \Magento\Sales\Block\Adminhtml\Order\View\Info which has the methods to get the order details – vijay b Mar 9 '17 at 12:20
  • @vijayb do you want to answer how to get customer detail from custom.php or you got answer from somewhere? – Bojjaiah Mar 9 '17 at 12:42
1

This would be much easier, In sales_order_view.xml

 <referenceBlock name="order_additional_info">
        <block class="Vendor\Module\Block\Adminhtml\Order\View" name="sales_order_custom_view" template="custom_view.phtml" />
 </referenceBlock>

Then create custom_view.phtml and place your custom code there. Your code block will reflect before the Item section block in the admin order view interface.

In info.phtml in core file, already they allocated a section for additional custom blocks,

<?= $block->getChildHtml('order_additional_info') ?>

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.