One such example that I have mentioned here is to add custom message to admin sales order view, invoice, and credit memo in Magento 2.
Thank you for subscribing.
Store admins tend to improve their stores’ admin panel by customizing admin functionalities, adding custom messages, columns, adding filters or removing them in the grid, etc.
For example, you may want to display a custom message when an order contains gift while processing that order from the admin panel.
Steps to Add Custom Message to Admin Sales Order View, Invoice, and Credit Memo in Magento 2
- Create layout files.
- Method to add a custom message to admin sales order view
If you have any doubts, just mention them in the Comments section below.
That’s all!
<?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_info”>
<block class=“VendorModuleBlockAdminhtmlOrderViewcustomMessage” name=“sales_order_view_custom_msg”
template=“order/view/customMessage.phtml”/>
</referenceBlock>
</body>
|
- Method to add a custom message to the invoice
Check out the below solution for implementing such examples in your store:
Create sales_order_creditmemo_view.xml at Vendor/Module/view/adminhtml/layout/
<?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”>
<block class=“VendorModuleBlockAdminhtmlOrderViewcustomMessage” name=“invoice_view_custom_msg”
template=“order/view/customMessage.phtml”/>
</referenceBlock>
</body>
|
- Method to add a custom message to the credit memo
Create sales_order_invoice_view.xml at Vendor/Module/view/adminhtml/layout/
<?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”>
<block class=“VendorModuleBlockAdminhtmlOrderViewcustomMessage” name=“credirmemo_view_custom_msg”
template=“order/view/customMessage.phtml”/>
</referenceBlock>
</body>
|
I would be happy to help.
namespace VendorModuleBlockAdminhtmlOrderView;
class customMessage extends MagentoBackendBlockTemplate
// Here you can fetch order detail if you want to display in order information as an extra detail
|
2. Now, create customMessage.php at Vendor/Module/Block/Adminhtml/Order/View/
<h3>This order contains gift</h3>
|
Create sales_order_view.xml at Vendor/Module/view/adminhtml/layout/
Default Magento 2 provides a user-friendly interface and customization facility for the admin to address their requirements efficiently.
Something went wrong.
Feel free to share the solution with Magento Community via social media.
Never miss Magento tips, tricks, tutorials, and news.
Get Weekly Updates
Thank You.
Magento 2 store admins not only strive to make their store convenient to customers but also continuously implement various tactics to make the store convenient for themselves!
3. Create customMessage.phtml at Vendor/Module/view/adminhtml/templates/order/view
/**/
/*.mfp-bg{background:#000000d4}
/*]]>*/
/*.mfp-bg.mfp-ready{opacity:.6}
/*]]>*/