From 4f25e4968edd307510893c9546dbd69f8f8fc59d Mon Sep 17 00:00:00 2001 From: Konstantin Date: Sat, 30 May 2026 12:35:32 +0300 Subject: [PATCH] =?UTF-8?q?public/admin/controller/catalog/product.php:135?= =?UTF-8?q?1=20=E2=80=94=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=B2=D0=BE=D0=B4=D0=B0=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA?= =?UTF-8?q?=D0=BE=20=D0=BF=D1=80=D0=B8=D0=B2=D1=8F=D0=B7=D0=B0=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D0=BA=20=D1=82=D0=BE=D0=B2=D0=B0=D1=80=D1=83=20?= =?UTF-8?q?=D0=B0=D1=82=D1=80=D0=B8=D0=B1=D1=83=D1=82=D0=BE=D0=B2,=20?= =?UTF-8?q?=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=BF=D0=BE=D0=BB=D1=83?= =?UTF-8?q?=D1=87=D0=B0=D0=B5=D1=82=20=D0=92=D0=A1=D0=95=20=D0=B0=D1=82?= =?UTF-8?q?=D1=80=D0=B8=D0=B1=D1=83=D1=82=D1=8B=20=D0=B8=D0=B7=20=D0=91?= =?UTF-8?q?=D0=94,=20=D1=81=D0=B3=D1=80=D1=83=D0=BF=D0=BF=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D0=B3=D1=80=D1=83=D0=BF=D0=BF=D0=B0=D0=BC,=20=D0=B8=20=D1=81?= =?UTF-8?q?=D0=BE=D0=BF=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D0=BB=D1=8F=D0=B5?= =?UTF-8?q?=D1=82=20=D1=81=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D1=91?= =?UTF-8?q?=D0=BD=D0=BD=D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S-=D0=BA=D0=BE=D0=B4=20addAttribute/attri?= =?UTF-8?q?buteautocomplete=20=D1=83=D0=B4=D0=B0=D0=BB=D1=91=D0=BD.=20publ?= =?UTF-8?q?ic/admin/model/catalog/product.php:25,183=20=E2=80=94=20=D0=B2?= =?UTF-8?q?=20addProduct()=20=D0=B8=20editProduct()=20=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=BA=D0=B0=20!empty($text)=20=E2=80=94=20=D1=81?= =?UTF-8?q?=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D1=8F=D1=8E=D1=82=D1=81=D1=8F=20?= =?UTF-8?q?=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20=D0=B7=D0=B0=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D0=BD=D0=B5=D0=BD=D0=BD=D1=8B=D0=B5=20textarea,=20=D0=BF?= =?UTF-8?q?=D1=83=D1=81=D1=82=D1=8B=D0=B5=20=D0=BF=D1=80=D0=BE=D0=BF=D1=83?= =?UTF-8?q?=D1=81=D0=BA=D0=B0=D1=8E=D1=82=D1=81=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/admin/controller/catalog/product.php | 60 ++++++++--- public/admin/model/catalog/product.php | 16 ++- .../view/template/catalog/product_form.twig | 100 ++++-------------- 3 files changed, 74 insertions(+), 102 deletions(-) diff --git a/public/admin/controller/catalog/product.php b/public/admin/controller/catalog/product.php index 6c45f23..7c2ee2c 100644 --- a/public/admin/controller/catalog/product.php +++ b/public/admin/controller/catalog/product.php @@ -1350,27 +1350,63 @@ if (isset($this->request->post['price_3'])) { // Attributes $this->load->model('catalog/attribute'); + $this->load->model('catalog/attribute_group'); + + $attribute_groups = $this->model_catalog_attribute_group->getAttributeGroups(); + + $saved_attributes = array(); if (isset($this->request->post['product_attribute'])) { - $product_attributes = $this->request->post['product_attribute']; + $saved_attributes_raw = $this->request->post['product_attribute']; + + foreach ($saved_attributes_raw as $attr_id => $attr_data) { + if (!empty($attr_data['product_attribute_description'])) { + $saved_attributes[] = array( + 'attribute_id' => $attr_id, + 'product_attribute_description' => $attr_data['product_attribute_description'] + ); + } + } } elseif (isset($this->request->get['product_id'])) { - $product_attributes = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']); - } else { - $product_attributes = array(); + $saved_attributes = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']); } - $data['product_attributes'] = array(); + $data['attribute_groups'] = array(); - foreach ($product_attributes as $product_attribute) { - $attribute_info = $this->model_catalog_attribute->getAttribute($product_attribute['attribute_id']); + foreach ($attribute_groups as $attribute_group) { + $attributes = $this->model_catalog_attribute->getAttributes(array( + 'filter_attribute_group_id' => $attribute_group['attribute_group_id'], + 'sort' => 'a.sort_order', + 'order' => 'ASC' + )); - if ($attribute_info) { - $data['product_attributes'][] = array( - 'attribute_id' => $product_attribute['attribute_id'], - 'name' => $attribute_info['name'], - 'product_attribute_description' => $product_attribute['product_attribute_description'] + if (!$attributes) { + continue; + } + + $group_attributes = array(); + + foreach ($attributes as $attribute) { + $text_data = array(); + + foreach ($saved_attributes as $saved) { + if ($saved['attribute_id'] == $attribute['attribute_id']) { + $text_data = $saved['product_attribute_description']; + break; + } + } + + $group_attributes[] = array( + 'attribute_id' => $attribute['attribute_id'], + 'name' => $attribute['name'], + 'text' => $text_data ); } + + $data['attribute_groups'][] = array( + 'name' => $attribute_group['name'], + 'attribute' => $group_attributes + ); } // Options diff --git a/public/admin/model/catalog/product.php b/public/admin/model/catalog/product.php index 43d06d7..b802d9a 100644 --- a/public/admin/model/catalog/product.php +++ b/public/admin/model/catalog/product.php @@ -25,13 +25,12 @@ class ModelCatalogProduct extends Model { if (isset($data['product_attribute'])) { foreach ($data['product_attribute'] as $product_attribute) { if ($product_attribute['attribute_id']) { - // Removes duplicates - $this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "'"); - foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) { - $this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "' AND language_id = '" . (int)$language_id . "'"); + if (!empty($product_attribute_description['text'])) { + $this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "' AND language_id = '" . (int)$language_id . "'"); - $this->db->query("INSERT INTO " . DB_PREFIX . "product_attribute SET product_id = '" . (int)$product_id . "', attribute_id = '" . (int)$product_attribute['attribute_id'] . "', language_id = '" . (int)$language_id . "', text = '" . $this->db->escape($product_attribute_description['text']) . "'"); + $this->db->query("INSERT INTO " . DB_PREFIX . "product_attribute SET product_id = '" . (int)$product_id . "', attribute_id = '" . (int)$product_attribute['attribute_id'] . "', language_id = '" . (int)$language_id . "', text = '" . $this->db->escape($product_attribute_description['text']) . "'"); + } } } } @@ -186,11 +185,10 @@ class ModelCatalogProduct extends Model { if (!empty($data['product_attribute'])) { foreach ($data['product_attribute'] as $product_attribute) { if ($product_attribute['attribute_id']) { - // Removes duplicates - $this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "'"); - foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) { - $this->db->query("INSERT INTO " . DB_PREFIX . "product_attribute SET product_id = '" . (int)$product_id . "', attribute_id = '" . (int)$product_attribute['attribute_id'] . "', language_id = '" . (int)$language_id . "', text = '" . $this->db->escape($product_attribute_description['text']) . "'"); + if (!empty($product_attribute_description['text'])) { + $this->db->query("INSERT INTO " . DB_PREFIX . "product_attribute SET product_id = '" . (int)$product_id . "', attribute_id = '" . (int)$product_attribute['attribute_id'] . "', language_id = '" . (int)$language_id . "', text = '" . $this->db->escape($product_attribute_description['text']) . "'"); + } } } } diff --git a/public/admin/view/template/catalog/product_form.twig b/public/admin/view/template/catalog/product_form.twig index dba6078..1582a2b 100644 --- a/public/admin/view/template/catalog/product_form.twig +++ b/public/admin/view/template/catalog/product_form.twig @@ -492,39 +492,26 @@
-
- - - - - - - - - - - {% set attribute_row = 0 %} - {% for product_attribute in product_attributes %} - - - - - - {% set attribute_row = attribute_row + 1 %} - {% endfor %} - - - - - - - - -
{{ entry_attribute }}{{ entry_text }}
{% for language in languages %} -
-
- {% endfor %}
+ {% for attribute_group in attribute_groups %} +
+

{{ attribute_group.name }}

+
+ {% for attribute in attribute_group.attribute %} +
+ +
+ + {% for language in languages %} +
+ +
+ {% endfor %} +
+
+ {% endfor %} +
+ {% endfor %}
@@ -846,55 +833,6 @@ $('#article-related').delegate('.fa-minus-circle', 'click', function() { $(this).parent().remove(); }); //--> -