From: fomichev Date: Fri, 22 Nov 2024 15:31:40 +0000 (+0300) Subject: Вывод доп свойств X-Git-Tag: 1.7~212^2~14 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=381842392e1b446edfcf2b3a7c9df6b62a941de7;p=erp24_rep%2Fyii-erp24%2F.git Вывод доп свойств --- diff --git a/erp24/controllers/ProductsController.php b/erp24/controllers/ProductsController.php index 5cdd39e5..7601c844 100755 --- a/erp24/controllers/ProductsController.php +++ b/erp24/controllers/ProductsController.php @@ -8,7 +8,9 @@ use yii\helpers\Html; use yii\web\Controller; use yii_app\records\ExportImportTable; use yii_app\records\Prices; +use yii_app\records\Product1cPropType; use yii_app\records\Products1c; +use yii_app\records\Products1cAdditionalCharacteristics; use yii_app\records\Products1cOptions; use yii_app\records\ProductsClass; use yii_app\records\ProductsVarieties; @@ -66,6 +68,9 @@ class ProductsController extends Controller } + + // Старый функционал + //TODO Просмотр опций - кнопку убрал public function actionAjaxProductProvider() { $id = Yii::$app->request->post('id'); @@ -79,7 +84,7 @@ class ProductsController extends Controller // ->asArray() ->all(); $providers = ArrayHelper::map($providers, 'id', 'name'); -// var_dump($providers); die(); + $data = Products1cOptions::find() ->where(['id' => $id]) @@ -94,7 +99,7 @@ class ProductsController extends Controller $productColorsArray = explode(';', $data->colors ?? ''); - // Определение массива групп продуктов + $productGroups = [ "1" => "Голландия/Израиль", 2 => "Кения", @@ -110,7 +115,7 @@ class ProductsController extends Controller $dataResponse = '
'; $dataResponse .= '
Поставщик
-
'; foreach($providers as $idv =>$name) { $dataResponse .= "'; return $dataResponse; } @@ -180,6 +198,47 @@ class ProductsController extends Controller } + public function actionAjaxProductCharacteristics() + { + if (Yii::$app->request->isAjax) { + $productId = Yii::$app->request->post('id'); + + if (empty($productId)) { + return $this->asJson(['error' => 'ID товара не передан']); + } + + + $characteristics = Products1cAdditionalCharacteristics::find() + ->where(['product_id' => $productId]) + ->asArray() + ->all(); + + + if (empty($characteristics)) { + return $this->asJson(['error' => 'Нет свойств для данного товара']); + } + + + $properties = Product1cPropType::find() + ->select(['id', 'name']) + ->all(); + $properties = ArrayHelper::map($properties, 'id', 'name'); + + // var_dump($properties); die(); + $result = []; + foreach ($characteristics as $characteristic) { + $propertyName = $properties[$characteristic['property_id']] ?? 'Неизвестное свойство'; + $result[] = [ + 'name' => $propertyName, + 'value' => $characteristic['value'], + ]; + } + + return $this->asJson(['characteristics' => $result]); + } + + return $this->asJson(['error' => 'Некорректный запрос']); + } public function actionAjaxGroupConfig() { @@ -195,6 +254,7 @@ class ProductsController extends Controller $data2[$row->tip] = $id; } + $array = [ "wrap" => "Упаковка", "potted" => "Горшечка", @@ -208,33 +268,19 @@ class ProductsController extends Controller "other_items" => "Номенклатура 1%" ]; - $dataString = ''; - - foreach($array as $k => $arr) { - $dataString .= "'; - } - $dataString .= '
$arr "; - if(!empty( $data2[$k] )) { - $dataString .= '
удалить
'; - } - else { - $dataString .= '
добавить
'; - } - - $dataString .= ' ('.$k.')
'; - - - return $dataString; + return $this->asJson([ + 'id' => $id, + 'data2' => $data2, + 'classes' => $array, + ]); } } - return ''; - + return $this->asJson(['error' => 'Invalid request']); + } - } public function actionAjaxProductsInGroup() { if (Yii::$app->request->isAjax) { @@ -367,10 +413,20 @@ class ProductsController extends Controller return "Некорректный запрос"; } - + // Старый функционал + //TODO Удалить public function actionAjaxAddProduct() { return $this->renderPartial('ajax-add-product'); } + + // Старый функционал + //TODO Удалить public function actionAjaxRemoveProduct() { return $this->renderPartial('ajax-remove-product'); } + + // Старый функционал + //TODO Удалить public function actionAjaxRemoveExport() { return $this->renderPartial('ajax-remove-export'); } + + // Старый функционал + //TODO Добавление поставщиков - кнопку убрал public function actionAjaxProductProviderAdd() { if (Yii::$app->request->isAjax) { diff --git a/erp24/web/js/products/products-1c.js b/erp24/web/js/products/products-1c.js index a4055ab8..79b385f7 100644 --- a/erp24/web/js/products/products-1c.js +++ b/erp24/web/js/products/products-1c.js @@ -18,24 +18,102 @@ }); } - function ajax_group_config(id) { - $('#modal-7').modal('show', {backdrop: 'static'}); - $('#modal-7 .modal-title').text('Настройка категории'); +function ajax_product_characteristics(id) { + $('#modal-7').modal('show', { backdrop: 'static' }); + $('#modal-7 .modal-title').text('Характеристики товара'); + + const param3 = $('meta[name=csrf-param]').attr('content'); + const token3 = $('meta[name=csrf-token]').attr('content'); + + $.ajax({ + url: '/products/ajax-product-characteristics/', + method: 'post', + dataType: 'json', + data: { id: id, [param3]: token3 }, + success: function(response) { + if (response.error) { + $('#modal-7 .modal-body').html(`

${response.error}

`); + return; + } - const param3 = $('meta[name=csrf-param]').attr('content'); - const token3 = $('meta[name=csrf-token]').attr('content'); - $.ajax({ - url: '/products/ajax-group-config/', - method: 'post', - dataType: 'html', - data: {id: '' + id + '', [param3]: token3}, - success: function(data) { + const characteristics = response.characteristics; + let tableHtml = ` + + + + + + + + + `; + + characteristics.forEach((characteristic) => { + tableHtml += ` + + + + + `; + }); + + tableHtml += '
СвойствоЗначение
${capitalizeFirstLetter(characteristic.name)}${capitalizeFirstLetter(characteristic.value)}
'; + $('#modal-7 .modal-body').html(tableHtml); + }, + error: function() { + $('#modal-7 .modal-body').html('

Ошибка при выполнении запроса.

'); + } + }); +} + +function ajax_group_config(id) { + $('#modal-7').modal('show', { backdrop: 'static' }); + $('#modal-7 .modal-title').text('Настройка категории'); + + const param3 = $('meta[name=csrf-param]').attr('content'); + const token3 = $('meta[name=csrf-token]').attr('content'); + + $.ajax({ + url: '/products/ajax-group-config/', + method: 'post', + dataType: 'json', // Ожидаем данные в формате JSON + data: { id: id, [param3]: token3 }, + success: function(response) { + if (response.error) { + $('#modal-7 .modal-body').html('

Ошибка: ' + response.error + '

'); + return; + } - $('#modal-7 .modal-body').html(data); + + let html = '
'; // Flex-контейнер + const classes = response.classes; + const data2 = response.data2; + + for (const [key, name] of Object.entries(classes)) { + html += ` +
+
${name}
+
+ ${data2[key] + ? `
(${key})
` + : `
(${key})
`} +
+ +
`; } - }); - } + + html += '
'; + + + + $('#modal-7 .modal-body').html(html); + }, + error: function() { + $('#modal-7 .modal-body').html('

Ошибка при выполнении запроса.

'); + } + }); +} function ajax_products_in_group(parent_id) { const param3 = $('meta[name=csrf-param]').attr('content'); @@ -58,9 +136,12 @@ data.forEach((row) => { const isHidden = row.view === 0 ? 'скрыто' : ''; - const providerButton = `
- + поставщика ${providers[row.id] ? providers[row.id] : ''}
`; + + поставщика ${providers[row.id] ? providers[row.id] : ''}
`;*/ + const addCharButton = `
+ Доп. характеристики
`; let colorsHtml = ''; if (colorsProducts[row.id]) { @@ -81,18 +162,11 @@ } } - const addProductButton = `
внести цена ${prices[row.id]}'}
`; - - const removeProductButtons = row.entity_id - ? `
удалить продукт
-
удалить только связь
` - : ''; - tableHtml += ` ${row.name} ${isHidden} - ${providerButton} + ${addCharButton} ${colorsHtml} GUID ${row.id} @@ -182,4 +256,8 @@ }}); } +function capitalizeFirstLetter(string) { + return string.charAt(0).toUpperCase() + string.slice(1) +} + //}); \ No newline at end of file