T
T
Tupic1232022-02-21 13:27:40
opencart
Tupic123, 2022-02-21 13:27:40

How to get field value from opencart admin?

Hello. Created a field in phpMyAdmin called loc_use. This is a field for editing categories. The data from the category editing form is written to the database, but it is not possible to display it. gives an error message

Undefined index: loc_use in /var/www/u1278903/public_html/opencart/catalog/controller/product/category.php on line 248
Fatal error: Uncaught Twig\Error\SyntaxError: Unknown "loc_use" tag in "default/template/product/category.twig" at line 27. in /var/www/u1278903/storage/vendor/twig/twig/src/Parser.php:175 Stack trace: #0 /var/www/u1278903/storage/vendor/twig/twig/src/Parser.php(98): Twig\Parser->subparse(NULL, false) #1 /var/www/u1278903/storage/vendor/twig/twig/src/Environment.php(563): Twig\Parser->parse(Object(Twig\TokenStream)) #2 /var/www/u1278903/storage/vendor/twig/twig/src/Environment.php(595): Twig\Environment->parse(Object(Twig\TokenStream)) #3 /var/www/u1278903/storage/vendor/twig/twig/src/Environment.php(408): Twig\Environment->compileSource(Object(Twig\Source)) #4 /var/www/u1278903/storage/vendor/twig/twig/src/Environment.php(381): Twig\Environment->loadClass('__TwigTemplate_...', 'default/templat...', NULL) #5 /var/www/u1278903/storage/vendor/twig/twig/src/Environment.php(359): Twig\Environment->loadTemplate('default/templat...') #6 /var/www/u1278903/storage/vendor/twig/twig/src/Environment.php(318): Twig\Environment->load( in /var/www/u1278903/storage/vendor/twig/twig/src/Parser.php on line 175


Файл admin/controller/catalog/category.php
if (isset($this->error['loc_use'])) {
      $data['error_loc_use'] = $this->error['loc_use'];
    } else {
      $data['error_loc_use'] = array();
    }

Файл admin/model/catalog/category.php
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']) . "', meta_title = '" . $this->db->escape($value['meta_title']) . "', meta_h1 = '" . $this->db->escape($value['meta_h1']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', loc_use = '" . $this->db->escape($value['loc_use']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "'");
    }


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']) . "', meta_title = '" . $this->db->escape($value['meta_title']) . "', meta_h1 = '" . $this->db->escape($value['meta_h1']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', loc_use = '" . $this->db->escape($value['loc_use']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "'");
    }

foreach ($query->rows as $result) {
      $category_description_data[$result['language_id']] = array(
        'name'             => $result['name'],
        'meta_title'       => $result['meta_title'],
        'meta_h1'      	   => $result['meta_h1'],
        'meta_description' => $result['meta_description'],
        'meta_keyword'     => $result['meta_keyword'],
        'loc_use'     => $result['loc_use'],

        'description'      => $result['description']
      );
    }


Файл admin/view/template/catalog/category_form.twig
<div class="form-group">
                    <label class="col-sm-2 control-label" for="input-loc_use{{ language.language_id }}">{{ entry_loc_use }}</label>
                    <div class="col-sm-10">
                      <textarea name="category_description[{{ language.language_id }}][loc_use]" placeholder="{{ entry_description }}" id="input-loc_use{{ language.language_id }}" data-toggle="summernote" data-lang="{{ summernote }}" class="form-control">{{ category_description[language.language_id] ? category_description[language.language_id].loc_use }}</textarea>
                    </div>
                  </div>


Файл catalog/controller/product/category.php
$data['loc_use'] = html_entity_decode($category_info['loc_use'], ENT_QUOTES, 'UTF-8');
$data['products'][] = array(
          'product_id'  => $result['product_id'],
          'thumb'       => $image,
          'name'        => $result['name'],
          'description' => utf8_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
          'loc_use' => utf8_substr(trim(strip_tags(html_entity_decode($result['loc_use'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',

          'price'       => $price,
          'special'     => $special,
          'tax'         => $tax,
          'minimum'     => $result['minimum'] > 0 ? $result['minimum'] : 1,
          'rating'      => $result['rating'],
          'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
        );


Файл catalog/model/catalog/category.php я не изменял, т.к. не нашел схожих полей, ориентируюсь по meta_h1

файл catalog/view/theme/my_theme/template/product/category.twig
{% loc_use %}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rst0, 2022-02-22
@Tupic123

File catalog/controller/product/category.php
$result['loc_use'] does not exist

$results = $this->model_catalog_product->getProducts($filter_data);  // <-- вы получили продукты
           foreach ($results as $result) {
                $data['products'][] = array(
         'loc_use' => utf8_substr(trim(strip_tags(html_entity_decode($result['loc_use'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
                 } 
          }

paste instead use $data['loc_use']
'loc_use' => utf8_substr(trim(strip_tags(html_entity_decode($data['loc_use'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',

and it makes no sense to assign
the same $data['loc_use'] in a loop
$data['loc_use'] = html_entity_decode($category_info['loc_use'], ENT_QUOTES, 'UTF-8');

this is before loop transfer
// сюда 
foreach ($results as $result) {

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question