Skip to content

Commit

Permalink
[ADD] Product save.
Browse files Browse the repository at this point in the history
  • Loading branch information
Seiger committed Jan 6, 2024
1 parent 5234d2f commit 2d78da9
Show file tree
Hide file tree
Showing 19 changed files with 785 additions and 298 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"php": "^8",
"php": "^8.1",
"seiger/sgallery": "*"
},
"autoload": {
Expand Down
31 changes: 30 additions & 1 deletion config/sCommerceSettings.php
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
<?php return [];
<?php return [
"basic" => [
"catalog_root" => 1,
"in_main_menu" => 1,
"main_menu_order" => 11,
"orders_on" => 0,
],
"product" => [
"link_rule" => "root",
"quantity_on" => 0,
"rating_on" => 0,
"show_field_availability" => 0,
"show_field_price" => 1,
"show_field_sku" => 1,
"views_on" => 1,
],
"products" => [
"show_field_availability" => 1,
"show_field_category" => 1,
"show_field_id" => 1,
"show_field_price" => 1,
"show_field_price_opt" => 0,
"show_field_price_opt_special" => 0,
"show_field_price_special" => 0,
"show_field_quantity" => 0,
"show_field_sku" => 1,
"show_field_views" => 1,
"show_field_visibility" => 1,
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public function up(): void
$table->unsignedInteger('views')->default(0)->comment('Count view the product');
$table->integer('quantity')->default(0)->comment('Quantity products in stock');
$table->unsignedDecimal('price_regular', 9, 2)->default(0);
$table->unsignedDecimal('price_special', 9, 2)->nullable();
$table->unsignedDecimal('price_special', 9, 2)->default(0);
$table->unsignedDecimal('price_opt_regular', 9, 2)->default(0);
$table->unsignedDecimal('price_opt_special', 9, 2)->nullable();
$table->unsignedDecimal('weight', 11, 4)->default(0.00);
$table->unsignedDecimal('price_opt_special', 9, 2)->default(0);
$table->unsignedDecimal('weight', 11, 4)->default(0);
$table->string('cover', 512)->default('')->comment('Cover image file link');
$table->jsonb('relevants')->default(new Expression('(JSON_ARRAY())'));
$table->jsonb('similar')->default(new Expression('(JSON_ARRAY())'));
Expand Down
14 changes: 14 additions & 0 deletions lang/en/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,18 @@
'price_help' => 'The main price of the product is in the currency of the store.',
'categories' => 'Categories',
'categories_help' => 'List of categories in which the product should be displayed. Formed from the resource tree from the root, which is designated as a directory. If a subcategory is selected, the product will be displayed in all higher categories.',
'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.',
'content' => 'Content',
'management_product_functionality' => 'Product functionality management',
'views_on_help' => 'Enable the function of counting product views.',
'rating_on_help' => 'Enable product rating calculation functionality.',
'quantity_on_help' => 'Enable the product balance functionality.',
'orders_on' => 'Order',
'orders_on_help' => 'Enable the functionality of orders on the site.',
'product_link' => 'Link to the product',
'product_link_rule_help' => 'Choose a rule for forming a link to the product.',
'product_link_rule_root' => 'from the root of the site',
'product_link_rule_catalog' => 'from the root of catalog directory',
'product_link_rule_category' => 'from the product category',
];
14 changes: 14 additions & 0 deletions lang/ru/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,18 @@
'price_help' => 'Основная стоимость товара в валюте магазина.',
'categories' => 'Категории',
'categories_help' => 'Список категорий в которых должен отображаться товар. Формируется из дерева ресурсов от корня, который обозначен как каталог. Если выбрана подкатегория - товар будет отображен во всех вышестоящих категориях.',
'gallery' => 'Галерея файлов',
'gallery_help' => 'Первое изображение галереи используется в качестве превью товара. Вы можете сортировать изображение путем их перемещения мышкой.',
'content' => 'Контент',
'management_product_functionality' => 'Управление функционалом товара',
'views_on_help' => 'Включить функционал подсчета просмотров товара.',
'rating_on_help' => 'Включить функционал подсчета рейтинга продукта.',
'quantity_on_help' => 'Включить функционал остатка товаров.',
'orders_on' => 'Заказ',
'orders_on_help' => 'Включите функционал заказов на сайте.',
'product_link' => 'Ссылка на товар',
'product_link_rule_help' => 'Выберите правило для формирования ссылки на товар.',
'product_link_rule_root' => 'от корня сайта',
'product_link_rule_catalog' => 'от корня каталога',
'product_link_rule_category' => 'от категории товара',
];
14 changes: 14 additions & 0 deletions lang/uk/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,18 @@
'price_help' => 'Основна ціна товару в валюті магазину.',
'categories' => 'Категорії',
'categories_help' => 'Список категорій, у яких повинен відображатися товар. Формується із дерева ресурсів від кореня, який позначено як каталог. Якщо обрано підкатегорію - товар буде відображено у всіх батьківських категоріях.',
'gallery' => 'Галерея файлів',
'gallery_help' => 'Перше зображення галереї використовується в якості превю товара. Ви маєте можливість сортувати зображення шляхом їх переміщення мишкою.',
'content' => 'Контент',
'management_product_functionality' => 'Керування функціоналом товару',
'views_on_help' => 'Ввімкнути функціонал підрахунку переглядів товару.',
'rating_on_help' => 'Ввімкнути функціонал підрахунку рейтингу товара.',
'quantity_on_help' => 'Ввімкнути функціонал залишку товарів.',
'orders_on' => 'Замовлення',
'orders_on_help' => 'Ввімкнути функціонал замовлень на сайті.',
'product_link' => 'Посилання на товар',
'product_link_rule_help' => 'Оберіть правило для формування посилання на товар.',
'product_link_rule_root' => 'від корня сайту',
'product_link_rule_catalog' => 'від корня каталогу',
'product_link_rule_category' => 'від категорії товару',
];
107 changes: 102 additions & 5 deletions module/sCommerceModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,138 @@
* E-commerce management module
*/

use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\Cookie;
use Seiger\sCommerce\Controllers\sCommerceController;
use Seiger\sCommerce\Facades\sCommerce;
use Seiger\sCommerce\Models\sProduct;
use Seiger\sCommerce\Models\sProductTranslate;
use Seiger\sGallery\Facades\sGallery;

if (!defined('IN_MANAGER_MODE') || IN_MANAGER_MODE != 'true') die("No access");
if (!file_exists(EVO_CORE_PATH . 'custom/config/seiger/settings/sCommerce.php')) {
evo()->webAlertAndQuit(__('sCommerce::global.finish_configuring'), "index.php?a=2");
}

$sCommerceController = new sCommerceController();
$get = request()->get ?? "orders";
Paginator::defaultView('sCommerce::partials.pagination');
$get = request()->get ?? (sCommerce::config('basic.orders_on', 1) == 1 ? "orders" : "products");
$editor = '';

$tabs = ['products'];
if (evo()->hasPermission('settings')) {
$tabs[] = 'settings';
}

switch ($get) {
/*
|--------------------------------------------------------------------------
| Orders
|--------------------------------------------------------------------------
*/
default:
case "orders":
break;
/*
|--------------------------------------------------------------------------
| Products
|--------------------------------------------------------------------------
*/
case "products":
$perpage = Cookie::get('scom_products_page_items', 50);
$order = request()->input('order', 'id');
$direc = request()->input('direc', 'desc');

$data['items'] = sProduct::orderBy($order, $direc)->paginate($perpage);
break;
/*
|--------------------------------------------------------------------------
| Product
|--------------------------------------------------------------------------
*/
case "product":
$tabs = ['product'];
$tabs = ['product', 'content'];
$product = sCommerce::getProduct((int)request()->input('i', 0));
//dd($product);
$data['categories'] = [];
$data['product'] = $product;
break;
case "productSave":
$requestId = (int)request()->input('i', 0);
$alias = request()->input('alias', 'new-product');
$product = sCommerce::getProduct($requestId);

$votes = data_is_json($product->votes ?? '', true);
$type = $product->type ?: 'simple';
$cover = sGallery::first('product', $requestId);

if (empty($alias)) {
$translate = sProductTranslate::whereProduct($requestId)
->whereIn('lang', ['en', $sCommerceController->langDefault()])->orderByRaw('FIELD(lang, "en", "' . $sCommerceController->langDefault() . '")')
->first();
if ($translate) {
$alias = $translate->pagetitle;
} else {
$alias = 'new-product';
}
}

if (!$votes) {
$votes = [];
$votes['total'] = 1;
$votes['1'] = 0;
$votes['2'] = 0;
$votes['3'] = 0;
$votes['3'] = 0;
$votes['4'] = 0;
$votes['5'] = 1;
}

$product->published = (int)request()->input('published', 0);
$product->availability = (int)request()->input('availability', 0);
$product->category = (int)request()->input('parent', sCommerce::config('basic.catalog_root', evo()->getConfig('site_start', 1)));
$product->sku = request()->input('sku', '');
$product->alias = $sCommerceController->validateAlias($alias, (int)$product->id);
$product->position = (int)request()->input('position', 0);
$product->quantity = (int)request()->input('quantity', 0);
$product->price_regular = $sCommerceController->validatePrice(request()->input('price_regular', 0));
$product->price_special = $sCommerceController->validatePrice(request()->input('price_special', 0));
$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->weight = (float)request()->input('weight', 0);
$product->cover = $cover->src ?? '/assets/site/noimage.png';
$product->relevants = json_encode(request()->input('relevants', []));
$product->similar = json_encode(request()->input('similar', []));
$product->tmplvars = json_encode(request()->input('tmplvars', []));
$product->votes = json_encode($votes);
$product->type = $type;
$product->save();

$product->categories()->sync((array)request()->input('categories', []));

if (!$product->texts->count()) {
$product->texts()->create(['lang' => $sCommerceController->langDefault()]);
}

$sCommerceController->setProductsListing();
$back = str_replace('&i=0', '&i=' . $product->id, (request()->back ?? '&get=product'));
return header('Location: ' . sCommerce::moduleUrl() . $back);
break;
/*
|--------------------------------------------------------------------------
| Settings
|--------------------------------------------------------------------------
*/
case "settings":
if (!evo()->hasPermission('settings')) {
$back = request()->back ?? '&get=orders';
return header('Location: ' . sCommerce::moduleUrl() . $back);
}
break;
case "settingsSave":
$sCommerceController->saveBasicConfigs();

$sCommerceController->updateDBConfigs();
$sCommerceController->updateFileConfigs();
evo()->clearCache('full');
sleep(5);

session()->flash('success', __('sCommerce::global.settings_save_success'));
$back = request()->back ?? '&get=settings';
Expand Down
8 changes: 4 additions & 4 deletions plugins/sCommercePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Add Menu item
*/
Event::listen('evolution.OnManagerMenuPrerender', function($params) {
if (evo()->getConfig('scom_in_main_menu', 0) == 1) {
if (sCommerce::config('basic.in_main_menu', 0) == 1) {
$menu['scommerce'] = [
'scommerce',
'main',
Expand All @@ -22,7 +22,7 @@
"",
"main",
0,
evo()->getConfig('scom_main_menu_order', 11),
sCommerce::config('basic.main_menu_order', 11),
];

return serialize(array_merge($params['menu'], $menu));
Expand All @@ -33,9 +33,9 @@
* Add icon to tree
*/
Event::listen('evolution.OnManagerNodePrerender', function($params) {
if (evo()->getConfig('scom_catalog_root', 0) > 1) {
if (sCommerce::config('basic.catalog_root', 0) > 1) {
switch ($params['ph']['id']) {
case evo()->getConfig('scom_catalog_root') :
case sCommerce::config('basic.catalog_root') :
$params['ph']['icon'] = '<i class="' . __('sCommerce::global.icon') . '"></i>';
$params['ph']['icon_folder_open'] = "<i class='" . __('sCommerce::global.icon') . "'></i>";
$params['ph']['icon_folder_close'] = "<i class='" . __('sCommerce::global.icon') . "'></i>";
Expand Down
Loading

0 comments on commit 2d78da9

Please sign in to comment.