How to open an invoice pdf in a new tab in the Magento backend?
How to see the preview of the invoice print in a new tab(target _blank) via the Magento invoice grid
I have added the new column "Actual View" in Sales-> Invoice grid in Magento backend like below.
I have customized this column, when you click this Actual view link, it will download the invoice that was sent to the customer.
But I want to open this invoice in a separate browser tab instead of downloading it.
Please refer the below code
sales_order_invoice_grid.xml
<!-- Add the column "custom_column" (Custom Column) to the sales invoice grid. --> <listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="sales_order_invoice_columns">
<actionsColumn name="action" class="Vendorname\InvoiceGridCustomization\Ui\Component\Listing\Column\ViewAction">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="viewUrlPath" xsi:type="string">sales/order_invoice/print</item>
<item name="urlEntityParamName" xsi:type="string">invoice_id</item>
</item>
</argument>
<settings>
<label translate="true">Actual view</label>
<indexField>increment_id</indexField>
</settings>
</actionsColumn>
</columns> </listing>
Vendorname\InvoiceGridCustomization\Ui\Component\Listing\Column\ViewAction.php
<?php
namespace Vendor\Modulename\Ui\Component\Listing\Column;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Ui\Component\Listing\Columns\Column;
/**
* Class ViewAction
*/
class ViewAction extends Column
{
/**f
* @var UrlInterface
*/
protected $urlBuilder;
/**
* Constructor
*
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param UrlInterface $urlBuilder
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
UrlInterface $urlBuilder,
array $components = [],
array $data = []
)
{
$this->urlBuilder = $urlBuilder;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
/**
* Prepare Data Source
*
* @param array $dataSource
* @return array
*/
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
if (isset($item['entity_id'])) {
$viewUrlPath = $this->getData('config/viewUrlPath') ?: '#';
$urlEntityParamName = $this->getData('config/urlEntityParamName') ?: 'entity_id';
$url = $this->urlBuilder->getUrl(
$viewUrlPath,
[
$urlEntityParamName => $item['entity_id']
]
);
$item[$this->getData('name')]['edit'] = [
'href' => $url,
'target' => '_blank',
'label' => __('Print'),
];
}
}
}
return $dataSource;
}
}