*/ public function rules(): array { $rules = [ // 처리 대상 옵션 ID 배열 (필수) - "productId-optionId" 형식 'ids' => ['required', 'array', 'min:1'], 'ids.*' => ['string', 'regex:/^\d+-\d+$/'], // 옵션 일괄 변경 조건 (선택) 'bulk_changes' => ['nullable', 'array'], 'bulk_changes.price_adjustment' => ['nullable', 'array'], 'bulk_changes.price_adjustment.method' => ['required_with:bulk_changes.price_adjustment', 'string', 'in:set,add,percent'], 'bulk_changes.price_adjustment.value' => ['required_with:bulk_changes.price_adjustment', 'numeric'], 'bulk_changes.stock_quantity' => ['nullable', 'array'], 'bulk_changes.stock_quantity.method' => ['required_with:bulk_changes.stock_quantity', 'string', 'in:set,add,subtract'], 'bulk_changes.stock_quantity.value' => ['required_with:bulk_changes.stock_quantity', 'integer', 'min:0'], // 옵션 개별 인라인 수정 (선택) 'items' => ['nullable', 'array'], 'items.*.product_id' => ['required', 'integer', Rule::exists(Product::class, 'id')], 'items.*.option_id' => ['required', 'integer', Rule::exists(ProductOption::class, 'id')], 'items.*.option_name' => ['nullable', 'array'], 'items.*.option_name.*' => ['nullable', 'string', 'max:255'], 'items.*.sku' => ['nullable', 'string', 'max:100'], 'items.*.list_price' => ['nullable', 'numeric', 'min:0'], 'items.*.price_adjustment' => ['nullable', 'numeric'], 'items.*.stock_quantity' => ['nullable', 'integer', 'min:0'], 'items.*.safe_stock_quantity' => ['nullable', 'integer', 'min:0'], 'items.*.is_default' => ['nullable', 'boolean'], 'items.*.is_active' => ['nullable', 'boolean'], ]; // 훅을 통한 validation rules 확장 return HookManager::applyFilters('sirsoft-ecommerce.option.bulk_update_validation_rules', $rules, $this); } /** * 커스텀 에러 메시지 * * @return array */ public function messages(): array { return [ 'ids.required' => __('sirsoft-ecommerce::validation.option.bulk.ids_required'), 'ids.min' => __('sirsoft-ecommerce::validation.option.bulk.ids_min'), 'ids.*.regex' => __('sirsoft-ecommerce::validation.option.bulk.invalid_id_format'), 'items.*.option_id.exists' => __('sirsoft-ecommerce::validation.product.bulk.option_not_found'), ]; } }