Something went wrong.
Related Posts:
In this example, the “qty” custom field is added and the sequence of “subtotal” changes as “qty” is placed in the first position.
Here, I have taken the example to change the sequence of custom field before “subtotal” in invoice in Magento 2 backend.
The default Magento 2 offers an invoice template as shown below.
If you have any doubts regarding this post, do mention them in the Comments section below.
Such changes in Magento 2 admin panel for invoice helps admin to get all the required details in invoice totals in the sequence of priority.
That’s all!
Steps to Change the Sequence of Custom Field Before “subtotal” in Invoice in Magento 2 Backend:
- Create registration.php file at appcodeVendorModule directory
use MagentoFrameworkComponentComponentRegistrar;ComponentRegistrar::register(ComponentRegistrar::MODULE, ‘Vendor_Module’, __DIR__);
- Create module.xml file at appcodeVendorModuleetc directory
<?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_Module” setup_version=“1.0.0”/> - Create sales_order_invoice_new.xml file at appcodeVendorModuleviewadminhtmllayout
<?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=“invoice_totals”><block class=“VendorModuleBlockSalesOrderQty” name=“qty”/></referenceBlock></body> - Create Qty.php file at appcodeVendorModuleBlockSalesOrder
namespace VendorModuleBlockSalesOrder;use MagentoFrameworkViewElementTemplateContext;class Qty extends MagentoFrameworkViewElementTemplateprotected $currency;public function __construct(Context $context, Currency $currency, array $data = [])parent::__construct($context, $data);$this->currency = $currency;public function initTotals()if ((integer)$this->getOrder()->getTotalQtyOrdered()) {$value = $this->getOrder()->getTotalQtyOrdered();$this->getParentBlock()->addTotalBefore(new MagentoFrameworkDataObject([‘code’ => ‘qty’,‘strong’ => false,‘label’ => ‘QTY’,‘value’ => $value,]),‘subtotal’);}return $this;public function getOrder()return $this->getParentBlock()->getOrder();
Never miss Magento tips, tricks, tutorials, and news.
Thank you for subscribing.
Using the above code, the QTY field is added to the invoice before subtotal as shown in below image.
Feel free to share the solution with Magento Community via social media.
Thank You.
The admin may want to add custom fields and change the sequence of the existing fields as per the business requirements.
Get Weekly Updates
An invoice is the legal accounting document that shows the transaction details between a merchant and a customer. Businesses need to craft the invoice design meticulously as it represents the brand and contributes to customers’ trust and shopping experience.
The Magento 2 store admin has to generate invoices for orders placed online. The invoice layout in backend must also be such that helps admin manage the order details easily.
I would be happy to help.
/**/
/*.mfp-bg{background:#000000d4}
/*]]>*/
/*.mfp-bg.mfp-ready{opacity:.6}
/*]]>*/