Skip to content

Commit

Permalink
fix: fixed all the mentioned issues
Browse files Browse the repository at this point in the history
  • Loading branch information
devansh-webkul committed Dec 18, 2024
1 parent f0ee070 commit 7075bf0
Show file tree
Hide file tree
Showing 26 changed files with 91 additions and 17 deletions.
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/ar/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@

'update-create' => [
'is-required' => 'مطلوب',
'max-characters' => 'الحد الأقصى للأحرف',
'name' => 'العنوان',
'no' => 'لا',
'price' => 'السعر',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/bn/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@

'update-create' => [
'is-required' => 'প্রয়োজনীয়',
'max-characters' => 'সর্বোচ্চ অক্ষর',
'name' => 'শিরোনাম',
'no' => 'না',
'price' => 'মূল্য',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/de/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@

'update-create' => [
'is-required' => 'Erforderlich',
'max-characters' => 'Maximale Zeichen',
'name' => 'Titel',
'no' => 'Nein',
'price' => 'Preis',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@

'update-create' => [
'is-required' => 'Is Required',
'max-characters' => 'Max Characters',
'name' => 'Title',
'no' => 'No',
'price' => 'Price',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/es/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@

'update-create' => [
'is-required' => 'Es obligatorio',
'max-characters' => 'Máximo de caracteres',
'name' => 'Título',
'no' => 'No',
'price' => 'Precio',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/fa/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@

'update-create' => [
'is-required' => 'الزامی است',
'max-characters' => 'حداکثر کاراکتر',
'name' => 'عنوان',
'no' => 'خیر',
'price' => 'قیمت',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/fr/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@

'update-create' => [
'is-required' => 'Est requis',
'max-characters' => 'Nombre maximum de caractères',
'name' => 'Titre',
'no' => 'Non',
'price' => 'Prix',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/he/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@

'update-create' => [
'is-required' => 'נדרש',
'max-characters' => 'מקסימום תווים',
'name' => 'כותרת',
'no' => 'לא',
'price' => 'מחיר',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/hi_IN/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@

'update-create' => [
'is-required' => 'आवश्यक है',
'max-characters' => 'अधिकतम वर्ण',
'name' => 'शीर्षक',
'no' => 'नहीं',
'price' => 'मूल्य',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/it/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@

'update-create' => [
'is-required' => 'È richiesto',
'max-characters' => 'Caratteri Massimi',
'name' => 'Titolo',
'no' => 'No',
'price' => 'Prezzo',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/ja/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@

'update-create' => [
'is-required' => '必須',
'max-characters' => '最大文字数',
'name' => 'タイトル',
'no' => 'いいえ',
'price' => '価格',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/nl/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@

'update-create' => [
'is-required' => 'Is verplicht',
'max-characters' => 'Max. aantal tekens',
'name' => 'Titel',
'no' => 'Nee',
'price' => 'Prijs',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/pl/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@

'update-create' => [
'is-required' => 'Wymagane',
'max-characters' => 'Maksymalna liczba znaków',
'name' => 'Tytuł',
'no' => 'Nie',
'price' => 'Cena',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/pt_BR/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@

'update-create' => [
'is-required' => 'É obrigatório',
'max-characters' => 'Máximo de caracteres',
'name' => 'Título',
'no' => 'Não',
'price' => 'Preço',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/ru/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@

'update-create' => [
'is-required' => 'Обязательно',
'max-characters' => 'Максимальное количество символов',
'name' => 'Название',
'no' => 'Нет',
'price' => 'Цена',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/sin/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@

'update-create' => [
'is-required' => 'අවශ්‍යයි',
'max-characters' => 'උපරිම අකුරු',
'name' => 'ශීර්ෂය',
'no' => 'නැත',
'price' => 'මිල',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/tr/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@

'update-create' => [
'is-required' => 'Gerekli mi',
'max-characters' => 'Maksimum Karakter',
'name' => 'Başlık',
'no' => 'Hayır',
'price' => 'Fiyat',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/uk/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@

'update-create' => [
'is-required' => 'Необхідно',
'max-characters' => 'Максимальна кількість символів',
'name' => 'Назва',
'no' => 'Ні',
'price' => 'Ціна',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/zh_CN/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@

'update-create' => [
'is-required' => '是否必填',
'max-characters' => '最大字符数',
'name' => '标题',
'no' => '否',
'price' => '价格',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ class="grid"
:value="index"
/>

<input
type="hidden"
:name="'customizable_options[' + element.id + '][max_characters]'"
:value="element.max_characters"
v-if="! canHaveMultiplePrices(element.type)"
/>

<input
type="hidden"
:name="'customizable_options[' + element.id + '][supported_file_extensions]'"
Expand Down Expand Up @@ -297,7 +304,23 @@ class="secondary-button text-sm"
</div>

<template v-if="! canHaveMultiplePrices(selectedOption.type)">
<x-admin::form.control-group v-if="selectedOption.type == 'file'">
<x-admin::form.control-group v-if="['text', 'textarea'].includes(selectedOption.type)">
<x-admin::form.control-group.label class="required">
@lang('admin::app.catalog.products.edit.types.simple.customizable-options.update-create.max-characters')
</x-admin::form.control-group.label>

<x-admin::form.control-group.control
type="text"
name="max_characters"
rules="required|numeric|min_value:1"
::value="selectedOption.max_characters"
:label="trans('admin::app.catalog.products.edit.types.simple.customizable-options.update-create.max-characters')"
/>

<x-admin::form.control-group.error control-name="max_characters" />
</x-admin::form.control-group>

<x-admin::form.control-group v-else-if="selectedOption.type == 'file'">
<x-admin::form.control-group.label class="required">
@lang('admin::app.catalog.products.edit.types.simple.customizable-options.update-create.supported-file-extensions')
</x-admin::form.control-group.label>
Expand All @@ -321,7 +344,7 @@ class="secondary-button text-sm"
<x-admin::form.control-group.control
type="price"
name="price"
rules="required"
rules="required|decimal|min_value:0"
::value="selectedOption.price"
:label="trans('admin::app.catalog.products.edit.types.simple.customizable-options.update-create.price')"
/>
Expand Down Expand Up @@ -556,7 +579,7 @@ class="secondary-button text-sm"
type="price"
name="price"
::value="selectedOptionItem.price"
rules="required"
rules="required|decimal|min_value:0"
:label="trans('admin::app.catalog.products.edit.types.simple.customizable-options.option.items.update-create.price')"
/>

Expand Down Expand Up @@ -655,6 +678,7 @@ class="primary-button"
label: '',
type: 'select',
is_required: 1,
max_characters: null,
supported_file_extensions: null,
price: 0,
},
Expand All @@ -669,6 +693,7 @@ class="primary-button"
label: option.label,
type: option.type,
is_required: option.is_required,
max_characters: option.max_characters,
supported_file_extensions: option.supported_file_extensions,
price_id: option.customizable_option_prices[0].id,
price: option.customizable_option_prices[0].price,
Expand All @@ -681,6 +706,7 @@ class="primary-button"
label: option.label,
type: option.type,
is_required: option.is_required,
max_characters: option.max_characters,
supported_file_extensions: option.supported_file_extensions,
price: 0,
customizable_option_prices: option.customizable_option_prices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function up()
$table->integer('product_id')->unsigned();
$table->string('type');
$table->boolean('is_required')->default(1);
$table->text('max_characters')->nullable();
$table->text('supported_file_extensions')->nullable();
$table->integer('sort_order')->default(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ProductCustomizableOption extends TranslatableModel implements ProductCust
*/
protected $fillable = [
'is_required',
'max_characters',
'product_id',
'sort_order',
'supported_file_extensions',
Expand Down
27 changes: 21 additions & 6 deletions packages/Webkul/Product/src/Type/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,13 @@ public function getAdditionalOptions($data)
if (in_array($option['type'], ['checkbox', 'multiselect'])) {
$data['attributes'][] = [
'attribute_type' => $option['type'],
'attribute_name' => $option['label'][app()->getLocale()],
'attribute_name' => $option['label'][app()->getLocale()] ?? $option['label'][app()->getFallbackLocale()],
'option_label' => collect($option['prices'])->pluck('label')->join(', ', ' and '),
];
} else {
$data['attributes'][] = [
'attribute_type' => $option['type'],
'attribute_name' => $option['label'][app()->getLocale()],
'attribute_name' => $option['label'][app()->getLocale()] ?? $option['label'][app()->getFallbackLocale()],
'option_label' => $option['prices'][0]['label'],
];
}
Expand Down Expand Up @@ -412,16 +412,16 @@ protected function formatRequestedCustomizableOptions(array $requestedCustomizab
->get();

foreach ($customizableOptions as $customizableOption) {
if (! $customizableOption->is_required && empty($requestedCustomizableOptions[$customizableOption->id])) {
continue;
}

switch ($customizableOption->type) {
case 'text':
case 'textarea':
case 'date':
case 'datetime':
case 'time':
if (! $customizableOption->is_required && empty($requestedCustomizableOptions[$customizableOption->id][0])) {
continue 2;
}

$optionPrice = $customizableOption->customizable_option_prices->first();

$formattedCustomizableOptions[] = [
Expand All @@ -442,6 +442,17 @@ protected function formatRequestedCustomizableOptions(array $requestedCustomizab
case 'radio':
case 'select':
case 'multiselect':
if (! $customizableOption->is_required && empty($requestedCustomizableOptions[$customizableOption->id])) {
continue 2;
}

/**
* If the option is not required and the user has selected the `None` option, then we will skip this option.
*/
if (in_array(0, $requestedCustomizableOptions[$customizableOption->id])) {
continue 2;
}

$optionPrices = $customizableOption->customizable_option_prices
->whereIn('id', $requestedCustomizableOptions[$customizableOption->id]);

Expand All @@ -460,6 +471,10 @@ protected function formatRequestedCustomizableOptions(array $requestedCustomizab
break;

case 'file':
if (! $customizableOption->is_required && empty($requestedCustomizableOptions[$customizableOption->id][0])) {
continue 2;
}

$optionPrice = $customizableOption->customizable_option_prices->first();

/**
Expand Down
16 changes: 12 additions & 4 deletions packages/Webkul/Product/src/Type/Virtual.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,16 +435,16 @@ protected function formatRequestedCustomizableOptions(array $requestedCustomizab
->get();

foreach ($customizableOptions as $customizableOption) {
if (! $customizableOption->is_required && empty($requestedCustomizableOptions[$customizableOption->id])) {
continue;
}

switch ($customizableOption->type) {
case 'text':
case 'textarea':
case 'date':
case 'datetime':
case 'time':
if (! $customizableOption->is_required && empty($requestedCustomizableOptions[$customizableOption->id][0])) {
continue 2;
}

$optionPrice = $customizableOption->customizable_option_prices->first();

$formattedCustomizableOptions[] = [
Expand All @@ -465,6 +465,10 @@ protected function formatRequestedCustomizableOptions(array $requestedCustomizab
case 'radio':
case 'select':
case 'multiselect':
if (! $customizableOption->is_required && empty($requestedCustomizableOptions[$customizableOption->id])) {
continue 2;
}

$optionPrices = $customizableOption->customizable_option_prices
->whereIn('id', $requestedCustomizableOptions[$customizableOption->id]);

Expand All @@ -483,6 +487,10 @@ protected function formatRequestedCustomizableOptions(array $requestedCustomizab
break;

case 'file':
if (! $customizableOption->is_required && empty($requestedCustomizableOptions[$customizableOption->id][0])) {
continue 2;
}

$optionPrice = $customizableOption->customizable_option_prices->first();

/**
Expand Down
Loading

0 comments on commit 7075bf0

Please sign in to comment.