| 1 |
<?php |
| 2 |
namespace FluentCart\App\Http\Controllers; |
| 3 |
|
| 4 |
use FluentCart\App\App; |
| 5 |
use FluentCart\App\Services\TemplateService; |
| 6 |
use FluentCart\App\Vite; |
| 7 |
use FluentCart\Framework\Http\Request\Request; |
| 8 |
use FluentCart\Framework\Support\Arr; |
| 9 |
|
| 10 |
class TemplateController extends Controller |
| 11 |
{ |
| 12 |
public function getPrintTemplates(Request $request): \WP_REST_Response |
| 13 |
{ |
| 14 |
$availableTemplates = [ |
| 15 |
'invoice_template' => __('Invoice Template', 'fluent-cart'), |
| 16 |
'packing_slip' => __('Packing Slip Template', 'fluent-cart'), |
| 17 |
'delivery_slip' => __('Delivery Slip Template', 'fluent-cart'), |
| 18 |
'shipping_slip' => __('Shipping Slip Template', 'fluent-cart'), |
| 19 |
'dispatch_slip' => __('Dispatch Slip Template', 'fluent-cart'), |
| 20 |
]; |
| 21 |
$templates = []; |
| 22 |
foreach ($availableTemplates as $path => $template) { |
| 23 |
$content = fluent_cart_get_option($path, ''); |
| 24 |
if (empty($content)) { |
| 25 |
$content = TemplateService::getInvoicePackingTemplateByPathName($path); |
| 26 |
} |
| 27 |
$templates[] = [ |
| 28 |
'key' => $path, |
| 29 |
'title' => $template, |
| 30 |
'content' => $content |
| 31 |
]; |
| 32 |
} |
| 33 |
|
| 34 |
return $this->sendSuccess([ |
| 35 |
'templates' => $templates |
| 36 |
]); |
| 37 |
} |
| 38 |
|
| 39 |
public function savePrintTemplates(Request $request): \WP_REST_Response |
| 40 |
{ |
| 41 |
$templates = Arr::get($request->all(), 'templates', []); |
| 42 |
foreach ($templates as $template) { |
| 43 |
$key = sanitize_key(Arr::get($template, 'key')); |
| 44 |
$content = wp_kses_post(Arr::get($template, 'content')); |
| 45 |
fluent_cart_update_option($key, $content); |
| 46 |
} |
| 47 |
return $this->sendSuccess([ |
| 48 |
'message' => __('Template saved successfully', 'fluent-cart') |
| 49 |
]); |
| 50 |
} |
| 51 |
|
| 52 |
} |
| 53 |
|