]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Перенос и правки кода
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 21 Nov 2024 15:08:45 +0000 (18:08 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 21 Nov 2024 15:08:45 +0000 (18:08 +0300)
erp24/controllers/ProductsController.php
erp24/modul/products/ajax_product_provider.php
erp24/modul/products/ajax_products_in_group.php
erp24/records/Products1cOptions.php
erp24/records/ProductsClass.php
erp24/views/products/_tree.php [new file with mode: 0644]
erp24/views/products/products-1c.php
erp24/web/js/products/products-1c.js [new file with mode: 0644]

index 21e562ecc6754471be29cc246a343a4d081c7095..5cdd39e5bc461366e3a6d43b8031e6c761cbbf94 100755 (executable)
@@ -288,131 +288,155 @@ class ProductsController extends Controller
                 }
 
 
-                $dataResponse .= '<table class="table table-sm table-hover"><tbody>';
-                foreach ($data as $row) {
-                     
-                    $dataResponse .= "<tr"; if(empty($row["entity_id"])) $dataResponse .= " class=\"bg-gray-500\""; $dataResponse .= "><td>".$row["name"]." ";
+                return $this->asJson([
+                    'data' => $data,
+                    'prices' => $prices,
+                    'providers' => $providers,
+                    'colorsProducts' => $colorsProducts,
+                    'productsVarieties' => $products_varieties,
+                    'parent_id' => $parent_id,
+                ]);
+            }
 
+            return $this->asJson(['error' => 'parent_id не передан']);
+        }
 
-                    $row['name']=str_replace('"','',$row['name']);
-                    $row['name']=str_replace("'",'',$row['name']);
+        return $this->asJson(['error' => 'Неверный запрос']);
+    }
 
-                    if($row["view"]==0) {
-                        $dataResponse .=  "<span class=\"btn btn-sm btn-danger\">скрыто</span>";
-                    }
 
-                    $dataResponse .= '<div  id="provider_'.$row['id'].'"  class="btn btn-sm btn-warning" onclick="ajax_product_provider(\''.$row['id'].'\'); " >+ поставщика '.($providers[$row['id']]??'').'</div>';
+    public function actionAjaxClassGroup()
+    {
+        if (Yii::$app->request->isAjax) {
+            $parent_id = Yii::$app->request->post('parent_id');
+            $tip = Yii::$app->request->post('tip', 'wrap');
 
-                    if(!empty($colorsProducts[$row["id"]])) {
-                        $s=0;
-                        foreach($colorsProducts[$row["id"]] as $color) {
-                            $color=trim($color);
-                            if(!empty($color)) {
-                                $s++;
-                                $dataResponse .= "<br><span class=\"btn btn-sm btn-info me-1 mt-1 mb-1\">$color</span>";
+            if (!empty($parent_id)) {
 
-                                if(!empty($products_varieties[$row["id"]][$color])) {
-                                    $dataResponse .= "сорта ";
-                                    foreach($products_varieties[$row["id"]][$color] as $varieties => $nameV) {
+                $productClass = ProductsClass::findOne(['category_id' => $parent_id]);
 
-                                        $dataResponse .= ' <span class="btn btn-sm btn-warning me-2">'.$nameV.'</span> ';
-                                    }
-                                }
-                            }
-                        }
+                if (!$productClass) {
 
-                        if($s>0) {
-                            $dataResponse .=  "<a href=\"/products/productVarieties/?id=" . $row['id'] . "\" target=new class=\"btn btn-info btn-sm\">+ добавить сорта</a>";
-                        }
-                    }
-                    $dataResponse .= " GUID ".$row["id"]."</td><td>";
+                    $productClass = new ProductsClass();
+                    $productClass->category_id = $parent_id;
+                }
 
-                    if(!empty($prices[$row['id']]) and empty($row["entity_id"]))
-                        $dataResponse .= '<div  id="diver_'.$row['id'].'"  class="btn btn-sm btn-warning" onclick="ajax_add_product(\''.$row['id'].'\',\''.$parent_id.'\',\''.$row['name'].'\',\''.$prices[$row['id']].'\'); " >внести цена '.$prices[$row['id']].'</div>';
-                    else {
-                        $dataResponse .= '<div  id="diver_'.$row['id'].'"  class="btn btn-sm btn-warning" onclick="ajax_add_product(\''.$row['id'].'\',\''.$parent_id.'\',\''.$row['name'].'\',\''.($prices[$row['id']]??'').'\'); " >внести цена '.($prices[$row['id']]??'').'</div>';
-                    }
 
-                    $dataResponse .= "</td><td>".$row["entity_id"]."";
+                $productClass->tip = $tip;
 
-                    if(!empty($row["entity_id"])) {
-                        $dataResponse .=  '<div  id="diver_' . $row['id'] . '"  class="btn btn-sm btn-danger" onclick="ajax_remove_product(\'' . $row['id'] . '\'); " >удалить продукт</div>
-                            <div  id="diver2_' . $row['id'] . '"  class="btn btn-sm btn-danger" onclick="ajaxRemoveExport(\'' . $row['id'] . '\'); " >
-                            удалить только связь</div>';
-                    }
+                if ($productClass->save()) {
+                    return "ok";
+                } else {
 
-                    $dataResponse .= "</td></tr>";
+                    return "Ошибка сохранения: " . implode(', ', $productClass->getFirstErrors());
+                }
+            }
 
+            return "Ошибка: parent_id не передан.";
+        }
 
-                    if(!empty($row["entity_id"])) {
-       
-                    }
+        return "Некорректный запрос.";
+    }
+
+
+    public function actionAjaxClassGroupRemove()
+    {
+        if (Yii::$app->request->isAjax) {
+            $id = Yii::$app->request->post('id');
+            $tip = Yii::$app->request->post('tip');
+
+            if (!empty($id) && !empty($tip)) {
 
+                $productClass = ProductsClass::findOne(['category_id' => $id, 'tip' => $tip]);
+
+
+                if ($productClass) {
+                    if ($productClass->delete()) {
+                        return "Метка удалена";
+                    } else {
+                        return "Ошибка удаления метки";
+                    }
+                } else {
+                    return "Запись не найдена";
                 }
-                $dataResponse .= '</tbody></table>';
-                
-                
             }
-             
-            return $dataResponse;
-               /* return $this->renderPartial('ajax-products-in-group', [
-                    'data' => $data,
-                    'prices' => $prices,
-                    'providers' => $providers,
-                    'colorsProducts' => $colorsProducts,
-                    'products_varieties' => $products_varieties,
-                ]);*/
 
+            return "Ошибка: параметры не переданы";
         }
 
-        // Возвращаем пустой ответ, если запрос не AJAX или parent_id пустой
-        return '';
+        return "Некорректный запрос";
     }
-    public function actionAjaxClassGroup() { return $this->renderPartial('ajax-class-group'); }
-    public function actionAjaxClassGroupRemove() { return $this->renderPartial('ajax-class-group-remove'); }
+
+
     public function actionAjaxAddProduct() { return $this->renderPartial('ajax-add-product'); }
     public function actionAjaxRemoveProduct() { return $this->renderPartial('ajax-remove-product'); }
     public function actionAjaxRemoveExport() { return $this->renderPartial('ajax-remove-export'); }
-    public function actionAjaxProductProviderAdd() { return $this->renderPartial('ajax-product-provider-add'); }
-
-    public function build_tree($cats, $parent_id, $products_class_row, $only_parent = false)
+    public function actionAjaxProductProviderAdd()
     {
-        $products_class = [
-            "wrap" => "Упаковка",
-            "potted" => "Горшечка",
-            "services" => "Услуги",
-            "services_delivery" => "Услуги по доставке",
-            "salut" => "Пиротехника",
-            "matrix" => "Матрица",
-            "marketplace" => "Товары для маркетплейсов",
-            "marketplace_additional" => "Доп. товары для маркетплейсов",
-            "related" => "Сопутка",
-            "other_items" => "Номенклатура 1%"
-        ];
-
-        $tree = '<ul style="margin-left:30px;">';
-        if ($only_parent == false) {
-            foreach ($cats[$parent_id] ?? [] as $cat) {
-                $tree .= '<li class="grup"><table class="m-0 table table-hover"><tbody>';
-                $tree .= '<tr id="tr_' . $cat->id . '"><td><span class="btn btn-info btn-sm me-2" onclick="if(!document.getElementById(\'trr_' . $cat->id . '\')) ajax_products_in_group(\'' . $cat->id . '\'); $(\'#trr_' . $cat->id . '\').toggle();">+</span>
-                <b>' . Html::encode($cat->name) . '</b><span class="dd' . $cat->id . '">';
-
-                foreach ($products_class_row[$cat->id] ?? [] as $tipi) {
-                    $tree .= ' <span class="tag m-1 tag-info">' . Html::encode($products_class[$tipi]) . '  </span> ';
+        if (Yii::$app->request->isAjax) {
+            $id = Yii::$app->request->post('id');
+            $options = Yii::$app->request->post('options', '');
+            $provider_id = intval(Yii::$app->request->post('provider_id', 0));
+            $expiration_days = intval(Yii::$app->request->post('expiration_days', 0));
+            $min_lot = intval(Yii::$app->request->post('min_lot', 0));
+            $colors = Yii::$app->request->post('colors', '');
+            $min_order = intval(Yii::$app->request->post('min_order', 0));
+            $price_zakup = floatval(Yii::$app->request->post('price_zakup', 0));
+            $group_id = intval(Yii::$app->request->post('group_id', 0));
+            $main = intval(Yii::$app->request->post('main', 0));
+            $view = Yii::$app->request->post('view') === 'on' ? 1 : 0;
+
+            if (!empty($id)) {
+
+                $product = Products1c::findOne(['id' => $id]);
+                if ($product) {
+                    $product->view = $view;
+                    $product->save();
+                }
+
+
+                $productOption = Products1cOptions::findOne(['id' => $id]);
+                if (!$productOption) {
+                    $productOption = new Products1cOptions();
+                    $productOption->id = $id;
                 }
 
-                $tree .= '</span>
-                 <span  class="btn btn-light btn-sm" onclick="ajax_group_config(\'' . $cat->id . '\'); ">настройки</span>
-                 </td>';
 
-                $tree .= '</tr></tbody></table>';
-                $tree .= $this->build_tree($cats, $cat->id, $products_class_row);
-                $tree .= '</li>';
+                $productOption->options = $options;
+                $productOption->provider_id = $provider_id;
+                $productOption->expiration_days = $expiration_days;
+                $productOption->min_lot = $min_lot;
+                $productOption->colors = $colors;
+                $productOption->price_zakup = $price_zakup;
+                $productOption->min_order = $min_order;
+                $productOption->group_id = $group_id;
+                $productOption->main = $main;
+
+               // var_dump($productOption); die();
+                if ($productOption->save(false)) {
+                    return "Запись сохранена";
+                } else {
+                    $errors = $productOption->getErrors();
+
+
+                    $errorMessages = [];
+                    foreach ($errors as $attribute => $messages) {
+                        foreach ($messages as $message) {
+                            $errorMessages[] = "Ошибка в поле '{$attribute}': {$message}";
+                        }
+                    }
+
+
+                    return implode("\n", $errorMessages);
+                }
             }
+
+            return "Ошибка: ID не передан.";
         }
-        $tree .= '</ul>';
 
-        return $tree;
+        return "Некорректный запрос.";
     }
 
+
+
 }
index 6984285763dafd3204574a577451d1ed10b9c79d..965adf30335175f2717ea138ecdf7f3a8cb1e1a3 100644 (file)
@@ -81,7 +81,7 @@ echo'</div><div class="col-12">';
 
 echo"<input type=checkbox name=view id=view ";  
  if($view==1)  echo' value=2 checked';
- else echo" valiue=0";
+ else echo" value=0";
 echo'> показыввать товар в автозаказе';
 
 echo'</div>
index e96f87f441b5db0eb59321d749571308e5f345a6..490ab3e22fede530568e820c239186f6c6eba435 100644 (file)
@@ -5,7 +5,7 @@ include_once(dirname(__DIR__, 2) . "/inc/db.php");
 include_once(dirname(__DIR__, 2) . "/inc/base_new.php");
 
 if(!empty($_REQUEST["parent_id"])) { $parent_id=htmlentities($_REQUEST["parent_id"]);
-$q = "SELECT p.id, p.name, e.entity_id, p.view  FROM products_1c as p LEFT JOIN export_import_table as e ON e.export_id='1' AND e.entity='products' AND e.export_val=p.id WHERE p.tip='products' AND p.parent_id=? order by p.name ASC";
+$q = "SELECT p.id, p.name, e.entity_id, p.view  FROM products_1c as p LEFT JOIN export_import_table as e ON e.export_iD e.export_val=p.id='1' AND e.entity='products' ANd WHERE p.tip='products' AND p.parent_id=? order by p.name ASC";
 
 $data = $db::getRows($q,[$parent_id]);
 
index 4669c7d853bb567026988014c40ea2739b357e55..e2b19555694f889849ef0bea660142c3eca222d4 100644 (file)
@@ -34,7 +34,9 @@ class Products1cOptions extends \yii\db\ActiveRecord
     public function rules()
     {
         return [
-            [['id', 'options', 'provider_id', 'expiration_days', 'min_lot', 'min_order', 'price_zakup', 'colors'], 'required'],
+
+            [['id', 'options', 'provider_id', 'expiration_days', 'min_lot', 'colors', 'price_zakup', 'min_order', 'group_id', 'main'], 'safe'],
+            [['id'], 'required'],
             [['options', 'colors'], 'string'],
             [['provider_id', 'expiration_days', 'min_lot', 'min_order', 'group_id', 'main'], 'integer'],
             [['price_zakup'], 'number'],
index ab7a8db9c4c93ee33688c75dc5425075945ea0e3..a018cdfc1672f7079056ae030484c7bf4c545d07 100755 (executable)
@@ -12,6 +12,19 @@ use Yii;
  */
 class ProductsClass extends \yii\db\ActiveRecord
 {
+
+    const PRODUCTS_CLASS = [
+        "wrap" => "Упаковка",
+        "potted" => "Горшечка",
+        "services" => "Услуги",
+        "services_delivery" => "Услуги по доставке",
+        "salut" => "Пиротехника",
+        "matrix" => "Матрица",
+        "marketplace" => "Товары для маркетплейсов",
+        "marketplace_additional" => "Доп. товары для маркетплейсов",
+        "related" => "Сопутка",
+        "other_items" => "Номенклатура 1%"
+    ];
     /**
      * {@inheritdoc}
      */
diff --git a/erp24/views/products/_tree.php b/erp24/views/products/_tree.php
new file mode 100644 (file)
index 0000000..6e8523d
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+use yii\helpers\Html;
+
+/* @var $cats array */
+/* @var $parent_id string */
+/* @var $products_class_row array */
+/* @var $products_class array */
+$this->registerJsFile('/js/products/products-1c.js', ['position' => \yii\web\View::POS_END]);
+if (!empty($cats[$parent_id])): ?>
+    <ul style="margin-left:30px;">
+        <?php foreach ($cats[$parent_id] ?? [] as $cat): ?>
+            <li class="grup">
+                <table class="m-0 table table-hover">
+                    <tbody>
+                    <tr id="tr_<?= Html::encode($cat->id) ?>">
+                        <td>
+                                <span class="btn btn-info btn-sm me-2"
+                                      onclick="if(!document.getElementById('trr_<?= Html::encode($cat->id) ?>'))
+                                          ajax_products_in_group('<?= Html::encode($cat->id) ?>');
+                                          $('#trr_<?= Html::encode($cat->id) ?>').toggle();">+</span>
+                            <b><?= Html::encode($cat->name) ?></b>
+                            <span class="dd<?= Html::encode($cat->id) ?>">
+                                    <?php foreach ($products_class_row[$cat->id] ?? [] as $tipi): ?>
+                                        <span class="tag m-1 tag-info">
+                                            <?= Html::encode($products_class[$tipi] ?? 'Неизвестно') ?>
+                                        </span>
+                                    <?php endforeach; ?>
+                                </span>
+                            <span class="btn btn-light btn-sm"
+                                  onclick="ajax_group_config('<?= Html::encode($cat->id) ?>');">
+                                    настройки
+                                </span>
+                        </td>
+                    </tr>
+                    </tbody>
+                </table>
+
+                <?= $this->render('_tree', [
+                    'cats' => $cats,
+                    'parent_id' => $cat->id,
+                    'products_class_row' => $products_class_row,
+                    'products_class' => $products_class,
+                ]) ?>
+            </li>
+        <?php endforeach; ?>
+    </ul>
+<?php endif; ?>
\ No newline at end of file
index dd30810b5934ef5952b2be4d6aa02287ff1d8355..47bc015521f260a7ff611753f12b5ea692f981cf 100644 (file)
@@ -11,7 +11,7 @@ include 'modul/products/products_1c.php';*/
 /* @var $prices array */
 /* @var $groups array */
 /* @var $groups_arr array */
-
+$this->registerJsFile('/js/products/products-1c.js', ['position' => \yii\web\View::POS_END]);
 use yii\helpers\Html;
 
 $this->title = 'Каталог 1С';
@@ -20,7 +20,43 @@ $this->title = 'Каталог 1С';
 
     <div class="groups">
         <div class="table-responsive">
-            <?= $this->context->build_tree($groups_arr, "", $products_class_row) ?>
+            <ul style="margin-left:30px;">
+                <?php foreach ($groups_arr[""] ?? [] as $cat): ?>
+                    <li class="grup">
+                        <table class="m-0 table table-hover">
+                            <tbody>
+                            <tr id="tr_<?= Html::encode($cat->id) ?>">
+                                <td>
+                                    <span class="btn btn-info btn-sm me-2"
+                                          onclick="if(!document.getElementById('trr_<?= Html::encode($cat->id) ?>'))
+                                                  ajax_products_in_group('<?= Html::encode($cat->id) ?>');
+                                                  $('#trr_<?= Html::encode($cat->id) ?>').toggle();">+</span>
+                                    <b><?= Html::encode($cat->name) ?></b>
+                                    <span class="dd<?= Html::encode($cat->id) ?>">
+                                        <?php foreach ($products_class_row[$cat->id] ?? [] as $tipi): ?>
+                                            <span class="tag m-1 tag-info">
+                                                <?= Html::encode($products_class[$tipi] ?? 'Неизвестно') ?>
+                                            </span>
+                                        <?php endforeach; ?>
+                                    </span>
+                                    <span class="btn btn-light btn-sm"
+                                          onclick="ajax_group_config('<?= Html::encode($cat->id) ?>');">
+                                        настройки
+                                    </span>
+                                </td>
+                            </tr>
+                            </tbody>
+                        </table>
+
+                        <?= $this->render('_tree', [
+                            'cats' => $groups_arr,
+                            'parent_id' => $cat->id,
+                            'products_class_row' => $products_class_row,
+                            'products_class' => \yii_app\records\ProductsClass::PRODUCTS_CLASS,
+                        ]) ?>
+                    </li>
+                <?php endforeach; ?>
+            </ul>
         </div>
     </div>
     <hr>
@@ -45,79 +81,3 @@ $this->title = 'Каталог 1С';
         </div>
     </div>
 
-<?php
-// Регистрация JavaScript-кода
-$this->registerJs(<<<JS
-function ajax_product_provider(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-provider/',
-        method: 'post',
-        dataType: 'html',
-        data: {id: '' + id + '', [param3]: token3},
-        success: function(data) {
-            $('#modal-7 .modal-body').html(data);
-        }
-    });
-}
-
-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: 'html',
-        data: {id: '' + id + '', [param3]: token3},
-        success: function(data) {
-            
-            $('#modal-7 .modal-body').html(data);
-        }
-    });
-}
-
-function ajax_products_in_group(parent_id) {
-    const param3 = $('meta[name=csrf-param]').attr('content');
-    const token3 = $('meta[name=csrf-token]').attr('content');
-
-    $.ajax({
-        url: '/products/ajax-products-in-group/',
-        method: 'post',
-        dataType: 'html',
-        data: {parent_id: '' + parent_id + '', [param3]: token3},
-        success: function(data) {
-            $('#tr_' + parent_id).after('<tr id="trr_' + parent_id + '"><td colspan="2">' + data + '</td></tr>');
-        }
-    });
-}
-
-function save_providerder(){
-
-const param3 = $('meta[name=csrf-param]').attr('content');
-const token3 = $('meta[name=csrf-token]').attr('content');
-
-$.ajax({
-       url: '/products/ajax-product-provider-add/',
-       method: 'post',       
-       dataType: 'html',        
-       data: {id: '<?=$id?>', provider_id: $('#provider_id').val(),
-       options: $('#options').val(),  expiration_days: $('#expiration_days').val(),  
-       min_lot: $('#min_lot').val(), colors: $('#colors').val(), min_order: $('#min_order').val(), price_zakup: $('#price_zakup').val(), group_id: $('#group_id').val() , main: $('#main').val() , view: $('#view').val(), [param3]:token3 },
-       success: function(data){  
-    $('#result_prov').html(data);
-       }}); 
-}
-
-// Добавьте остальные функции JavaScript аналогично
-JS
-    , \yii\web\View::POS_END);
-?>
\ No newline at end of file
diff --git a/erp24/web/js/products/products-1c.js b/erp24/web/js/products/products-1c.js
new file mode 100644 (file)
index 0000000..a4055ab
--- /dev/null
@@ -0,0 +1,185 @@
+//document.addEventListener('DOMContentLoaded', function () {
+
+    function ajax_product_provider(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-provider/',
+            method: 'post',
+            dataType: 'html',
+            data: {id: '' + id + '', [param3]: token3},
+            success: function(data) {
+                $('#modal-7 .modal-body').html(data);
+            }
+        });
+    }
+
+    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: 'html',
+            data: {id: '' + id + '', [param3]: token3},
+            success: function(data) {
+
+                $('#modal-7 .modal-body').html(data);
+            }
+        });
+    }
+
+    function ajax_products_in_group(parent_id) {
+        const param3 = $('meta[name=csrf-param]').attr('content');
+        const token3 = $('meta[name=csrf-token]').attr('content');
+
+        $.ajax({
+            url: '/products/ajax-products-in-group/',
+            method: 'post',
+            dataType: 'json',
+            data: {parent_id: parent_id, [param3]: token3},
+            success: function(response) {
+                if (response.error) {
+                    alert(response.error);
+                    return;
+                }
+
+                const { data, prices, providers, colorsProducts, productsVarieties } = response;
+
+                let tableHtml = '<table class="table table-sm table-hover"><tbody>';
+
+                data.forEach((row) => {
+                    const isHidden = row.view === 0 ? '<span class="btn btn-sm btn-danger">скрыто</span>' : '';
+                    const providerButton = `<div id="provider_${row.id}" class="btn btn-sm btn-warning" 
+                onclick="ajax_product_provider('${row.id}');">
+                + поставщика ${providers[row.id] ? providers[row.id] : ''}</div>`;
+
+                    let colorsHtml = '';
+                    if (colorsProducts[row.id]) {
+                        colorsProducts[row.id].forEach((color) => {
+                            color = color.trim();
+                            if (color) {
+                                colorsHtml += `<span class="btn btn-sm btn-info me-1 mt-1 mb-1">${color}</span>`;
+                                if (productsVarieties[row.id] && productsVarieties[row.id][color]) {
+                                    productsVarieties[row.id][color].forEach((variety) => {
+                                        colorsHtml += `<span class="btn btn-sm btn-warning me-2">${variety}</span>`;
+                                    });
+                                }
+                            }
+                        });
+
+                        if (colorsHtml) {
+                            colorsHtml += `<a href="/products/productVarieties/?id=${row.id}" target="_new" class="btn btn-info btn-sm">+ добавить сорта</a>`;
+                        }
+                    }
+
+                    const addProductButton = `<div id="diver_${row.id}" class="btn btn-sm btn-warning" onclick="ajax_add_product('${row.id}', '${response.parent_id}', '${row.name}', '${prices[row.id]}');">внести цена ${prices[row.id]}'}</div>`;
+
+                    const removeProductButtons = row.entity_id
+                        ? `<div id="diver_${row.id}" class="btn btn-sm btn-danger" onclick="ajax_remove_product('${row.id}');">удалить продукт</div>
+                       <div id="diver2_${row.id}" class="btn btn-sm btn-danger" onclick="ajaxRemoveExport('${row.id}');">удалить только связь</div>`
+                        : '';
+
+                    tableHtml += `
+                    <tr class="${row.entity_id ? '' : 'bg-gray-500'}">
+                        <td>
+                            ${row.name} ${isHidden}
+                            ${providerButton}
+                            ${colorsHtml}
+                            GUID ${row.id}
+                        </td>
+                        
+                    </tr>`;
+                });
+
+                tableHtml += '</tbody></table>';
+                $(`#tr_${parent_id}`).after(`<tr id="trr_${parent_id}"><td colspan="2">${tableHtml}</td></tr>`);
+            },
+            error: function() {
+                alert('Ошибка при выполнении запроса.');
+            },
+        });
+    }
+
+    function save_providerder(){
+
+        const param3 = $('meta[name=csrf-param]').attr('content');
+        const token3 = $('meta[name=csrf-token]').attr('content');
+
+        $.ajax({
+            url: '/products/ajax-product-provider-add/',
+            method: 'post',
+            dataType: 'html',
+            data: {id: '<?=$id?>',
+                provider_id: $('#provider_id').val(),
+                options: $('#options').val(),
+                expiration_days: $('#expiration_days').val(),
+                min_lot: $('#min_lot').val(),
+                colors: $('#colors').val(),
+                min_order: $('#min_order').val(),
+                price_zakup: $('#price_zakup').val(),
+                group_id: $('#group_id').val() ,
+                main: $('#main').val() , view: $('#view').val(), [param3]:token3 },
+            success: function(data){
+                $('#result_prov').html(data);
+            }});
+    }
+
+
+    function ajax_add_product(id,parent_id,name,price){
+
+        const param3 = $('meta[name=csrf-param]').attr('content');
+        const token3 = $('meta[name=csrf-token]').attr('content');
+
+        $.ajax({
+            url: '/products/ajax-add-product/',
+            method: 'post',
+            dataType: 'html',
+            data: {id: ''+id+'', name: ''+name+'',parent_id: ''+parent_id+'',price: ''+price+'', [param3]:token3},
+            success: function(data){
+                $('#diver_'+id+'').html(data);
+
+            }});
+    }
+    function ajax_remove_product(id){
+
+        const param3 = $('meta[name=csrf-param]').attr('content');
+        const token3 = $('meta[name=csrf-token]').attr('content');
+
+        $.ajax({
+            url: '/products/ajax-remove-product/',
+            method: 'post',
+            dataType: 'html',
+            data: {id: ''+id+'', [param3]:token3},
+            success: function(data){
+                $('#diver_'+id+'').html(data);
+
+            }});
+    }
+
+
+    function ajaxRemoveExport(id){
+
+        const param3 = $('meta[name=csrf-param]').attr('content');
+        const token3 = $('meta[name=csrf-token]').attr('content');
+
+        $.ajax({
+            url: '/products/ajax-remove-export/',
+            method: 'post',
+            dataType: 'html',
+            data: {id: ''+id+'', [param3]:token3},
+            success: function(data){
+                $('#diver2_'+id+'').html(data);
+
+            }});
+    }
+
+//});
\ No newline at end of file