Skip to content

Commit 050744e

Browse files
committed
The issue tracked under #2139 has been addressed.
1 parent 8891af8 commit 050744e

File tree

4 files changed

+65
-4
lines changed

4 files changed

+65
-4
lines changed

packages/Webkul/Admin/src/Http/Controllers/Quote/QuoteController.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public function create(): View
6262
*/
6363
public function store(AttributeForm $request): RedirectResponse
6464
{
65+
$this->additionalValidation();
66+
6567
Event::dispatch('quote.create.before');
6668

6769
$quote = $this->quoteRepository->create($request->all());
@@ -94,6 +96,8 @@ public function edit(int $id): View
9496
*/
9597
public function update(AttributeForm $request, int $id): RedirectResponse
9698
{
99+
$this->additionalValidation();
100+
97101
Event::dispatch('quote.update.before', $id);
98102

99103
$quote = $this->quoteRepository->update($request->all(), $id);
@@ -187,4 +191,21 @@ public function print($id): Response|StreamedResponse
187191
'Quote_'.$quote->subject.'_'.$quote->created_at->format('d-m-Y')
188192
);
189193
}
194+
195+
/**
196+
* Additional validation for quote product items.
197+
*/
198+
private function additionalValidation(): void
199+
{
200+
$this->validate(request(), [
201+
'items' => 'required|array',
202+
'items.*.product_id' => 'required|exists:products,id',
203+
'items.*.quantity' => 'required|numeric|min:0',
204+
'items.*.price' => 'required|numeric|min:0',
205+
'items.*.total' => 'required|numeric|min:0',
206+
'items.*.discount_amount' => 'required|numeric|min:0',
207+
'items.*.tax_amount' => 'required|numeric|min:0',
208+
'items.*.final_total' => 'required|numeric|min:0',
209+
]);
210+
}
190211
}

packages/Webkul/Admin/src/Resources/views/components/attributes/edit/date.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
$value = \Carbon\Carbon::parse($value)->format('Y-m-d');
77
}
88
}
9+
10+
$value = old($attribute->code, $value);
911
@endphp
1012

1113
<x-admin::form.control-group.control

packages/Webkul/Admin/src/Resources/views/quotes/create.blade.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,13 @@ class="control"
436436
::name="`${inputName}[product_id]`"
437437
:placeholder="trans('admin::app.quotes.create.search-products')"
438438
@on-selected="(product) => addProduct(product)"
439+
rules="required"
440+
label="Product Name"
441+
::class="errors[`${inputName}[product_id]`] ? 'border !border-red-600 hover:border-red-600' : ''"
439442
/>
443+
444+
<x-admin::form.control-group.error name="items.item_0.product_id"/>
445+
<x-admin::form.control-group.error name="items[item_0][product_id]"/>
440446
</x-admin::form.control-group>
441447
</x-admin::table.td>
442448
@@ -447,13 +453,15 @@ class="control"
447453
type="inline"
448454
::name="`${inputName}[quantity]`"
449455
::value="product.quantity"
450-
rules="required|decimal:4"
456+
rules="required|numeric|min:1"
451457
::errors="errors"
452458
:label="trans('admin::app.quotes.create.quantity')"
453459
:placeholder="trans('admin::app.quotes.create.quantity')"
454460
@on-change="(event) => product.quantity = event.value"
455461
position="center"
456462
/>
463+
464+
<x-admin::form.control-group.error name="items.item_0.quantity"/>
457465
</x-admin::form.control-group>
458466
</x-admin::table.td>
459467
@@ -472,6 +480,8 @@ class="control"
472480
position="center"
473481
::value-label="$admin.formatPrice(product.price)"
474482
/>
483+
484+
<x-admin::form.control-group.error name="items.item_0.price"/>
475485
</x-admin::form.control-group>
476486
</x-admin::table.td>
477487
@@ -490,6 +500,8 @@ class="control"
490500
position="center"
491501
::value-label="$admin.formatPrice(product.price * product.quantity)"
492502
/>
503+
504+
<x-admin::form.control-group.error name="items.item_0.total"/>
493505
</x-admin::form.control-group>
494506
</x-admin::table.td>
495507
@@ -508,6 +520,8 @@ class="control"
508520
position="center"
509521
::value-label="$admin.formatPrice(product.discount_amount)"
510522
/>
523+
524+
<x-admin::form.control-group.error name="items.item_0.discount_amount"/>
511525
</x-admin::form.control-group>
512526
</x-admin::table.td>
513527
@@ -526,6 +540,8 @@ class="control"
526540
position="center"
527541
::value-label="$admin.formatPrice(product.tax_amount)"
528542
/>
543+
544+
<x-admin::form.control-group.error name="items.item_0.tax_amount"/>
529545
</x-admin::form.control-group>
530546
</x-admin::table.td>
531547
@@ -541,6 +557,8 @@ class="control"
541557
position="center"
542558
::value-label="$admin.formatPrice(parseFloat(product.price * product.quantity) + parseFloat(product.tax_amount) - parseFloat(product.discount_amount))"
543559
/>
560+
561+
<x-admin::form.control-group.error name="items.item_0.final_total"/>
544562
</x-admin::form.control-group>
545563
</x-admin::table.td>
546564

packages/Webkul/Admin/src/Resources/views/quotes/edit.blade.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ class="!px-2 ltr:text-right rtl:text-left"
329329
</template>
330330
</x-admin::table.tbody>
331331
</x-admin::table>
332+
333+
<x-admin::form.control-group.error name="items"/>
332334
</div>
333335
334336
<!-- Add New Quote Item -->
@@ -425,7 +427,13 @@ class="control"
425427
::value="{ id: product.product_id, name: product.name }"
426428
@on-selected="(product) => addProduct(product)"
427429
:placeholder="trans('admin::app.quotes.edit.search-products')"
430+
rules="required"
431+
label="Product Name"
432+
::class="errors[`${inputName}[product_id]`] ? 'border !border-red-600 hover:border-red-600' : ''"
428433
/>
434+
435+
<x-admin::form.control-group.error name="`items.${product.id}.product_id`"/>
436+
<x-admin::form.control-group.error ::name="`${inputName}[product_id]`"/>
429437
</x-admin::form.control-group>
430438
</x-admin::table.td>
431439
@@ -443,6 +451,9 @@ class="control"
443451
@on-change="(event) => product.quantity = event.value"
444452
position="center"
445453
/>
454+
455+
456+
<x-admin::form.control-group.error ::name="`items.${product.id}.quantity`"/>
446457
</x-admin::form.control-group>
447458
</x-admin::table.td>
448459
@@ -452,7 +463,7 @@ class="control"
452463
<x-admin::form.control-group.control
453464
type="inline"
454465
::name="`${inputName}[price]`"
455-
::value="product.price"
466+
::value="(product.price) ?? 0"
456467
rules="required|decimal:4"
457468
::errors="errors"
458469
:label="trans('admin::app.quotes.create.price')"
@@ -461,6 +472,9 @@ class="control"
461472
position="center"
462473
::value-label="$admin.formatPrice(product.price)"
463474
/>
475+
476+
<x-admin::form.control-group.error name="`items.${product.id}.price`"/>
477+
<x-admin::form.control-group.error ::name="`${inputName}[price]`"/>
464478
</x-admin::form.control-group>
465479
</x-admin::table.td>
466480
@@ -470,7 +484,7 @@ class="control"
470484
<x-admin::form.control-group.control
471485
type="inline"
472486
::name="`${inputName}[total]`"
473-
::value="product.price * product.quantity"
487+
::value="(product.price * product.quantity) ?? 0"
474488
rules="required|decimal:4"
475489
::errors="errors"
476490
:label="trans('admin::app.quotes.create.total')"
@@ -479,6 +493,9 @@ class="control"
479493
position="center"
480494
::value-label="$admin.formatPrice(product.price * product.quantity)"
481495
/>
496+
497+
<x-admin::form.control-group.error name="`items.${product.id}.total`"/>
498+
<x-admin::form.control-group.error ::name="`${inputName}[total]`"/>
482499
</x-admin::form.control-group>
483500
</x-admin::table.td>
484501
@@ -497,6 +514,9 @@ class="control"
497514
position="center"
498515
::value-label="$admin.formatPrice(product.discount_amount)"
499516
/>
517+
518+
<x-admin::form.control-group.error name="`items.${product.id}.discount_amount`"/>
519+
<x-admin::form.control-group.error ::name="`${inputName}[discount_amount]`"/>
500520
</x-admin::form.control-group>
501521
</x-admin::table.td>
502522
@@ -768,7 +788,7 @@ class="icon-delete cursor-pointer text-2xl"
768788
addProduct(result) {
769789
this.product.product_id = result.id;
770790
this.product.name = result.name;
771-
this.product.price = result.price;
791+
this.product.price = result.price ?? 0;
772792
this.product.quantity = result.quantity ?? 1;
773793
this.product.discount_amount = 0;
774794
this.product.tax_amount = 0;

0 commit comments

Comments
 (0)