1

I have created two website and need to override the adminhtml order view phtml only for the second website. Please suggest how can i achieve this.

Please help. Thanks in advance.

<?php
namespace Vendor\OrderCustomiztion\Block\Adminhtml\Order\View;
use Magento\Framework\View\Element\Template;
use Magento\Eav\Model\AttributeDataFactory;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Sales\Model\Order\Address;
class Info extends \Magento\Sales\Block\Adminhtml\Order\View\Info{

/**
     * Customer service
     *
     * @var \Magento\Customer\Api\CustomerMetadataInterface
     */
    protected $metadata;

    /**
     * Group service
     *
     * @var \Magento\Customer\Api\GroupRepositoryInterface
     */
    protected $groupRepository;

    /**
     * Metadata element factory
     *
     * @var \Magento\Customer\Model\Metadata\ElementFactory
     */
    protected $_metadataElementFactory;

    /**
     * @var Address\Renderer
     */
    protected $addressRenderer;
    protected $_storeManager; 

    /**
     * Constructor
     *
     * @param \Magento\Backend\Block\Template\Context $context
     * @param \Magento\Framework\Registry $registry
     * @param \Magento\Sales\Helper\Admin $adminHelper
     * @param \Magento\Customer\Api\GroupRepositoryInterface $groupRepository
     * @param \Magento\Customer\Api\CustomerMetadataInterface $metadata
     * @param \Magento\Customer\Model\Metadata\ElementFactory $elementFactory
     * @param \Magento\Sales\Model\Order\Address\Renderer $addressRenderer
     * @param array $data
     */
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Sales\Helper\Admin $adminHelper,
        \Magento\Customer\Api\GroupRepositoryInterface $groupRepository,
        \Magento\Customer\Api\CustomerMetadataInterface $metadata,
        \Magento\Customer\Model\Metadata\ElementFactory $elementFactory,
        \Magento\Sales\Model\Order\Address\Renderer $addressRenderer,
            \Magento\Store\Model\StoreManagerInterface $storeManager,
        array $data = []
    ) {
        $this->groupRepository = $groupRepository;
        $this->metadata = $metadata;
        $this->_metadataElementFactory = $elementFactory;
        $this->addressRenderer = $addressRenderer;
         $this->_storeManager = $storeManager; 
        parent::__construct($context,$registry,$adminHelper,$groupRepository,$metadata,$elementFactory,$addressRenderer);
        $code= $this->_storeManager->getStore()->getCode();
        if($code == "columbus_app_store_view"){
              $this->setTemplate('Amos_OrderCustomiztion::Info.phtml');
              echo '<pre>';print_r("hie");die();
        }
        else{
           echo '<pre>';print_r("hie2");die(); 
        }
    }
}
1
  • Create new module

  • Create a file at Vendor\Module\view\adminhtml\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>
        <referenceBlock name="order_info">
            <action method="setTemplate">
               <argument name="template" xsi:type="string">Vendor_Module::order/view/info.phtml</argument>
           </action>
       </referenceBlock>
    </body>
    

  • Just copy vendor\magento\module-sales\view\adminhtml\templates\order\view\info.phtml to Vendor\Module\view\adminhtml\templates\order\view\info.phtml

  • You need to override Magento\Sales\Block\Adminhtml\Order\View\Info for get the current website id.

  • Now you can place condition according to your need in our info.phtml file

1

If you have a block php file defined for that template, You can set template in block file.

protected function _construct()
{
    parent::_construct();

    if(website1)
        $this->setTemplate('Vendor_Module::tpl1.phtml');
    else if(website2)
        $this->setTemplate('Vendor_Module::tpl2.phtml');
}
  • Yash shah- Its not working. Please see my updated code. – Flying Finner Apr 26 '19 at 5:33
  • I think you have placed setTemplate in __construct instead of _construct ... That may be the issue .. try to place that code in _construct function. Let me know if it still doesnt work. – Yash Shah Apr 26 '19 at 5:40

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.