Всем доброго дня! Пытаюсь создать print на странице. Сделал тело модуля mail в design/backend/template/ addons/sales_reports_mail.tpl
В нем два файла print_reports.tpl и reports.tpl
В модуле func.php прописал так:
<?php
use Tygh\Enum\ProductOptionsApplyOrder;
use Tygh\Enum\SiteArea;
use Tygh\Registry;
if (!defined('BOOTSTRAP')) { die('Access denied'); }
function fn_get_sales_report_templates()
{
$templates = array();
$theme = Themes::areaFactory('C');
$files = $theme->getDirContents(array(
'dir' => 'mail/templates/addons/sales_reports_mail',
'get_dirs' => false,
'get_files' => true,
'extension' => array('.tpl'),
), Themes::STR_MERGE, Themes::PATH_ABSOLUTE, Themes::USE_BASE);
foreach ($files as $file => $file_info) {
$path_parts = explode(".", $file);
$file_name = __($path_parts[0]);
$templates[$file] = !empty($file_name) ? $file_name : ucfirst($path_parts[0]);
}
return $templates;
}
function fn_print_sales_report($report_ids, $params = [], $lang_code = CART_LANGUAGE)
{
// Backward compatibility
if (is_bool($params)) {
// phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
$args = func_get_args();
$params = [];
/**
* Executes when normalizing parameters for invoice printing, allows you to populate additional parameters.
*
* @param array<int, string|bool> $args Function arguments
* @param array<string, string|bool> $params Normalized parameters
*/
fn_set_hook('print_sales_report_normalize_parameters', $args, $params);
// if (isset($args[2])) {
// $params['area'] = $args[2];
// }
// if (isset($args[3])) {
// $params['lang_code'] = $args[3];
// }
}
// Default params
$params = array_merge(
[
'area' => SiteArea::ADMIN_PANEL,
'lang_code' => CART_LANGUAGE,
'html_wrap' => true,
'add_page_break' => true,
],
$params
);
$report_ids = (array) $report_ids;
/**
* Executes before printing order invoices, allows you to modify parameters passed to the function.
*
* @param array<int> $report_ids Order IDs to print invoices for
* @param array<string, string|bool> $params Print parameters
*/
fn_set_hook('print_sales_report_pre', $report_ids, $params);
$view = Tygh::$app['view'];
$html = [];
// $data['order_status_descr'] = fn_get_simple_statuses(STATUSES_ORDER, true, true, $params['lang_code']);
// $data['profile_fields'] = fn_get_profile_fields('I', [], $params['lang_code']);
foreach ($report_ids as $report_id) {
$report_data = fn_get_report_data($report_id);
$templates = fn_get_sales_report_templates();
$report_type = fn_get_parameters($report_id);
if (empty($report_data['template']) || !isset($templates[$report_data['template']])) {
$report_data['template'] = key($templates);
}
if (Registry::get('settings.Appearance.email_templates') === 'old') {
$report_id = !empty($report_data['report_id']) ? $report_data['report_id'] : Registry::get('runtime.report_id');
$view = Tygh::$app['view'];
$view->assign('report_data');
return $view->displayMail('view/sales_reports' . $report_data['template'], false, 'C', $report_id, $lang_code);
} else {
$report = Tygh::$app['template.document.report.type'];
$template_code = isset($params['template_code']) ? $params['template_code'] : 'default';
$result = $report->renderByData($report_data, $template_code, $lang_code);
if (!$result) {
continue;
}
$view->assign('content', $result);
$result = $view->displayMail('common/wrap_document.tpl', false, $params['area'], $params['lang_code']);
$html[] = $result;
}
if (
!$params['add_page_break']
|| $report_id === end($report_ids)
) {
continue;
}
$html[] = "<div style='page-break-before: always;'> </div>";
}
$output = implode(PHP_EOL, $html);
return $output;
}
Контроллер который вызывает эту функцию находится в controllers/backend/sales_reports_print.tpl
В нем прописал:
<?php
use Tygh\Registry;
if (!defined('BOOTSTRAP')) { die('Access denied'); }
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
return [CONTROLLER_STATUS_OK];
}
$params = $_REQUEST;
if ($mode == 'print_reports') {
if (!empty($_REQUEST['report_id'])) {
echo(fn_print_sales_report($_REQUEST['report_id'], $_REQUEST));
}
return[CONTROLLER_STATUS_NO_CONTENT];
}