pdf - Magento 2更改pdf文件名
问题描述
我想更改 Magento 2 中 PDF 文件的文件名。
默认名称不清楚,我希望发票在保存到我的电脑上的某个位置时可以搜索。
是否可以将 Magento 2 中 PDF 文件的文件名更改为“invoice_1000000123.pdf”之类的格式?
解决方案
你永远不应该编辑核心文件。说真的,不要。
由于/vendor/magento/module-sales/Controller/Adminhtml/Invoice/AbstractInvoice/PrintAction.php
是一个抽象类,您必须在模块中使用插件或首选项才能覆盖它。
你需要做到这一点:
通常的最小文件:
/Vendor/Module/composer.json
, /Vendor/Module/registration.php
,/Vendor/Module/etc/module.xml
在/Vendor/Module/etc/module.xml
你应该排序 Magento_Sales
<?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">
<sequence>
<module name="Magento_Sales"/>
</sequence>
</module>
</config>
然后您可以使用插件或首选项/Vendor/Module/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\PrintAction" type="Vendor\Module\Controller\Adminhtml\Invoice\AbstractInvoice\PrintAction"/>
</config>
插件看起来像这样:
<type name="Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\PrintAction">
<plugin name="Vendor_Module::aroundPrintInvoice" type="Vendor\Module\Block\Class" sortOrder="0"/>
</type>
现在将 a 添加PrintAction.php
到您的首选项/插件中指定的路径(首选项示例)
<?php
namespace Vendor\Module\Controller\Adminhtml\Invoice\AbstractInvoice;
class PrintAction extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\PrintAction
{
/* Write code here */
}
推荐阅读
- javascript - 模块 C://.. 没有“firebaseObservable”导出成员错误
- ios - 当用户点击滚动视图停止滚动时,点击手势识别器被触发
- javascript - Node.js 不会在 /bin 中创建 NPM 文件夹
- sql - 选择黑斑羚最近两个月的数据
- octave - OCTAVE 置换熵
- sql - 在 Postgres 中使用自引用更新表会更新比预期更多的条目
- mongodb - 无法使用 docker stack 连接到 mongo-express
- python - Colobar 散点图
- c# - 如何获取传递给构造函数的对象的 ObjectCreationExpressionSyntax?
- javascript - contacts.map 不是函数