|
@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\Product;
|
|
use App\Models\Product;
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
class ExportController extends Controller
|
|
class ExportController extends Controller
|
|
|
{
|
|
{
|
|
@@ -11,15 +12,17 @@ class ExportController extends Controller
|
|
|
$ids = json_decode($request->ids,true);
|
|
$ids = json_decode($request->ids,true);
|
|
|
$products = Product::query()->whereIn('id', $ids)->orderBy('series', 'asc')->get();
|
|
$products = Product::query()->whereIn('id', $ids)->orderBy('series', 'asc')->get();
|
|
|
|
|
|
|
|
- $my_template = new \PhpOffice\PhpWord\TemplateProcessor(storage_path('template_maf.docx'));
|
|
|
|
|
|
|
+ $my_template = new \PhpOffice\PhpWord\TemplateProcessor(storage_path('templates/template_maf.docx'));
|
|
|
|
|
|
|
|
$vars_for_template = [];
|
|
$vars_for_template = [];
|
|
|
$i = 1;
|
|
$i = 1;
|
|
|
foreach ($products as $product){
|
|
foreach ($products as $product){
|
|
|
$vars_for_template = array_merge($vars_for_template, [
|
|
$vars_for_template = array_merge($vars_for_template, [
|
|
|
'series#' . $i => $product->series,
|
|
'series#' . $i => $product->series,
|
|
|
|
|
+ 'product_group#' .$i => $product->product_group,
|
|
|
'num#' . $i => $i,
|
|
'num#' . $i => $i,
|
|
|
'name#' . $i => $product->name,
|
|
'name#' . $i => $product->name,
|
|
|
|
|
+ 'name_for_form#' . $i => $product->name_for_form,
|
|
|
'price#' . $i => number_format($product->price, 0, '', ' '),
|
|
'price#' . $i => number_format($product->price, 0, '', ' '),
|
|
|
'image#' . $i => $product->image_path,
|
|
'image#' . $i => $product->image_path,
|
|
|
'description#' . $i => str_replace("\n", '</w:t><w:br/><w:t xml:space="preserve">', $product->characteristics . "\r\n" . $product->tech_description),
|
|
'description#' . $i => str_replace("\n", '</w:t><w:br/><w:t xml:space="preserve">', $product->characteristics . "\r\n" . $product->tech_description),
|
|
@@ -31,19 +34,14 @@ class ExportController extends Controller
|
|
|
$my_template->cloneBlock('product_block', count($products), true, true, $vars_for_template);
|
|
$my_template->cloneBlock('product_block', count($products), true, true, $vars_for_template);
|
|
|
|
|
|
|
|
foreach ($vars_for_template as $k => $v){
|
|
foreach ($vars_for_template as $k => $v){
|
|
|
- if(str_starts_with($k, 'image')){
|
|
|
|
|
- $my_template->setImageValue($k, ['path' => public_path() . '/' . env('IMAGES_PATH') . '/' . $v,
|
|
|
|
|
|
|
+ if(str_starts_with($k, 'image') && file_exists($file = public_path() . '/' . env('IMAGES_PATH') . '/' . $v)){
|
|
|
|
|
+ $my_template->setImageValue($k, ['path' => $file,
|
|
|
'width' => 270, 'height' => 180
|
|
'width' => 270, 'height' => 180
|
|
|
]);
|
|
]);
|
|
|
} else {
|
|
} else {
|
|
|
$my_template->setValue($k, $v);
|
|
$my_template->setValue($k, $v);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if(str_starts_with($k, 'series')) {
|
|
|
|
|
-// $my_template->cloneRow($k, 5);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -60,6 +58,8 @@ class ExportController extends Controller
|
|
|
header('Expires: 0');
|
|
header('Expires: 0');
|
|
|
ob_clean();
|
|
ob_clean();
|
|
|
$my_template->saveAs("php://output");
|
|
$my_template->saveAs("php://output");
|
|
|
|
|
+ Log::notice('Execution time: ' . microtime(true) - LARAVEL_START);
|
|
|
|
|
+
|
|
|
exit();
|
|
exit();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|