3

I add phtml in frontend sales order view page. frontend/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\Order\View">
        <plugin name="sales-order-view-seller" type="Companyname\Modulename\Plugin\Block\Order\View" />
  </type>
</config>

View.php

<?php

namespace Companyname\Modulename\Plugin\Block\Order;

class View extends \Magento\Framework\View\Element\Template {

    public function beforeToHtml(\Magento\Sales\Block\Order\View $originalBlock) {

        $originalBlock->setTemplate('Companyname_Modulename::seller_review_view.phtml');
    }
}

Code is working but phtml content showing two times. Any Thing wrong ?

1 Answer 1

3

You can add your custom phtml in order view page like this

[Namespace]\[Modulename]\view\frontend\layout\sales_order_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>
    <referenceContainer name="content">
        <block class="[Namespace]\[Modulename]\Block\Comment" template="[Namespace]_[Modulename]::view.phtml"></block>
    </referenceContainer>
</body>
</page>

[Namespace]\[Modulename]\Block\Comment.php

<?php

namespace [Namespace]\[Modulename]\Block;
   class Comment extends \Magento\Framework\View\Element\Template
   {
     public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
         array $data = []
     ) {
     parent::__construct($context, $data);
   }

   ----Your Block Method----
}

[Namespace]\[Modulename]\view\frontend\templates\view.phtml

<?php echo "Hii"?>

If you don't want to make your custom block than in xml write block class Magento\Framework\View\Element\Template

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.