Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento 2更改pdf文件名_Pdf_Filenames_Magento2 - Fatal编程技术网

Magento 2更改pdf文件名

Magento 2更改pdf文件名,pdf,filenames,magento2,Pdf,Filenames,Magento2,我想更改Magento 2中PDF文件的文件名 默认名称不清楚,我希望发票保存到电脑上的某个位置时可以搜索 是否可以将Magento 2中PDF文件的文件名更改为类似invoice_1000000123.PDF的格式?是的,可以更改invoice PDF文件名 请转到以下路径: /vendor/magento/module-sales/Controller/Adminhtml/Invoice/AbstractInvoice/PrintAction.php 您可以更改上述文件的文件名。您不应该编

我想更改Magento 2中PDF文件的文件名

默认名称不清楚,我希望发票保存到电脑上的某个位置时可以搜索


是否可以将Magento 2中PDF文件的文件名更改为类似invoice_1000000123.PDF的格式?

是的,可以更改invoice PDF文件名

请转到以下路径:

/vendor/magento/module-sales/Controller/Adminhtml/Invoice/AbstractInvoice/PrintAction.php
您可以更改上述文件的文件名。

您不应该编辑核心文件。说真的,不要

由于/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>
插件的外观如下所示:

<type name="Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\PrintAction">
    <plugin name="Vendor_Module::aroundPrintInvoice" type="Vendor\Module\Block\Class" sortOrder="0"/>
</type>

您需要覆盖发票管理控制器

<?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\Order\Invoice" 
      type="Vendor\Module\Controller\Adminhtml\Order\Invoice" />
</config>
在自定义模块管理控制器中,您需要更改Pdf文件的名称

public function execute() 
{
  $invoiceId = $this->getRequest()->getParam('invoice_id');
  return $this->_fileFactory->create(
                    'invoice_13012020' . $invoiceId . '.pdf', //<== Change the pdf name here.
                    $pdf->render(),
                    DirectoryList::VAR_DIR,
                    'application/pdf'
                );
        ...
    }
<?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\Order\Invoice" 
      type="Vendor\Module\Controller\Adminhtml\Order\Invoice" />
</config>
public function execute() 
{
  $invoiceId = $this->getRequest()->getParam('invoice_id');
  return $this->_fileFactory->create(
                    'invoice_13012020' . $invoiceId . '.pdf', //<== Change the pdf name here.
                    $pdf->render(),
                    DirectoryList::VAR_DIR,
                    'application/pdf'
                );
        ...
    }