Skip to content

Commit

Permalink
Merge pull request #1908 from amit-webkul/product-price-validation
Browse files Browse the repository at this point in the history
🛠️ [v2.0] : Fixed Issue #1786
  • Loading branch information
devansh-webkul authored Jan 13, 2025
2 parents 172f201 + 526e7b9 commit 0daf1e4
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
<x-admin::form.control-group.control
type="text"
:id="$attribute->code"
:name="$attribute->code"
:value="old($attribute->code) ?? $value"
:rules="$validations"
:label="$attribute->name"
/>
@if (isset($attribute))
<v-price-component
:attribute="{{ json_encode($attribute) }}"
:validations="'{{ $validations }}'"
:value="{{ json_encode(old($attribute->code) ?? $value) }}"
>
</v-price-component>
@endif

@pushOnce('scripts')
<script
type="text/x-template"
id="v-price-component-template"
>
<x-admin::form.control-group.control
type="text"
::id="attribute.code"
::value="value"
::name="attribute.code"
::rules="getValidation"
::label="attribute.name"
/>
</script>

<script type="module">
app.component('v-price-component', {
template: '#v-price-component-template',
props: ['validations', 'attribute', 'value'],
computed: {
getValidation() {
return {
numeric: true,
...(this.validations === 'required' ? { required: true } : {}),
};
},
},
});
</script>
@endPushOnce
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
$validations = implode('|', array_filter($validations));
}
@endphp

<x-admin::form.control-group class="mb-2.5 w-full">
<x-admin::form.control-group.label
for="{{ $attribute->code }}"
Expand Down
2 changes: 1 addition & 1 deletion packages/Webkul/Core/src/Contracts/Validations/Code.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public function passes($attribute, $value)
*/
public function message()
{
return trans('This value must be valid.');
return trans('core::app.validations.code');
}
}
2 changes: 1 addition & 1 deletion packages/Webkul/Core/src/Contracts/Validations/Decimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public function passes($attribute, $value)
*/
public function message()
{
return trans('core::validation.decimal');
return trans('core::app.validations.decimal');
}
}
2 changes: 0 additions & 2 deletions packages/Webkul/Core/src/Providers/CoreServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public function boot()

$this->loadTranslationsFrom(__DIR__.'/../Resources/lang', 'core');

$this->loadViewsFrom(__DIR__.'/../Resources/views', 'core');

$this->publishes([
dirname(__DIR__).'/Config/concord.php' => config_path('concord.php'),
dirname(__DIR__).'/Config/cors.php' => config_path('cors.php'),
Expand Down
8 changes: 8 additions & 0 deletions packages/Webkul/Core/src/Resources/lang/ar/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'validations' => [
'code' => 'يجب أن يكون الحقل رمزًا صالحًا.',
'decimal' => 'يجب أن يكون الحقل رقمًا عشريًا.',
],
];
8 changes: 8 additions & 0 deletions packages/Webkul/Core/src/Resources/lang/en/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'validations' => [
'code' => 'The field must be a valid code.',
'decimal' => 'The field must be a decimal number.',
],
];
8 changes: 8 additions & 0 deletions packages/Webkul/Core/src/Resources/lang/es/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'validations' => [
'code' => 'El campo debe ser un código válido.',
'decimal' => 'El campo debe ser un número decimal.',
],
];
8 changes: 8 additions & 0 deletions packages/Webkul/Core/src/Resources/lang/fa/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'validations' => [
'code' => 'این فیلد باید یک کد معتبر باشد.',
'decimal' => 'این فیلد باید یک عدد اعشاری باشد.',
],
];
8 changes: 8 additions & 0 deletions packages/Webkul/Core/src/Resources/lang/pt_BR/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'validations' => [
'code' => 'O campo deve ser um código válido.',
'decimal' => 'O campo deve ser um número decimal.',
],
];
8 changes: 8 additions & 0 deletions packages/Webkul/Core/src/Resources/lang/tr/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'validations' => [
'code' => 'Alan geçerli bir kod olmalıdır.',
'decimal' => 'Alan ondalık bir sayı olmalıdır.',
],
];
8 changes: 8 additions & 0 deletions packages/Webkul/Core/src/Resources/lang/vi/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'validations' => [
'code' => 'Trường phải là một mã hợp lệ.',
'decimal' => 'Trường phải là một số thập phân.',
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public function run($parameters = [])
], [
'code' => 'price',
'name' => trans('installer::app.seeders.attributes.products.price', [], $defaultLocale),
'type' => 'text',
'type' => 'price',
'entity_type' => 'products',
'lookup_type' => null,
'validation' => 'decimal',
Expand Down

0 comments on commit 0daf1e4

Please sign in to comment.