当前位置: 技术文章>> Magento 2: 如何在订单中增加新字段

文章标题:Magento 2: 如何在订单中增加新字段
  • 文章分类: Magento
  • 21967 阅读
系统学习magento二次开发,推荐小册:《Magento中文全栈二次开发 》

本小册面向Magento2以上版本,书代码及示例兼容magento2.0-2.4版本。涵盖了magento前端开发,后端开发,magento2主题,magento2重写,magento2 layout,magento2控制器,magento2 block等相关内容,带领您成为magento开发技术专家。


在Magento 2中订单PDF中的订单总块添加新字段的步骤:

让我们举个例子,我添加了ABC TAX。

步骤 1:移动到以下路径

app\code\Vendor\Extension\etc\pdf.xml

现在添加代码,如下所示

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/pdf_file.xsd">
  <totals>
    <total name="abc">
      <title translate="true">ABC TAX</title>
      <source_field>abc_tax</source_field> // it’s Your Database Field Name
      <display_zero>false</display_zero> // If your column has 0 Value then it will not display in Frontend
      <sort_order>550</sort_order> // it will decide where you want to display your field in total block , for e.g after sub total, before grand total etc.
 <font_size>7</font_size> // to give font size.
    <model>Class_Name</model> // to customize the value you can use model class.
    </total>
   <amount_prefix>hello</amount_prefix> // you cann add profiex before amount
  </totals>
</config>

不过,如果你想了解更多的理解和定制,你需要了解Magento核心文件。这是路径,

vendor\Magento\Sales\Model\Order\Pdf\Config\Converter.php

要查看更多标签,您需要查看以下文件

vendor\magento\module-sales\etc\pdf_files.xsd

结论:

因此,通过这种方式,您可以在Magento 2中的订单PDF中的订单总块处添加新字段。


推荐文章