← All changes
|
app/Modules/Shipping/Http/Requests/ShippingZoneRequest.php
+16
-0
1.6.0
→
1.6.5
View file →
| @@ -19,8 +19,24 @@ | ||
| 19 | 19 | // Only include shipping_class_id if explicitly submitted — prevents wiping on edit |
| 20 | 20 | if (array_key_exists('shipping_class_id', $data)) { |
| 21 | 21 | $classId = $data['shipping_class_id']; |
| 22 | 22 | $data['shipping_class_id'] = $classId ? intval($classId) : null; |
| 23 | + } else { | |
| 24 | + // Omitted on update means "preserve the stored class". Resolve the | |
| 25 | + // effective class HERE (this return is merged into the request) so | |
| 26 | + // the whole-world uniqueness rule below validates the same class | |
| 27 | + // bucket the row will actually keep — and the controller writes | |
| 28 | + // that same value back. Without this, a class-scoped zone going | |
| 29 | + // region=all was checked against general zones: falsely rejected by | |
| 30 | + // an unrelated general whole-world zone, while a real conflict in | |
| 31 | + // its own class went unchecked. | |
| 32 | + $currentId = Arr::get($data, 'id') ?: App::getInstance()->request->get('id'); | |
| 33 | + if ($currentId) { | |
| 34 | + $storedClassId = \FluentCart\App\Models\ShippingZone::query() | |
| 35 | + ->where('id', intval($currentId)) | |
| 36 | + ->value('shipping_class_id'); | |
| 37 | + $data['shipping_class_id'] = $storedClassId ? intval($storedClassId) : null; | |
| 38 | + } | |
| 23 | 39 | } |
| 24 | 40 | |
| 25 | 41 | return $data; |
| 26 | 42 | } |