PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Http / Controllers / TemplateController.php

TemplateController.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Http/Controllers/TemplateController.php

53 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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