PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.23
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.23
1.6.5 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 All 48 releases
fluent-cart / app / Http / Controllers / TaxConfigurationController.php

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

96 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Http\Controllers;
4
5 use FluentCart\Framework\Support\Arr;
6 use FluentCart\App\Modules\Tax\TaxModule;
7 use FluentCart\App\Services\Tax\TaxManager;
8 use FluentCart\Framework\Http\Request\Request;
9
10 class TaxConfigurationController extends Controller
11 {
12 public function getTaxRates()
13 {
14 $taxManager = TaxManager::getInstance();
15 $rates = $taxManager->getTaxRatesFromTaxPhp();
16
17 return $this->sendSuccess([
18 'tax_rates' => $rates
19 ]);
20 }
21
22 public function saveConfiguredCountries(Request $request)
23 {
24 $countryCodes = $request->get('countries', []);
25 $taxManager = TaxManager::getInstance();
26 $taxManager->generateTaxClasses($countryCodes);
27
28 return $this->sendSuccess([
29 'message' => __('Countries saved successfully', 'fluent-cart')
30 ]);
31 }
32
33 public function getSettings()
34 {
35 $settings = (new TaxModule())->getSettings();
36
37 return $this->sendSuccess([
38 'settings' => $settings
39 ]);
40 }
41
42 public function saveSettings(Request $request)
43 {
44 $settings = $request->get('settings', $this->defaultSettings());
45
46 foreach ($settings as $key => $value) {
47 if ($key === 'eu_vat_settings' && is_array($value)) {
48 // Sanitize nested eu_vat_settings
49 $eu = $value;
50 foreach ($eu as $ek => $ev) {
51 if ($ek === 'vat_reverse_excluded_categories') {
52 $cats = is_array($ev) ? $ev : [];
53 $eu[$ek] = array_values(array_filter(array_map('intval', $cats), function ($v) { return $v > 0; }));
54 } else {
55 $eu[$ek] = is_array($ev) ? $ev : sanitize_text_field($ev);
56 }
57 }
58 $settings[$key] = $eu;
59 } else if (is_array($value)) {
60 $settings[$key] = array_map('sanitize_text_field', $value);
61 } else {
62 $settings[$key] = sanitize_text_field($value);
63 }
64 }
65
66 // save settings to wp_options
67 update_option('fluent_cart_tax_configuration_settings', $settings, true);
68
69 if (Arr::get($settings, 'enable_tax') === 'yes') {
70 (new TaxClassController())->checkAndCreateInitialTaxClasses();
71 }
72
73 return $this->sendSuccess([
74 'message' => __('Settings saved successfully', 'fluent-cart')
75 ]);
76 }
77
78 private function defaultSettings()
79 {
80 return [
81 'tax_inclusion' => 'included',
82 'tax_calculation_basis' => 'shipping',
83 'tax_rounding' => 'item',
84 'enable_tax' => 'no',
85 'eu_vat_settings' => [
86 'require_vat_number' => 'no',
87 'local_reverse_charge' => 'yes',
88 'vat_reverse_excluded_categories' => [],
89 'country_wise_vat' => []
90 ]
91 ];
92 }
93
94 }
95
96