3

I have used a plugin to add new template at end of the page in Order view page in admin but the issue is I cannot see it at end of the page, instead, it is showing inside Address Information, Please find below code of plugin I have used:

   <type name="Magento\Sales\Block\Adminhtml\Order\View\Info">
            <plugin name="commercepundit_dealerregistration-show_order_histiry" 
type="Commercepundit\Dealerregistration\Plugin\Block\Adminhtml\SalesOrderViewInfo" 
sortOrder="99999" />
        </type>

It's showing like following right now: order view admin

code of Plugin:

<?php
namespace Commercepundit\Dealerregistration\Plugin\Block\Adminhtml;

class SalesOrderViewInfo
{
    /**
     * @param \Magento\Sales\Block\Adminhtml\Order\View\Info $subject
     * @param string $result
     * @return string
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function afterToHtml(
        \Magento\Sales\Block\Adminhtml\Order\View\Info $subject,
        $result
    ) {
        $commentBlock = $subject->getLayout()->getBlock('order_status_history');
        if ($commentBlock !== false && $subject->getNameInLayout() == 'order_info') {
            $commentBlock->setOrder($subject->getOrder());
            $result = $result . $commentBlock->toHtml();
        }

        return $result;
    }
}
  • 1
    sortOrder tag does not sorting html content position – Amit Bera Sep 14 '18 at 8:27
  • 1
    Please share code of ommercepundit\Dealerregistration\Plugin\Block\Adminhtml\SalesOrderViewInfo – Amit Bera Sep 14 '18 at 8:27
  • added plugin code, please check – bhargav shastri Sep 14 '18 at 9:02
1

As you want to add template below order section then You have to changes plugin class.

Magento\Sales\Block\Adminhtml\Order\View\Tab\Info

from Magento\Sales\Block\Adminhtml\Order\View\Info.

You have to create plugin on class Magento\Sales\Block\Adminhtml\Order\View\Tab\Info.

You have to changes

subject->getNameInLayout() == 'order_info'

to

subject->getNameInLayout() == 'order_tab_info'

<block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Info" name="order_tab_info" template="Magento_Sales::order/view/tab/info.phtml">

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">
    <type name="Magento\Sales\Block\Adminhtml\Order\View\Tab\Info">
        <plugin name="commercepundit_dealerregistration-show_order_histiry" 
                    type="Commercepundit\Dealerregistration\Plugin\Block\Adminhtml\SalesOrderViewInfo" 
                    sortOrder="99999" />
    </type>
</config>

PLugin Class

<?php

namespace Commercepundit\Dealerregistration\Plugin\Block\Adminhtml;


class SalesOrderViewInfo {

    public function afterToHtml(
    \Magento\Sales\Block\Adminhtml\Order\View\Tab\Info $subject, $result
    ) {
        $commentBlock = $subject->getLayout()->getBlock('order_status_history');
        if ($commentBlock !== false && $subject->getNameInLayout() == 'order_info') {
            $commentBlock->setOrder($subject->getOrder());
            $result = $result . $commentBlock->toHtml();
        }

        //return $result.'testtest';
    return $result;
    }
}   
  • this is code i have used in sales_order_view.xml <block class="Magento\Backend\Block\Template" name="order_status_history" template="Commercepundit_Dealerregistration::order/view/statushistory.phtml" /> – bhargav shastri Sep 14 '18 at 9:21
  • I have tried by changing to order_tab_info, now my template is not showing anywhere – bhargav shastri Sep 14 '18 at 9:22
  • did you understand where you did the mistake ? You have the issue at condition – Amit Bera Sep 14 '18 at 9:22
  • i have tried whatever you said but i cannot see my template in page by subject->getNameInLayout() == 'order_tab_info' – bhargav shastri Sep 14 '18 at 9:27
  • Okay.let me check – Amit Bera Sep 14 '18 at 9:31
0

I finally changed behaviour of info.phtml file for order view i have override it with my module xml and changed order of order history and order totals section and my purpose was solved.

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.