- Add a custom hook `useCardTableExpand` for managing expandable card tables. - Refactor product columns to include variant edit and delete handlers. - Integrate `CardTable` component for displaying products with expandable variant details. - Create `ProductCardRow` component for rendering product information in a card format. - Implement variant editing functionality with a dedicated `ProductVariantEdit` component. - Add `VariantSubRow` component to display variant details in a table format. - Update routes to handle product variant editing and deletion. - Enhance tests to cover variant editing and deletion scenarios.
56 lines
1.6 KiB
PHP
56 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin\Master\Product;
|
|
|
|
use App\Enums\PriceType;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class ProductVariantRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function prepareForValidation(): void
|
|
{
|
|
$prices = $this->prices;
|
|
if (is_array($prices)) {
|
|
foreach ($prices as $i => $price) {
|
|
if (isset($price['price']) && is_string($price['price'])) {
|
|
$this->request->set("prices.$i.price", (int) str_replace('.', '', $price['price']));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => ['required', 'string', 'max:200'],
|
|
'stock' => ['required', 'integer', 'min:0'],
|
|
'reject_stock' => ['required', 'integer', 'min:0'],
|
|
'retail_stock' => ['required', 'integer', 'min:0'],
|
|
'photo_key' => ['required', 'string', 'max:500'],
|
|
'prices' => ['required', 'array', 'size:9'],
|
|
'prices.*.type' => ['required', Rule::in(PriceType::values())],
|
|
'prices.*.price' => ['required', 'integer', 'min:0'],
|
|
];
|
|
}
|
|
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'name' => 'Nama Varian',
|
|
'stock' => 'Stok Bagus',
|
|
'reject_stock' => 'Stok Reject',
|
|
'retail_stock' => 'Stok Ecer',
|
|
'photo_key' => 'Foto',
|
|
'prices' => 'Harga',
|
|
'prices.*.type' => 'Tipe Harga',
|
|
'prices.*.price' => 'Harga',
|
|
];
|
|
}
|
|
}
|