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 / api / Confirmation.php

Confirmation.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at api/Confirmation.php

121 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\Api;
4
5 use FluentCart\App\App;
6 use FluentCart\App\CPT\Pages;
7 use FluentCart\App\Helpers\Helper as HelperService;
8 use FluentCart\App\Vite;
9 use FluentCart\Framework\Support\Arr;
10
11 class Confirmation
12 {
13 /**
14 * @var string
15 *
16 * Confirmation settings option name
17 */
18 protected $confirmationHandler = 'fluent_cart_confirmation_settings';
19
20 /**
21 * @var array key value pair
22 *
23 * Confirmation settings parsed from fields
24 */
25 protected $confirmationSettings;
26
27 public function __construct()
28 {
29 $defaults = static::fields();
30
31 $template = "fluent_cart_order_created_template";
32 ob_start();
33 $defaultBannerImage = Vite::getAssetUrl('images/email-template/email-banner.png');
34
35 App::make('view')->render('emails.' . $template, [
36 'default_banner_image' => $defaultBannerImage,
37 ]);
38 $view = ob_get_clean();
39
40
41 $defaultSettings = [
42 'confirmation_type' => 'same_page',
43 'message_to_show' => $view
44 ];
45
46 foreach (array_keys($defaults) as $index => $key) {
47 $defaultSettings[$key] = $defaults[$key]['value'];
48 }
49
50 $settings = fluent_cart_get_option($this->confirmationHandler, []);
51
52 $this->confirmationSettings = wp_parse_args($settings, $defaultSettings);
53
54 }
55
56 /**
57 * @return array
58 *
59 * Get all confirmation settings fields
60 * @hook to use apply_filters("fluent_cart/confirmation_setting_fields", $fields)
61 */
62 public static function fields()
63 {
64 $pages = Pages::getPages('');
65
66 $fields = [
67 "confirmation_page_id" => [
68 "label" => __('Select custom page', 'fluent-cart'),
69 "type" => "select",
70 "options" => $pages,
71 "value" => "",
72 "note" => \FluentCart\App\Helpers\Helper::getShortcodeInstructionString('[fluent_cart_receipt]')
73 ],
74 ];
75
76 return apply_filters("fluent_cart/confirmation_setting_fields", $fields, []);
77 }
78
79 /**
80 * @return array
81 *
82 * @param string $key like stripe or PayPal
83 * All confirmation settings if key is not provided
84 */
85 public function get($key = null, $default = null)
86 {
87 if (!$key) {
88 return array_merge(
89 $this->confirmationSettings,
90 $default??[],
91 );
92 }
93
94 return Arr::get($this->confirmationSettings, $key, $default);
95 }
96
97
98 /**
99 * @return boolean
100 *
101 * @param array $settings like stripe or PayPal settings array
102 * Save confirmation settings
103 */
104 public function save(array $settings)
105 {
106 if (isset($settings['message_to_show'])) {
107 $settings['message_to_show'] = wp_kses_post($settings['message_to_show']);
108 }
109 $settings = Helper::sanitize($settings, static::fields());
110 (new StoreSettings())->set('receipt_page_id', Arr::get($settings,'confirmation_page_id'));
111 unset($settings['confirmation_page_id']);
112 return fluent_cart_update_option($this->confirmationHandler, $settings);
113 }
114
115 public function getContent()
116 {
117 return $this->confirmationSettings['message_to_show'];
118 }
119
120 }
121