4

I have created a custom module in magento 2 and its layout file is located in

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

but the system loads the layout from

vendor/magento/module-sales/view/adminhtml/layout/sales_order_view.xml 

instead of my custom layout file.

How can i override this vendor layout file with my custom layout file?

the complete code of sales_order_view.xml file is

<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="order_info"> <action method="setTemplate"> <argument name="template" translate="true" xsi:type="string">Learning_RewriteSales::order/view/info.phtml</argument> </action> </referenceBlock> <referenceBlock name="order_info"> <block class="Learning\RewriteSales\Block\Adminhtml\Order\View\Custom" name="sales_order_view_custom" template="order/view/custom.phtml" /> </referenceBlock> <referenceBlock name="order_item"> <action method="setTemplate"> <argument name="template" translate="true" xsi:type="string">Learning_RewriteSales::order/view/items.phtml</argument> </action> <arguments> <argument name="columns" xsi:type="array"> <item name="product" xsi:type="string" translate="true">Producthhhh</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> <item name="image" xsi:type="string" translate="true">Image</item> </argument> </arguments> </referenceBlock> <referenceBlock name="order_item"> <block class="Learning\RewriteSales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer" name="sales_order_view_items_renderer_defaultrenderer" 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> <item name="image" xsi:type="string" translate="false">col-image</item> </argument> </arguments> </referenceBlock> </body> 

but the module does not take this layout.

1
  • Add your complete code of RewriteSales module. Commented Oct 13, 2016 at 8:24

2 Answers 2

10

inside module.xml file, you have to declare dependency of core module,

<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Vendor_Modulename" setup_version="1.0.0" active="true"> <sequence> <module name="Magento_Sales"/> </sequence> </module> </config> 

You have override your xml file at right place,

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

Inside your file, you have to just keep only required code to work your custom layout file inside body tag of xml file.

Demo for set different template file,

<?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="column_name"> <action method="setTemplate"> <argument name="template" xsi:type="string">Vendor_Modulename::mycustomfile.phtml</argument> </action> </referenceBlock> </body> </page> 

You have to first check if any log error are generated for this layout.

You have to just clear cache and remove var folder.

4
  • no log error was generated Commented Oct 13, 2016 at 9:38
  • the layout is taken from vendor/magento/module-sales/view/adminhtml/layout/sales_order_view.xml Commented Oct 13, 2016 at 9:39
  • i have updated my answer. please check Commented Oct 18, 2016 at 12:47
  • @RakeshJesadiya - can you plz check this question - magento.stackexchange.com/questions/191243/… Commented Aug 31, 2017 at 5:34
5

if you are overriding layout xml of any core module you should mention sequence in module.xml like this :

<module name="vendorname_modulename" setup_version="1.0.0"> <sequence> <module name="Magento_Sales"/> </sequence> </module> 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.