good
This commit is contained in:
@@ -19,7 +19,7 @@ class OrderIndexResource extends JsonResource
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'status' => OrderStatus::formattedStatusFor($this->status),
|
||||
'shipping_method' => OrderShipping::formattedShippingMethod($this->shipping_method),
|
||||
'shipping_method' => $this->formattedShippingMethod(),
|
||||
'notes' => $this->notes,
|
||||
'delivery_time' => $this->delivery_time,
|
||||
'delivery_at' => $this->delivery_at,
|
||||
|
||||
@@ -19,7 +19,7 @@ class OrderShowResource extends JsonResource
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'status' => OrderStatus::formattedStatusFor($this->status),
|
||||
'shipping_method' => OrderShipping::formattedShippingMethod($this->shipping_method),
|
||||
'shipping_method' => $this->formattedShippingMethod(),
|
||||
'notes' => $this->notes,
|
||||
'delivery_time' => $this->delivery_time,
|
||||
'delivery_at' => $this->delivery_at,
|
||||
|
||||
@@ -9,10 +9,26 @@ use App\Models\System\Settings\Location\Region;
|
||||
use App\Models\System\Settings\OS;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\Ecommerce\Product\Order\Shipping\OrderShippingMethod;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class CheckoutOrderRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
if (! $this->has('shipping_method_id') && $this->has('shipping_method')) {
|
||||
$method = OrderShippingMethod::query()->where('slug', $this->shipping_method)->first();
|
||||
if ($method) {
|
||||
$this->merge([
|
||||
'shipping_method_id' => $method->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the validator instance.
|
||||
*
|
||||
@@ -39,7 +55,8 @@ class CheckoutOrderRequest extends FormRequest
|
||||
'customer_phone' => ['required', 'integer', 'between:61000000,71999999'],
|
||||
'customer_address' => ['required', 'string', 'max:255'],
|
||||
|
||||
'shipping_method' => ['required', 'string', 'max:255', Rule::in(array_keys(OrderShipping::values()))],
|
||||
'shipping_method_id' => ['required', 'integer', 'exists:order_shipping_methods,id'],
|
||||
'shipping_method' => ['nullable', 'string', 'max:255', Rule::in(array_keys(OrderShipping::values()))],
|
||||
|
||||
'shipping_price' => ['nullable', 'numeric'],
|
||||
'product_ids' => ['required', 'array'],
|
||||
@@ -67,13 +84,16 @@ class CheckoutOrderRequest extends FormRequest
|
||||
*/
|
||||
protected function passedValidation(): void
|
||||
{
|
||||
$shippingMethod = OrderShippingMethod::query()->find($this->shipping_method_id);
|
||||
|
||||
$this->merge([
|
||||
'number' => Str::random(30),
|
||||
'status' => OrderStatus::default(),
|
||||
'user_id' => auth()->id(),
|
||||
'notes' => $this->notes ?: null,
|
||||
'province_id' => $this->province_id ?: null,
|
||||
'shipping_price' => $this->shipping_price ?: OrderShipping::priceFor($this->shipping_method),
|
||||
'shipping_method' => $this->shipping_method ?: $shippingMethod?->slug,
|
||||
'shipping_price' => $this->shipping_price ?: ($shippingMethod?->price ?? 0),
|
||||
'delivery_time' => $this->delivery_time ?: OrderShipping::MORNING,
|
||||
'delivery_at' => $this->delivery_at ?: date('Y-m-d'),
|
||||
'source_app' => $this->source ?: OS::MOBILE_APP,
|
||||
@@ -88,9 +108,7 @@ class CheckoutOrderRequest extends FormRequest
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'shipping_method.in' => sprintf('Valid sources: %s', implode(', ', array_keys(
|
||||
OrderShipping::values()
|
||||
))),
|
||||
'shipping_method_id.exists' => 'The selected shipping method is invalid.',
|
||||
'payment_type_id.in' => sprintf('Valid sources: %s', implode(', ', array_keys(
|
||||
OrderPayment::values()
|
||||
))),
|
||||
|
||||
@@ -19,7 +19,7 @@ class OrderIndexResource extends JsonResource
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'status' => OrderStatus::formattedStatusFor($this->status),
|
||||
'shipping_method' => OrderShipping::formattedShippingMethod($this->shipping_method),
|
||||
'shipping_method' => $this->formattedShippingMethod(),
|
||||
'notes' => $this->notes,
|
||||
'customer_name' => $this->customer_name,
|
||||
'customer_phone' => $this->customer_phone,
|
||||
|
||||
@@ -19,7 +19,7 @@ class VendorOrderIndexResource extends JsonResource
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'status' => OrderStatus::formattedStatusFor($this->status),
|
||||
'shipping_method' => OrderShipping::formattedShippingMethod($this->shipping_method),
|
||||
'shipping_method' => $this->formattedShippingMethod(),
|
||||
'notes' => $this->notes,
|
||||
'delivery_time' => $this->delivery_time,
|
||||
'delivery_at' => $this->delivery_at?->format('d.m.Y'),
|
||||
|
||||
@@ -19,7 +19,7 @@ class VendorOrderShowResource extends JsonResource
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'status' => OrderStatus::formattedStatusFor($this->status),
|
||||
'shipping_method' => OrderShipping::formattedShippingMethod($this->shipping_method),
|
||||
'shipping_method' => $this->formattedShippingMethod(),
|
||||
'notes' => $this->notes,
|
||||
'delivery_time' => $this->delivery_time,
|
||||
'delivery_at' => $this->delivery_at,
|
||||
|
||||
@@ -62,6 +62,10 @@ class OrderFieldsForUpdate
|
||||
Text::make(__('Shipping price'), 'shipping_price')
|
||||
->rules('required', 'numeric')
|
||||
->dependsOn('shippingMethod', function ($field, $request, $formData) {
|
||||
if ($formData->shipping_price) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($formData->shippingMethod) {
|
||||
$method = OrderShippingMethodModel::query()->find($formData->shippingMethod);
|
||||
if ($method) {
|
||||
|
||||
Reference in New Issue
Block a user