| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Modules\Shipping\Http\Controllers; |
| 4 |
|
| 5 |
use FluentCart\App\Http\Controllers\Controller; |
| 6 |
use FluentCart\App\Models\ShippingMethod; |
| 7 |
use FluentCart\Framework\Support\Arr; |
| 8 |
use FluentCart\App\Modules\Shipping\Http\Requests\ShippingMethodRequest; |
| 9 |
|
| 10 |
class ShippingMethodController extends Controller |
| 11 |
{ |
| 12 |
|
| 13 |
public function store(ShippingMethodRequest $request): \WP_REST_Response |
| 14 |
{ |
| 15 |
$data = $request->getSafe($request->sanitize()); |
| 16 |
|
| 17 |
ShippingMethod::create($data); |
| 18 |
|
| 19 |
return $this->sendSuccess([ |
| 20 |
'message' => __('Shipping method has been created successfully', 'fluent-cart') |
| 21 |
]); |
| 22 |
} |
| 23 |
|
| 24 |
public function update(ShippingMethodRequest $request): \WP_REST_Response |
| 25 |
{ |
| 26 |
$data = $request->getSafe($request->sanitize()); |
| 27 |
$methodId = Arr::get($data, 'method_id'); |
| 28 |
|
| 29 |
$method = ShippingMethod::findOrFail($methodId); |
| 30 |
|
| 31 |
$method->update($data); |
| 32 |
|
| 33 |
return $this->sendSuccess([ |
| 34 |
'message' => __('Shipping method has been updated successfully', 'fluent-cart') |
| 35 |
]); |
| 36 |
} |
| 37 |
|
| 38 |
public function destroy($method_id) |
| 39 |
{ |
| 40 |
$method = ShippingMethod::findOrFail($method_id); |
| 41 |
$method->delete(); |
| 42 |
|
| 43 |
return $this->sendSuccess([ |
| 44 |
'message' => __('Shipping method has been deleted successfully', 'fluent-cart') |
| 45 |
]); |
| 46 |
} |
| 47 |
|
| 48 |
} |
| 49 |
|