Cannot access offset of type string on string
Переписал свою функцию
<?php
use Tygh\Enum\ProductOptionsApplyOrder;
use Tygh\Addons\SalesReport\ServiceProvider;
use Tygh\Enum\SiteArea;
use Tygh\Registry;
use Tygh\Settings;
use Tygh\Tygh;
use Tygh\Themes\Themes;
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/print_reports.tpl' || 'mail/templates/addons/sales_reports_mail/reports.tpl',
'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($reports_ids, $params = [], $lang_code = CART_LANGUAGE) {
if(is_bool($params)) {
$args = func_get_args();
$params = [];
fn_set_hook('print_sales_report_normalize_parameters', $args, $params);
/*if(isset($args[2])) {
$params['area'] = $args[2];
}
if (isset($args[2])) {
$params['lang_code'] = $args[2];
}*/
}
$params = array_merge(
[
'area' => SiteArea::ADMIN_PANEL,
'land_code' => CART_LANGUAGE,
'html_wrap' => true,
'add_page_break' => true,
],
$params
);
$reports_ids = (array) $reports_ids;
fn_set_hook('print_sales_report_pre', $reports_ids, $params);
$view = Tygh::$app['view'];
$html = [];
foreach ($reports_ids as $report_id) {
$report_data = fn_check_elements($report_id, $elements, $time_from, $time_to, $table);
$templates = fn_get_sales_report_templates();
if (empty($report_data['template']) || !isset($templates[$report_data['template']])) {
$report_data['template'] = key($templates);
}
$gcv_data = fn_check_elements($report_data, 'P', $stored_products, $templates);
if (Registry::get('settings.Appearance.email_templates') == 'old') {
$company_id = !empty($report_data['company_id']) ? $report_data['company_id'] : Registry::get('runtime.company_id');
$view = Tygh::$app['view'];
$view->assign('$report_data', $gcv_data);
return $view->displayMail('addons/sales_reports_mail/print_reports.tpl' . $report_data['template'], false, 'C', $company_id, $lang_code);
} else {
$report = Tygh::$app['template.document.report.type'];
$template_code = isset($params['template_code']) ? $params['template_code'] : 'default';
$result = $report->renderByData($gcv_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($reports_ids)
) {
continue;
}
$html[] = "<div style='page-break-before: always;'> </div>";
}
$output = implode(PHP_EOL, $html);
return $output;
}