Skip to content

Commit

Permalink
[ADD] fields for delivery.
Browse files Browse the repository at this point in the history
  • Loading branch information
Seiger committed Nov 22, 2024
1 parent ee439d3 commit 42c326c
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function up(): void
*/
Schema::create('s_products', function (Blueprint $table) {
$table->id('id');
$table->uuid('uuid')->default(DB::raw('(UUID())'));
$table->unsignedTinyInteger('published')->default(0)->index()->comment('0-Unpublished|1-Published');
$table->unsignedTinyInteger('availability')->default(0)->index()->comment('0-Not available|1-In stock|2-On order');
$table->string('sku')->index()->comment('It is the SKU Product code');
Expand All @@ -71,11 +72,15 @@ public function up(): void
$table->unsignedInteger('views')->default(0)->index()->comment('Count view the product');
$table->unsignedInteger('rating')->default(5)->index()->comment('Rating the product base on votes');
$table->unsignedInteger('type')->default(0)->comment('Type the product');
$table->unsignedDecimal('price_regular', 9, 2)->default(0);
$table->unsignedDecimal('price_special', 9, 2)->default(0);
$table->unsignedDecimal('price_opt_regular', 9, 2)->default(0);
$table->unsignedDecimal('price_opt_special', 9, 2)->default(0);
$table->unsignedDecimal('weight', 11, 4)->default(0);
$table->unsignedDecimal('price_regular', 9, 2)->default(0)->comment('The regular price of the product');
$table->unsignedDecimal('price_special', 9, 2)->default(0)->comment('The special price of the product');
$table->unsignedDecimal('price_opt_regular', 9, 2)->default(0)->comment('The wholesale price of the product');
$table->unsignedDecimal('price_opt_special', 9, 2)->default(0)->comment('The special wholesale price of the product');
$table->unsignedDecimal('weight', 11, 4)->default(0)->comment('The weight of production is indicated if necessary for technical purposes');
$table->unsignedDecimal('width', 11, 4)->default(0)->comment('The width of production is indicated if necessary for technical purposes');
$table->unsignedDecimal('height', 11, 4)->default(0)->comment('The height of production is indicated if necessary for technical needs');
$table->unsignedDecimal('length', 11, 4)->default(0)->comment('The length of production is indicated if necessary for technical needs');
$table->unsignedDecimal('volume', 11, 4)->default(0)->comment('The volume of production is indicated if necessary for technical needs');
$table->integer('quantity')->default(0)->comment('Quantity products in stock');
$table->char('currency', 3)->default('USD')->comment('Currency price this product');
$table->string('cover', 512)->default('')->comment('Cover image file link');
Expand Down
7 changes: 7 additions & 0 deletions lang/en/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"finish_configuring" => "Finish configuring the module according to the <strong><a href=\"https://seiger.github.io/sCommerce/getting-started/\" target=\"_blank\">instructions</a></strong>.",
"gallery" => "File gallery",
"gallery_help" => "The first image of the gallery is used as a product preview. You can sort the images by moving them with the mouse.",
"height" => "Height",
"helptext" => "Help text",
"helptext_help" => "Description about this Attribute in adminpanel.",
"icon" => "fa fa-store",
Expand All @@ -68,6 +69,7 @@
"items_on_page" => "Items on the page",
"key" => "Key",
"key_help" => "The key must have a unique value. Only lowercase Latin characters, numbers, and dashes are supported.",
"length" => "Length",
"list_texts" => "List of texts",
"main_currency" => "Main currency",
"main_currency_help" => "The store's base currency, which is default used.",
Expand Down Expand Up @@ -123,6 +125,7 @@
"published_help" => "Mark to publish immediately after saving.",
"publisheds" => "Published",
"quantity" => "Quantity",
"quantity_help" => "Shows the remaining stock of the product.",
"quantity_on_help" => "Enable the product balance functionality.",
"rating" => "Rating",
"rating_on_help" => "Enable product rating calculation functionality.",
Expand All @@ -149,6 +152,7 @@
"sortproducts_help" => "Sorting products by position in a category",
"sortproducts_icon" => "fa fa-sort",
"text_block" => "Text block",
"technical_parameter_for_delivery" => "technical parameter of the product that can be taken into account during delivery.",
"title" => "Commerce",
"to_list_attributes" => "To list attributes",
"to_list_products" => "To list products",
Expand Down Expand Up @@ -179,7 +183,10 @@
"views_on_help" => "Enable product views counter functionality.",
"visibility" => "Visibility",
"visual_editor_for" => "Visual editor for",
"volume" => "Volume",
"websites" => "Websites",
"weight" => "Weight",
"width" => "Width",
"with_id" => "With ID",
"you_sure" => "Are you sure?",
"you_sure_duplicate" => "Are you sure you want to duplicate?",
Expand Down
7 changes: 7 additions & 0 deletions lang/ru/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"finish_configuring" => "Завершите настройку модуля согласно <strong><a href=\"https://seiger.github.io/sCommerce/getting-started/\" target=\"_blank\">инструкции</a></strong>.",
"gallery" => "Галерея файлов",
"gallery_help" => "Первое изображение галереи используется в качестве превью товара. Вы можете сортировать изображение путем их перемещения мышкой.",
"height" => "Высота",
"helptext" => "Справочный текст",
"helptext_help" => "Описание этого атрибута в палитре администратора.",
"icon" => "fa fa-store",
Expand All @@ -68,6 +69,7 @@
"items_on_page" => "Записей на странице",
"key" => "Ключ",
"key_help" => "Ключ должен иметь уникальное значение. Поддерживаются только символы латинского алфавита в нижнем регистре, цифры и тире.",
"length" => "Длина",
"list_texts" => "Список текстов",
"main_currency" => "Основная валюта",
"main_currency_help" => "Базовая валюта магазина, которая используется по умолчанию.",
Expand Down Expand Up @@ -123,6 +125,7 @@
"published_help" => "Отметьте что бы опубликовать сразу после сохранения.",
"publisheds" => "Опубликованых",
"quantity" => "Остаток",
"quantity_help" => "Показывает остаток товара на складе.",
"quantity_on_help" => "Включить функционал остатка товаров.",
"rating" => "Рейтинг",
"rating_on_help" => "Включить функционал подсчета рейтинга продукта.",
Expand All @@ -149,6 +152,7 @@
"sortproducts_help" => "Сортировка товаров по позиции в категории",
"sortproducts_icon" => "fa fa-sort",
"text_block" => "Текстовый блок",
"technical_parameter_for_delivery" => "технический параметр товара, который можно учитывать при доставке.",
"title" => "Коммерция",
"to_list_attributes" => "К списку атрибутов",
"to_list_products" => "К списоку товаров",
Expand Down Expand Up @@ -179,7 +183,10 @@
"views_on_help" => "Включить функционал подсчета просмотров товара.",
"visibility" => "Видимость",
"visual_editor_for" => "Визуальный редактор для",
"volume" => "Объем",
"websites" => "Сайти",
"weight" => "Вес",
"width" => "Ширина",
"with_id" => "с ID",
"you_sure" => "Вы уверены, что хотите удалить запись",
"you_sure_copy" => "Вы уверены, что хотите скопировать запись",
Expand Down
7 changes: 7 additions & 0 deletions lang/uk/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"finish_configuring" => "Завершіть налаштування модуля згідно <strong><a href=\"https://seiger.github.io/sCommerce/getting-started/\" target=\"_blank\">інструкції</a></strong>.",
"gallery" => "Галерея файлів",
"gallery_help" => "Перше зображення галереї використовується в якості превю товара. Ви маєте можливість сортувати зображення шляхом їх переміщення мишкою.",
"height" => "Висота",
"helptext" => "Довідковий текст",
"helptext_help" => "Опис цього атрибута в панелі адміністратора.",
"icon" => "fa fa-store",
Expand All @@ -68,6 +69,7 @@
"items_on_page" => "Записів на сторінці",
"key" => "Ключ",
"key_help" => "Ключ має мати унікальне значення. Підтримуються лише символи латинського алфавіту в нижньому регістрі, цифри та тире.",
"length" => "Довжина",
"list_texts" => "Список текстів",
"main_currency" => "Основна валюта",
"main_currency_help" => "Базова валюта магазину, що використовується типово.",
Expand Down Expand Up @@ -123,6 +125,7 @@
"published_help" => "Відзначте, щоб опублікувати відразу після збереження.",
"publisheds" => "Опублікованих",
"quantity" => "Залишок",
"quantity_help" => "Показує залишок товару на складі.",
"quantity_on_help" => "Ввімкнути функціонал залишку товарів.",
"rating" => "Рейтинг",
"rating_on_help" => "Ввімкнути функціонал підрахунку рейтингу товара.",
Expand All @@ -148,6 +151,7 @@
"sortproducts" => "Сортування за позицією",
"sortproducts_help" => "Сортування товарів за позицією в категорії ",
"sortproducts_icon" => "fa fa-sort",
"technical_parameter_for_delivery" => "технічний параметр товару, який можна враховувати під час доставки.",
"text_block" => "Текстовий блок",
"title" => "Комерція",
"to_list_attributes" => "До списку атрибутів",
Expand Down Expand Up @@ -179,7 +183,10 @@
"views_on_help" => "Ввімкнути функціонал підрахунку переглядів товару.",
"visibility" => "Видимість",
"visual_editor_for" => "Візуальний редактор для",
"volume" => "Об'єм",
"websites" => "Сайти",
"weight" => "Вага",
"width" => "Ширина",
"with_id" => "з ID",
"you_sure" => "Ви впевнені, що хочете видалити запис",
"you_sure_copy" => "Ви впевнені, що хочете скопіювати запис",
Expand Down
10 changes: 9 additions & 1 deletion module/sCommerceModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@
$product->price_opt_regular = $sCommerceController->validatePrice(request()->input('price_opt_regular', 0));
$product->price_opt_special = $sCommerceController->validatePrice(request()->input('price_opt_special', 0));
$product->currency = request()->input('currency', sCommerce::config('basic.main_currency', 'USD'));
$product->weight = (float)request()->input('weight', 0);
$product->weight = $sCommerceController->validateNumber(request()->input('weight', 0));
$product->width = $sCommerceController->validateNumber(request()->input('width', 0));
$product->height = $sCommerceController->validateNumber(request()->input('height', 0));
$product->length = $sCommerceController->validateNumber(request()->input('length', 0));
$product->volume = $sCommerceController->validateNumber(request()->input('volume', 0));
$product->cover = str_replace(MODX_SITE_URL, '', $cover->src ?? '/assets/site/noimage.png');
$product->relevants = json_encode(request()->input('relevants', []));
$product->similar = json_encode(request()->input('similar', []));
Expand Down Expand Up @@ -344,6 +348,10 @@
$newProduct->price_opt_special = $product->price_opt_special;
$newProduct->currency = $product->currency;
$newProduct->weight = $product->weight;
$newProduct->width = $product->width;
$newProduct->height = $product->height;
$newProduct->length = $product->length;
$newProduct->volume = $product->volume;
$newProduct->cover = $product->cover;
$newProduct->relevants = $product->relevants;
$newProduct->similar = $product->similar;
Expand Down
18 changes: 18 additions & 0 deletions src/Controllers/sCommerceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,24 @@ public function removeDirRecursive(string $dir): void
rmdir($dir);
}

/**
* Validate and sanitize a number value.
*
* @param mixed $number The number value to be validated.
* @return int|float The validated and sanitized price value.
*/
public function validateNumber(mixed $number): int|float
{
$validateNumber = 0;
$number = str_replace(',', '.', $number);

if (is_numeric($number)) {
$number = intval($number) == floatval($number) ? intval($number) : floatval($number);
}

return $number;
}

/**
* Validate and sanitize a price value.
*
Expand Down
77 changes: 72 additions & 5 deletions views/productTab.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
<div class="row form-row">
<div class="col-auto col-title">
<label for="quantity">@lang('sCommerce::global.quantity')</label>
<i class="fa fa-question-circle" data-tooltip="@lang('sCommerce::global.sku_help')"></i>
<i class="fa fa-question-circle" data-tooltip="@lang('sCommerce::global.quantity_help')"></i>
</div>
<div class="col">
<input id="quantity" class="form-control" name="quantity" value="{{$item->quantity ?? ''}}" onblur="documentDirty=true;">
Expand Down Expand Up @@ -232,10 +232,7 @@
</div>
</div>
@endif
</div>
<div class="split my-3"></div>
<div class="row form-row">
@if(sCommerce::config('product.show_field_relevant', 1) == 1)
@if(sCommerce::config('product.show_field_relevant', 1))
<div class="row-col col-lg-6 col-md-6 col-12">
<div class="row form-row">
<div class="col-auto col-title">
Expand All @@ -255,6 +252,76 @@
</div>
@endif
</div>
@if(sCommerce::config('product.show_field_weight', 1) || sCommerce::config('product.show_field_width', 1) || sCommerce::config('product.show_field_height', 1) || sCommerce::config('product.show_field_length', 1) || sCommerce::config('product.show_field_volume', 1))
<div class="split my-3"></div>
<div class="row form-row">
@if(sCommerce::config('product.show_field_weight', 1))
<div class="row-col col-lg-3 col-md-6 col-12">
<div class="row form-row">
<div class="col-auto col-title">
<label for="weight">@lang('sCommerce::global.weight')</label>
<i class="fa fa-question-circle" data-tooltip="@lang('sCommerce::global.weight') - @lang('sCommerce::global.technical_parameter_for_delivery')"></i>
</div>
<div class="col">
<input id="weight" class="form-control" name="weight" value="{{round($item->weight ?? 0, 4)}}" onblur="documentDirty=true;">
</div>
</div>
</div>
@endif
@if(sCommerce::config('product.show_field_width', 1))
<div class="row-col col-lg-3 col-md-6 col-12">
<div class="row form-row">
<div class="col-auto col-title">
<label for="width">@lang('sCommerce::global.width')</label>
<i class="fa fa-question-circle" data-tooltip="@lang('sCommerce::global.width') - @lang('sCommerce::global.technical_parameter_for_delivery')"></i>
</div>
<div class="col">
<input id="width" class="form-control" name="width" value="{{round($item->width ?? 0, 4)}}" onblur="documentDirty=true;">
</div>
</div>
</div>
@endif
@if(sCommerce::config('product.show_field_height', 1))
<div class="row-col col-lg-3 col-md-6 col-12">
<div class="row form-row">
<div class="col-auto col-title">
<label for="height">@lang('sCommerce::global.height')</label>
<i class="fa fa-question-circle" data-tooltip="@lang('sCommerce::global.height') - @lang('sCommerce::global.technical_parameter_for_delivery')"></i>
</div>
<div class="col">
<input id="height" class="form-control" name="height" value="{{round($item->height ?? 0, 4)}}" onblur="documentDirty=true;">
</div>
</div>
</div>
@endif
@if(sCommerce::config('product.show_field_length', 1))
<div class="row-col col-lg-3 col-md-6 col-12">
<div class="row form-row">
<div class="col-auto col-title">
<label for="length">@lang('sCommerce::global.length')</label>
<i class="fa fa-question-circle" data-tooltip="@lang('sCommerce::global.length') - @lang('sCommerce::global.technical_parameter_for_delivery')"></i>
</div>
<div class="col">
<input id="length" class="form-control" name="length" value="{{round($item->length ?? 0, 4)}}" onblur="documentDirty=true;">
</div>
</div>
</div>
@endif
@if(sCommerce::config('product.show_field_volume', 1))
<div class="row-col col-lg-3 col-md-6 col-12">
<div class="row form-row">
<div class="col-auto col-title">
<label for="volume">@lang('sCommerce::global.volume')</label>
<i class="fa fa-question-circle" data-tooltip="@lang('sCommerce::global.volume') - @lang('sCommerce::global.technical_parameter_for_delivery')"></i>
</div>
<div class="col">
<input id="volume" class="form-control" name="volume" value="{{round($item->volume ?? 0, 4)}}" onblur="documentDirty=true;">
</div>
</div>
</div>
@endif
</div>
@endif
</div>
@php($mainAttributes = sCommerce::config('constructor.main_product', []))
@if(count($mainAttributes))
Expand Down
Loading

0 comments on commit 42c326c

Please sign in to comment.