PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
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
← All changes | app/Http/Controllers/TaxClassController.php +16 -52 1.3.21 → 1.6.5 View file →
@@ -3,10 +3,8 @@
3 3 namespace FluentCart\App\Http\Controllers;
4 4
5 5 use FluentCart\App\Models\TaxClass;
6 6 use FluentCart\Framework\Support\Arr;
7 -use FluentCart\Framework\Support\Str;
8 -use FluentCart\App\Modules\Tax\TaxModule;
9 7 use FluentCart\Framework\Http\Request\Request;
10 8 use FluentCart\App\Http\Requests\TaxClassRequest;
11 9
12 10 class TaxClassController extends Controller
@@ -22,12 +20,9 @@
22 20 if ($aPriority === $bPriority) {
23 21 return $b->id <=> $a->id; // newer first when priority equal
24 22 }
25 23 return $bPriority <=> $aPriority;
26 - })->values()->map(function ($taxClass) {
27 - $taxClass->categories = Arr::get($taxClass->meta, 'categories', []);
28 - return $taxClass;
29 - });
24 + })->values();
30 25
31 26 return $this->sendSuccess([
32 27 'tax_classes' => $taxClasses
33 28 ]);
@@ -39,11 +34,9 @@
39 34 $data = $request->getSafe($request->sanitize());
40 35
41 36 $taxClassData = [
42 37 'title' => Arr::get($data, 'title'),
43 - 'description' => Arr::get($data, 'description', ''),
44 38 'meta' => [
45 - 'categories' => Arr::get($data, 'categories', []),
46 39 'priority' => Arr::get($data, 'priority', 0),
47 40 ]
48 41 ];
49 42
@@ -55,9 +48,9 @@
55 48 ]);
56 49 }
57 50
58 51 return $this->sendSuccess([
59 - 'message' => __('Tax class has been created successfully', 'fluent-cart')
52 + 'message' => __('Tax profile has been created successfully', 'fluent-cart')
60 53 ]);
61 54
62 55 }
63 56
@@ -66,50 +59,16 @@
66 59 if (get_option('fluent_cart_has_tax_configure', false)) {
67 60 return;
68 61 }
69 62
70 - $taxClasses = [
63 + TaxClass::query()->firstOrCreate(
64 + ['slug' => 'standard'],
71 65 [
72 66 'title' => __('Standard', 'fluent-cart'),
73 - 'slug' => 'standard',
74 - 'description' => __('Standard tax rate for most products', 'fluent-cart'),
75 - 'meta' => [
76 - 'categories' => [],
77 - 'priority' => 10,
78 - ]
79 - ],
80 - [
81 - 'title' => __('Reduced', 'fluent-cart'),
82 - 'slug' => 'reduced',
83 - 'description' => __('Reduced tax rate for essential goods', 'fluent-cart'),
84 - 'meta' => [
85 - 'categories' => [],
86 - 'priority' => 5,
87 - ]
88 - ],
89 - [
90 - 'title' => __('Zero', 'fluent-cart'),
91 - 'slug' => 'zero',
92 - 'description' => __('Zero tax rate for exempt products', 'fluent-cart'),
93 - 'meta' => [
94 - 'categories' => [],
95 - 'priority' => 2,
96 - ]
97 67 ]
98 - ];
99 -
100 - foreach ($taxClasses as $taxClass) {
101 - $taxClass = TaxClass::query()->firstOrCreate(
102 - ['slug' => $taxClass['slug']],
103 - [
104 - 'title' => $taxClass['title'],
105 - 'description' => $taxClass['description'],
106 - 'meta' => $taxClass['meta']
107 - ]
108 68 );
109 - }
110 69
111 - update_option('fluent_cart_has_tax_configure', true);
70 + update_option('fluent_cart_has_tax_configure', true);
112 71 }
113 72
114 73 public function update(TaxClassRequest $request, $id)
115 74 {
@@ -117,11 +76,9 @@
117 76 $taxClass = TaxClass::query()->findOrFail($id);
118 77
119 78 $taxClassData = [
120 79 'title' => Arr::get($data, 'title'),
121 - 'description' => Arr::get($data, 'description', ''),
122 80 'meta' => [
123 - 'categories' => Arr::get($data, 'categories', []),
124 81 'priority' => Arr::get($data, 'priority', 0),
125 82 ]
126 83 ];
127 84
@@ -128,14 +85,14 @@
128 85 $isUpdated = $taxClass->update($taxClassData);
129 86
130 87 if (!$isUpdated) {
131 88 return $this->sendError([
132 - 'message' => __('Failed to update tax class', 'fluent-cart')
89 + 'message' => __('Failed to update tax profile', 'fluent-cart')
133 90 ]);
134 91 }
135 92
136 93 return $this->sendSuccess([
137 - 'message' => __('Tax class has been updated successfully', 'fluent-cart')
94 + 'message' => __('Tax profile has been updated successfully', 'fluent-cart')
138 95 ]);
139 96 }
140 97
141 98
@@ -142,18 +99,25 @@
142 99
143 100 public function delete(Request $request, $id)
144 101 {
145 102 $taxClass = TaxClass::query()->findOrFail($id);
103 +
104 + if ($taxClass->slug === 'standard') {
105 + return $this->sendError([
106 + 'message' => __('Cannot delete the Standard tax class', 'fluent-cart')
107 + ], 423);
108 + }
109 +
146 110 $isDeleted = $taxClass->delete();
147 111
148 112 if (!$isDeleted) {
149 113 return $this->sendError([
150 - 'message' => __('Failed to delete tax class', 'fluent-cart')
114 + 'message' => __('Failed to delete tax profile', 'fluent-cart')
151 115 ]);
152 116 }
153 117
154 118 return $this->sendSuccess([
155 - 'message' => __('Tax class has been deleted successfully', 'fluent-cart')
119 + 'message' => __('Tax profile has been deleted successfully', 'fluent-cart')
156 120 ]);
157 121 }
158 122
159 123 }