I override the classes ‘Pdfcreditmemos.php’ and ‘PrintAction.php’ to change the name of pdf Credit memos , but this is not working, it still works with origin classes, thanks for you help.
MagentoSalesControllerAdminhtmlCreditmemoAbstractCreditmemoPdfcreditmemos
MagentoSalesControllerAdminhtmlCreditmemoAbstractCreditmemoPrintAction
*************di.xml
<preference for="MagentoSalesControllerAdminhtmlCreditmemoAbstractCreditmemoPdfcreditmemos" type="LcdrInvoicePdfControllerAdminhtmlCreditmemoAbstractCreditmemoPdfcreditmemos"/>
<preference for="MagentoSalesControllerAdminhtmlCreditmemoAbstractCreditmemoPrintAction" type="LcdrInvoicePdfControllerAdminhtmlCreditmemoAbstractCreditmemoPrintAction"/>
Pdfcreditmemos.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace LcdrInvoicePdfControllerAdminhtmlCreditmemoAbstractCreditmemo;
use MagentoFrameworkAppResponseInterface;
use MagentoFrameworkAppFilesystemDirectoryList;
use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;
/**
* Class Pdfcreditmemos
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Pdfcreditmemos extends MagentoSalesControllerAdminhtmlCreditmemoAbstractCreditmemoPdfcreditmemos
{
public function massAction(AbstractCollection $collection)
{
$pdf = $this->pdfCreditmemo->getPdf($collection);
$fileContent = ['type' => 'string', 'value' => $pdf->render(), 'rm' => true];
return $this->fileFactory->create(
sprintf('creditmemoaaaaaaaa%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')),
$fileContent,
DirectoryList::VAR_DIR,
'application/pdf'
);
}
}
PrintAction.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace LcdrInvoicePdfControllerAdminhtmlCreditmemoAbstractCreditmemo;
use MagentoFrameworkAppFilesystemDirectoryList;
class PrintAction extends MagentoSalesControllerAdminhtmlCreditmemoAbstractCreditmemoPrintAction
{
public function execute()
{
/** @see MagentoSalesControllerAdminhtmlOrderInvoice */
$creditmemoId = $this->getRequest()->getParam('creditmemo_id');
if ($creditmemoId) {
$creditmemo = $this->creditmemoRepository->get($creditmemoId);
if ($creditmemo) {
$pdf = $this->_objectManager->create(
MagentoSalesModelOrderPdfCreditmemo::class
)->getPdf(
[$creditmemo]
);
$date = $this->_objectManager->get(
MagentoFrameworkStdlibDateTimeDateTime::class
)->date('Y-m-d_H-i-s');
$fileContent = ['type' => 'string', 'value' => $pdf->render(), 'rm' => true];
return $this->_fileFactory->create(
'creditmemokkkkkkkkk' . $date . '.pdf',
$fileContent,
DirectoryList::VAR_DIR,
'application/pdf'
);
}
} else {
$resultForward = $this->resultForwardFactory->create();
$resultForward->forward('noroute');
return $resultForward;
}
}
}