本文整理汇总了PHP中Magento\Framework\App\Response\Http\FileFactory::create方法的典型用法代码示例。如果您正苦于以下问题:PHP FileFactory::create方法的具体用法?PHP FileFactory::create怎么用?PHP FileFactory::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\App\Response\Http\FileFactory
的用法示例。
在下文中一共展示了FileFactory::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Export shipment grid to CSV format
*
* @return ResponseInterface
*/
public function execute()
{
$resultPage = $this->resultPageFactory->create();
$fileName = 'authors.csv';
/** @var \Sample\News\Block\Adminhtml\Author\Grid $grid */
$grid = $resultPage->getLayout()->getChildBlock('sample_news.author.grid', 'grid.export');
return $this->fileFactory->create($fileName, $grid->getCsvFile(), DirectoryList::VAR_DIR);
}
示例2: execute
/**
* Export credit memo grid to Excel XML format
*
* @return ResponseInterface
*/
public function execute()
{
$this->_view->loadLayout(false);
$fileName = 'creditmemos.xml';
$grid = $this->_view->getLayout()->getChildBlock('sales.creditmemo.grid', 'grid.export');
return $this->_fileFactory->create($fileName, $grid->getExcelFile($fileName), \Magento\Framework\App\Filesystem::VAR_DIR);
}
示例3: execute
/**
* Export invoice grid to CSV format
*
* @return ResponseInterface
*/
public function execute()
{
$fileName = 'invoices.csv';
/** @var \Magento\Backend\Block\Widget\Grid\ExportInterface $exportBlock */
$exportBlock = $this->resultLayoutFactory->create()->getLayout()->getChildBlock('sales.invoice.grid', 'grid.export');
return $this->_fileFactory->create($fileName, $exportBlock->getCsvFile(), DirectoryList::VAR_DIR);
}
示例4: execute
/**
* Custom options download action
*
* @return \Magento\Framework\Controller\Result\Forward
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExitExpression)
*/
public function execute()
{
$option = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item\\Option')->load($this->getRequest()->getParam('id'));
/** @var \Magento\Framework\Controller\Result\Forward $resultForward */
$resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD);
if (!$option->getId()) {
$resultForward->forward('noroute');
return $resultForward;
}
$optionId = null;
if (strpos($option->getCode(), \Magento\Catalog\Model\Product\Type\AbstractType::OPTION_PREFIX) === 0) {
$optionId = str_replace(\Magento\Catalog\Model\Product\Type\AbstractType::OPTION_PREFIX, '', $option->getCode());
if ((int) $optionId != $optionId) {
$resultForward->forward('noroute');
return $resultForward;
}
}
$productOption = $this->_objectManager->create('Magento\\Catalog\\Model\\Product\\Option')->load($optionId);
if (!$productOption || !$productOption->getId() || $productOption->getProductId() != $option->getProductId() || $productOption->getType() != 'file') {
$resultForward->forward('noroute');
return $resultForward;
}
try {
$info = unserialize($option->getValue());
$secretKey = $this->getRequest()->getParam('key');
if ($secretKey == $info['secret_key']) {
$this->_fileResponseFactory->create($info['title'], ['value' => $info['quote_path'], 'type' => 'filename'], DirectoryList::ROOT);
}
} catch (\Exception $e) {
$resultForward->forward('noroute');
return $resultForward;
}
}
示例5: execute
/**
* Export shipment grid to CSV format
*
* @return ResponseInterface
*/
public function execute()
{
$this->_view->loadLayout(false);
$fileName = 'shipments.csv';
$grid = $this->_view->getLayout()->getChildBlock('sales.shipment.grid', 'grid.export');
return $this->_fileFactory->create($fileName, $grid->getCsvFile(), \Magento\Framework\App\Filesystem::VAR_DIR);
}
示例6: massAction
/**
* Print invoices for selected orders
*
* @param AbstractCollection $collection
* @return ResponseInterface|\Magento\Backend\Model\View\Result\Redirect
*/
protected function massAction(AbstractCollection $collection)
{
$resultRedirect = $this->resultRedirectFactory->create();
$flag = false;
/** @var \Magento\Sales\Model\Order $order */
foreach ($collection->getItems() as $order) {
$invoices = $order->getInvoiceCollection();
if ($invoices->getSize() > 0) {
$flag = true;
if (!isset($pdf)) {
$pdf = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Pdf\\Invoice')->getPdf($invoices);
} else {
$pages = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Pdf\\Invoice')->getPdf($invoices);
$pdf->pages = array_merge($pdf->pages, $pages->pages);
}
}
}
if ($flag) {
$date = $this->_objectManager->get('Magento\\Framework\\Stdlib\\DateTime\\DateTime')->date('Y-m-d_H-i-s');
return $this->fileFactory->create('invoice' . $date . '.pdf', $pdf->render(), DirectoryList::VAR_DIR, 'application/pdf');
} else {
$this->messageManager->addError(__('There are no printable documents related to selected orders.'));
$resultRedirect->setPath('sales/*/');
return $resultRedirect;
}
}
示例7: executeInternal
/**
* @return ResponseInterface|\Magento\Backend\Model\View\Result\Forward
*/
public function executeInternal()
{
/** @see \Magento\Sales\Controller\Adminhtml\Order\Invoice */
$creditmemoId = $this->getRequest()->getParam('creditmemo_id');
if ($creditmemoId) {
$creditmemo = $this->creditmemoRepository->get($creditmemoId);
if ($creditmemo) {
$pdf = $this->_objectManager->create(
'Magento\Sales\Model\Order\Pdf\Creditmemo'
)->getPdf(
[$creditmemo]
);
$date = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\DateTime')->date('Y-m-d_H-i-s');
return $this->_fileFactory->create(
'creditmemo' . $date . '.pdf',
$pdf->render(),
DirectoryList::VAR_DIR,
'application/pdf'
);
}
} else {
$resultForward = $this->resultForwardFactory->create();
$resultForward->forward('noroute');
return $resultForward;
}
}
示例8: executeInternal
/**
* @return ResponseInterface|\Magento\Backend\Model\View\Result\Forward
*/
public function executeInternal()
{
$shipmentId = $this->getRequest()->getParam('shipment_id');
if ($shipmentId) {
$shipment = $this->_objectManager->create('Magento\Sales\Model\Order\Shipment')->load($shipmentId);
if ($shipment) {
$pdf = $this->_objectManager->create(
'Magento\Sales\Model\Order\Pdf\Shipment'
)->getPdf(
[$shipment]
);
$date = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\DateTime')->date('Y-m-d_H-i-s');
return $this->_fileFactory->create(
'packingslip' . $date . '.pdf',
$pdf->render(),
DirectoryList::VAR_DIR,
'application/pdf'
);
}
} else {
/** @var \Magento\Backend\Model\View\Result\Forward $resultForward */
$resultForward = $this->resultForwardFactory->create();
return $resultForward->forward('noroute');
}
}
示例9: execute
/**
* Print label for one specific shipment
*
* @return ResponseInterface|void
*/
public function execute()
{
try {
$this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
$this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
$this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment'));
$this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking'));
$shipment = $this->shipmentLoader->load();
$labelContent = $shipment->getShippingLabel();
if ($labelContent) {
$pdfContent = null;
if (stripos($labelContent, '%PDF-') !== false) {
$pdfContent = $labelContent;
} else {
$pdf = new \Zend_Pdf();
$page = $this->labelGenerator->createPdfPageFromImageString($labelContent);
if (!$page) {
$this->messageManager->addError(__('We don\'t recognize or support the file extension in this shipment: %1.', $shipment->getIncrementId()));
}
$pdf->pages[] = $page;
$pdfContent = $pdf->render();
}
return $this->_fileFactory->create('ShippingLabel(' . $shipment->getIncrementId() . ').pdf', $pdfContent, DirectoryList::VAR_DIR, 'application/pdf');
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
$this->messageManager->addError(__('An error occurred while creating shipping label.'));
}
$this->_redirect('adminhtml/order_shipment/view', ['shipment_id' => $this->getRequest()->getParam('shipment_id')]);
}
示例10: executeInternal
/**
* Create pdf document with information about packages
*
* @return ResponseInterface|void
*/
public function executeInternal()
{
$this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
$this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
$this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment'));
$this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking'));
$shipment = $this->shipmentLoader->load();
if ($shipment) {
/** @var \Zend_Pdf $pdf */
$pdf = $this->_objectManager->create('Magento\Shipping\Model\Order\Pdf\Packaging')->getPdf($shipment);
return $this->_fileFactory->create(
'packingslip' . $this->_objectManager->get(
'Magento\Framework\Stdlib\DateTime\DateTime'
)->date(
'Y-m-d_H-i-s'
) . '.pdf',
$pdf->render(),
DirectoryList::VAR_DIR,
'application/pdf'
);
} else {
$this->_forward('noroute');
}
}
示例11: execute
/**
* Custom options download action
*
* @return void
*/
public function execute()
{
$option = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item\\Option')->load($this->getRequest()->getParam('id'));
if (!$option->getId()) {
return $this->_forward('noroute');
}
$optionId = null;
if (strpos($option->getCode(), \Magento\Catalog\Model\Product\Type\AbstractType::OPTION_PREFIX) === 0) {
$optionId = str_replace(\Magento\Catalog\Model\Product\Type\AbstractType::OPTION_PREFIX, '', $option->getCode());
if ((int) $optionId != $optionId) {
return $this->_forward('noroute');
}
}
$productOption = $this->_objectManager->create('Magento\\Catalog\\Model\\Product\\Option')->load($optionId);
if (!$productOption || !$productOption->getId() || $productOption->getProductId() != $option->getProductId() || $productOption->getType() != 'file') {
return $this->_forward('noroute');
}
try {
$info = unserialize($option->getValue());
$filePath = $this->_objectManager->get('Magento\\Framework\\App\\Filesystem')->getPath(\Magento\Framework\App\Filesystem::ROOT_DIR) . $info['quote_path'];
$secretKey = $this->getRequest()->getParam('key');
if ($secretKey == $info['secret_key']) {
$this->_fileResponseFactory->create($info['title'], array('value' => $filePath, 'type' => 'filename'), \Magento\Framework\App\Filesystem::ROOT_DIR);
}
} catch (\Exception $e) {
$this->_forward('noroute');
}
exit(0);
}
示例12: execute
/**
* Export search report to Excel XML format
*
* @return \Magento\Framework\App\ResponseInterface
*/
public function execute()
{
/** @var \Magento\Framework\View\Result\Layout $resultLayout */
$resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT);
$content = $resultLayout->getLayout()->getChildBlock('adminhtml.report.search.grid', 'grid.export');
return $this->fileFactory->create('search.xml', $content->getExcelFile(), DirectoryList::VAR_DIR);
}
示例13: testCreate
public function testCreate()
{
$authStorageMock = $this->getMock('Magento\\Backend\\Model\\Auth\\Session', array('isFirstPageAfterLogin', 'processLogout', 'processLogin'), array(), '', false);
$this->_authMock->expects($this->once())->method('getAuthStorage')->will($this->returnValue($authStorageMock));
$authStorageMock->expects($this->once())->method('isFirstPageAfterLogin')->will($this->returnValue(true));
$this->_sessionMock->expects($this->once())->method('setIsUrlNotice');
$this->_model->create('fileName', null);
}
示例14: execute
/**
* Export customer grid to CSV format
*
* @return \Magento\Framework\App\ResponseInterface
*/
public function execute()
{
$this->_view->loadLayout();
$fileName = 'customers.csv';
/** @var \Magento\Backend\Block\Widget\Grid\ExportInterface $exportBlock */
$exportBlock = $this->_view->getLayout()->getChildBlock('admin.block.customer.grid', 'grid.export');
return $this->_fileFactory->create($fileName, $exportBlock->getCsvFile(), DirectoryList::VAR_DIR);
}
示例15: execute
/**
* Export credit memo grid to Excel XML format
*
* @return ResponseInterface
*/
public function execute()
{
$fileName = 'creditmemos.xml';
$resultLayout = $this->resultLayoutFactory->create();
$grid = $resultLayout->getLayout()->getChildBlock('sales.creditmemo.grid', 'grid.export');
$excelFile = $grid->getExcelFile($fileName);
return $this->_fileFactory->create($fileName, $excelFile, DirectoryList::VAR_DIR);
}