S
S
Samat2021-11-22 08:26:34
opencart
Samat, 2021-11-22 08:26:34

How to add a field to category description in opencart 3?

Engine version 3.0.2.0
There is a need to add a second description for the category, conditionally let it be called description_short
So, I added a field to the database in the table oc_category_description "description_short" similar to "description"

Added to admin/views/template/category_form.twig

<div class="form-group">
                    <label class="col-sm-2 control-label" for="input-description-short{{ language.language_id }}">{{ entry_description_short }}</label>
                    <div class="col-sm-10">
                      <textarea name="category_description[{{ language.language_id }}][description_short]" placeholder="{{ entry_description }}" id="input-description-short{{ language.language_id }}" data-toggle="summernote" data-lang="{{ summernote }}" class="form-control">{{ category_description[language.language_id] ? category_description[language.language_id].description_short }}</textarea>
                    </div>
                  </div>


This piece of code works correctly, it sends the correct form data

Added to catalog/controller/product/category.php:
$data['description_short'] = html_entity_decode($category_info['description_short'], ENT_QUOTES, 'UTF-8');
// под подобной записью


In admin/model/catalog/category.php
Changed the following methods.

// в методе addCategory в первом фориче и в методе editCaterogy соответственно, так же в первом фориче

foreach ($data['category_description'] as $language_id => $value) {
      $this->db->query("INSERT INTO " . DB_PREFIX . "category_description SET category_id = '" . (int)$category_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', description = '" . $this->db->escape($value['description']) . "', description_short = '" . $this->db->escape($value['description_short']) . "', meta_title = '" . $this->db->escape($value['meta_title']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "'");
    }

// editCategory
foreach ($data['category_description'] as $language_id => $value) {
      $this->db->query("INSERT INTO " . DB_PREFIX . "category_description SET category_id = '" . (int)$category_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', description = '" . $this->db->escape($value['description']) . "', description_short = '" . $this->db->escape($value['description_short']) . "', meta_title = '" . $this->db->escape($value['meta_title']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "'");
    }


What's happening?
The view is displayed correctly in the admin panel, the data from the database does not come / are not displayed, that is, if I make changes to the database manually, they will not come to the client, there will simply be an empty line

Next, if I enter some data into the database in these fields , then they will still not be anywhere, but if I edit the category where there is an entry in this field, then this field will become an empty string

. What could be the problem ??

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VVCh, 2021-11-22
@Mileon

there is also a getProductDescriptions method

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question