Помощь Добавить описание к баннеру

Тема в разделе "Opencart", создана пользователем stsepelin, 20 дек 2014.

Информация :
Внимание форумчане! При создании тем, или выкладывании какой-либо информации проверьте в какой ветке форума вы находитесь! Не путайте Opencart и Opencart2. При несоблюдении данного условия выносится соответствующее наказание! И потом не говорите что вас НЕ ПРЕДУПРЕЖДАЛИ! По возможности используйте обменники mail, yandex, google, dropbox, rghost Дабы избежать просьб перезалить и проблем с рекламой!
Модераторы: ZiX
  1. stsepelin

    stsepelin Постоялец

    Регистр.:
    8 сен 2011
    Сообщения:
    56
    Симпатии:
    12
    Здравствуйте!

    Пытался добавить поле textfield для описания к баннеры в Opencart 2.0.1.1
    Делал я это при помощи отредактированного vqmod модуля с версии 1.5.x
    И все бы ничего, но модуль работает не совсем корректно.
    Например, если я добавляю описание к картинке, я могу видеть его на сайте, но не могу видеть или прочитать его в админке. Получается, в админке значение description обнуляется каждый раз, когда я нажимаю на кнопку сохранить. Причем если проверить элемент, то там висит ошибка:
    Собственно скрипт для 1.5.х
    Код:
    <modification>
       <id>DESCRIPTION BANNER SLIDESHOW</id>
       <version>1.5.x</version>
       <vqmver>2.X</vqmver>
       <author>templates-general.com</author>
       <file name="admin/controller/design/banner.php">
          <operation>
             <search position="after"><![CDATA[
                $this->data['heading_title'] = $this->language->get('heading_title');
                ]]></search>
             <add><![CDATA[
                $this->data['entry_description'] = $this->language->get('entry_description');
                ]]></add>
          </operation>
            <operation>
             <search position="after"><![CDATA[
                $this->data['banner_images'][] = array(
                ]]></search>
             <add><![CDATA[
             'description'            => $banner_image['description'],
                ]]></add>
          </operation>
       </file>
        <file name="admin/model/design/banner.php">
          <operation>
             <search position="replace"><![CDATA[
                $this->db->query("INSERT INTO " . DB_PREFIX . "banner_image_description SET banner_image_id = '" . (int)$banner_image_id . "', language_id = '" . (int)$language_id . "', banner_id = '" . (int)$banner_id . "', title = '" .  $this->db->escape($banner_image_description['title']) . "'");             ]]></search>
             <add><![CDATA[
                $this->db->query("INSERT INTO " . DB_PREFIX . "banner_image_description SET banner_image_id = '" . (int)$banner_image_id . "', language_id = '" . (int)$language_id . "', banner_id = '" . (int)$banner_id . "', title = '" .  $this->db->escape($banner_image_description['title']) . "', description = '" .  $this->db->escape($banner_image_description['description']) . "'");
                ]]></add>
          </operation>
            <operation>
             <search position="after"><![CDATA[
                $banner_image_description_data[$banner_image_description['language_id']] = array('title' => $banner_image_description['title']);
                ]]></search>
             <add><![CDATA[
             $banner_image_description_desc[$banner_image_description['language_id']] = array ( 'description' => $banner_image_description['description'] );
                ]]></add>
          </operation>
            <operation>
             <search position="after"><![CDATA[
                'banner_image_description' => $banner_image_description_data,
                ]]></search>
             <add><![CDATA[
                'description'              => $banner_image_description_desc,
                ]]></add>
          </operation>
       </file>
        <file name="admin/language/*/design/banner.php">
          <operation>
             <search position="before"><![CDATA[
                ?>
                ]]></search>
             <add><![CDATA[
                $_['entry_description']       = 'Description:';
                ]]></add>
          </operation>
       </file>
        <file name="admin/view/template/design/banner_form.tpl">
          <operation>
             <search position="after"><![CDATA[
                <td class="left"><?php echo $entry_title; ?></td>
                ]]></search>
             <add><![CDATA[
                <td class="left"><?php echo $entry_description; ?></td>
                ]]></add>
          </operation>
            <operation>
             <search position="before"><![CDATA[
                <td class="left"><input type="text" name="banner_image[<?php echo $image_row; ?>][link]" value="<?php echo $banner_image['link']; ?>" /></td>
                ]]></search>
             <add><![CDATA[
                <td>
                     <?php foreach ($languages as $language) { ?>
                    <textarea style="width:300px; height:150px;" name="banner_image[<?php echo $image_row; ?>][banner_image_description][<?php echo $language['language_id']; ?>][description]" id="description"><?php echo isset($banner_image['description'][$language['language_id']]) ? $banner_image['description'][$language['language_id']]['description'] : ''; ?></textarea>
                    <img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /><br />
                    <?php } ?>
                    </td>
                ]]></add>
          </operation>
            <operation>
             <search position="before"><![CDATA[
               html += '<td class="left"><input type="text" name="banner_image[' + image_row + '][link]" value="" /></td>';
                ]]></search>
             <add><![CDATA[
        html += '<td class="left">';
       <?php foreach ($languages as $language) { ?>
       html += '<textarea style="width:300px; height:150px;" name="banner_image[' + image_row + '][banner_image_description][<?php echo $language['language_id']; ?>][description]" id="description"></textarea><br />';
        <?php } ?>
       html += '</td>';
        ]]></add>
          </operation>
       </file>
        <file name="catalog/controller/module/banner.php">
          <operation>
             <search position="before"><![CDATA[
                'title' => $result['title'],
                ]]></search>
             <add><![CDATA[
                'description' => ($result['description']),
                ]]></add>
          </operation>
       </file>
        <file name="catalog/controller/module/slideshow.php">
          <operation>
             <search position="before"><![CDATA[
                'title' => $result['title'],
                ]]></search>
             <add><![CDATA[
                'description' => ($result['description']),
                ]]></add>
          </operation>
       </file>
        <file name="catalog/controller/module/carousel.php">
          <operation>
             <search position="before"><![CDATA[
                'title' => $result['title'],
                ]]></search>
             <add><![CDATA[
                'description' => ($result['description']),
                ]]></add>
          </operation>
       </file>
        <file name="catalog/view/theme/*/template/module/slideshow.tpl">
          <operation>
             <search position="after"><![CDATA[
                <img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" />
                ]]></search>
             <add><![CDATA[
                <br/><?php echo $banner['description']; ?>
                ]]></add>
          </operation>
            <operation>
             <search position="after"><![CDATA[
                <a href="<?php echo $banner['link']; ?>"><img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" /></a>
                ]]></search>
             <add><![CDATA[
                <br/><?php echo $banner['description']; ?>
                ]]></add>
          </operation>
       </file>
        <file name="catalog/view/theme/*/template/module/banner.tpl">
          <operation>
             <search position="replace"><![CDATA[
                <div><a href="<?php echo $banner['link']; ?>"><img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" title="<?php echo $banner['title']; ?>" /></a></div>
                ]]></search>
             <add><![CDATA[
                <div><a href="<?php echo $banner['link']; ?>"><img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" title="<?php echo $banner['title']; ?>" /><?php echo $banner['description']; ?></a></div>
                ]]></add>
          </operation>
            <operation>
             <search position="after"><![CDATA[
                 <div><img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" title="<?php echo $banner['title']; ?>" /></div>
                ]]></search>
             <add><![CDATA[
                  <div><?php echo $banner['description']; ?><img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" title="<?php echo $banner['title']; ?>" /></div>
                ]]></add>
          </operation>
       </file>
        <file name="catalog/view/theme/*/template/module/carousel.tpl">
          <operation>
             <search position="replace"><![CDATA[
        <li><a href="<?php echo $banner['link']; ?>"><img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" title="<?php echo $banner['title']; ?>" /></a></li>
                ]]></search>
             <add><![CDATA[
        <li><a href="<?php echo $banner['link']; ?>"><img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" title="<?php echo $banner['title']; ?>" /></a><?php echo $banner['description']; ?><br/></li>
                ]]></add>
          </operation>
       </file>
    </modification>
    Замененные значения в Opencar 2.0 (я напишу только конечный результат, в том же порядке, что и в скрипте)

    admin/controller/design/banner.php

    Код:
    $data['entry_description']= $this->language->get('entry_description');
    
    'description'=> $banner_image['description'],
    
    admin/model/design/banner.php

    Код:
    $this->db->query("INSERT INTO ". DB_PREFIX ."banner_image_description SET banner_image_id = '".(int)$banner_image_id ."', language_id = '".(int)$language_id ."', banner_id = '".(int)$banner_id ."', title = '". $this->db->escape($banner_image_description['title'])."', description = '". $this->db->escape($banner_image_description['description'])."'");
    
    $this->db->query("INSERT INTO ". DB_PREFIX ."banner_image_description SET banner_image_id = '".(int)$banner_image_id ."', language_id = '".(int)$language_id ."', banner_id = '".(int)$banner_id ."', title = '". $this->db->escape($banner_image_description['title'])."', description = '". $this->db->escape($banner_image_description['description'])."'");
    
    $banner_image_description_desc[$banner_image_description['language_id']]= array('description'=> $banner_image_description['description']);
    
    'description'=> $banner_image_description_desc,
    admin/language/*/design/banner.php

    Код:
    $_['entry_description']='Description:';
     
  2. stsepelin

    stsepelin Постоялец

    Регистр.:
    8 сен 2011
    Сообщения:
    56
    Симпатии:
    12
    admin/view/template/design/banner_form.tpl

    Код:
    <?php echo $header; ?><?php echo $column_left; ?>
    <div id="content">
      <div class="page-header">
        <div class="container-fluid">
          <div class="pull-right">
            <button type="submit" form="form-banner" data-toggle="tooltip" title="<?php echo $button_save; ?>" class="btn btn-primary"><i class="fa fa-save"></i></button>
            <a href="<?php echo $cancel; ?>" data-toggle="tooltip" title="<?php echo $button_cancel; ?>" class="btn btn-default"><i class="fa fa-reply"></i></a></div>
          <h1><?php echo $heading_title; ?></h1>
          <ul class="breadcrumb">
            <?php foreach ($breadcrumbs as $breadcrumb) { ?>
            <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
            <?php } ?>
          </ul>
        </div>
      </div>
      <div class="container-fluid">
        <?php if ($error_warning) { ?>
        <div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
          <button type="button" class="close" data-dismiss="alert">&times;</button>
        </div>
        <?php } ?>
        <div class="panel panel-default">
          <div class="panel-heading">
            <h3 class="panel-title"><i class="fa fa-pencil"></i> <?php echo $text_form; ?></h3>
          </div>
          <div class="panel-body">
            <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-banner" class="form-horizontal">
              <div class="form-group required">
                <label class="col-sm-2 control-label" for="input-name"><?php echo $entry_name; ?></label>
                <div class="col-sm-10">
                  <input type="text" name="name" value="<?php echo $name; ?>" placeholder="<?php echo $entry_name; ?>" id="input-name" class="form-control" />
                  <?php if ($error_name) { ?>
                  <div class="text-danger"><?php echo $error_name; ?></div>
                  <?php } ?>
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label" for="input-status"><?php echo $entry_status; ?></label>
                <div class="col-sm-10">
                  <select name="status" id="input-status" class="form-control">
                    <?php if ($status) { ?>
                    <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                    <option value="0"><?php echo $text_disabled; ?></option>
                    <?php } else { ?>
                    <option value="1"><?php echo $text_enabled; ?></option>
                    <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                    <?php } ?>
                  </select>
                </div>
              </div>
              <table id="images" class="table table-striped table-bordered table-hover">
                <thead>
                  <tr>
                    <td class="text-left"><?php echo $entry_title; ?></td>
                    <td class="text-left"><?php echo $entry_description; ?></td>
                    <td class="text-left"><?php echo $entry_link; ?></td>
                    <td class="text-left"><?php echo $entry_image; ?></td>
                    <td class="text-right"><?php echo $entry_sort_order; ?></td>
                    <td></td>
                  </tr>
                </thead>
                <tbody>
                  <?php $image_row = 0; ?>
                  <?php foreach ($banner_images as $banner_image) { ?>
                  <tr id="image-row<?php echo $image_row; ?>">
                    <td class="text-left"><?php foreach ($languages as $language) { ?>
                      <div class="input-group pull-left"><span class="input-group-addon"><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /> </span>
                        <input type="text" name="banner_image[<?php echo $image_row; ?>][banner_image_description][<?php echo $language['language_id']; ?>][title]" value="<?php echo isset($banner_image['banner_image_description'][$language['language_id']]) ? $banner_image['banner_image_description'][$language['language_id']]['title'] : ''; ?>" placeholder="<?php echo $entry_title; ?>" class="form-control" />
                      </div>
                      <?php if (isset($error_banner_image[$image_row][$language['language_id']])) { ?>
                      <div class="text-danger"><?php echo $error_banner_image[$image_row][$language['language_id']]; ?></div>
                      <?php } ?>
                      <?php } ?></td>
                    <td class="text-left"><?php foreach ($languages as $language) { ?>
                      <div class="input-group pull-left"><span class="input-group-addon"><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /> </span>
                        <textarea rows="5" name="banner_image[<?php echo $image_row; ?>][banner_image_description][<?php echo $language['language_id']; ?>][description]" value="<?php echo isset($banner_image['banner_image_description'][$language['language_id']]) ? $banner_image['banner_image_description'][$language['language_id']]['description'] : ''; ?>" placeholder="<?php echo $entry_description; ?>" class="form-control"></textarea>
                      </div>
                      <?php } ?></td>
                    <td class="text-left" style="width: 20%;"><input type="text" name="banner_image[<?php echo $image_row; ?>][link]" value="<?php echo $banner_image['link']; ?>" placeholder="<?php echo $entry_link; ?>" class="form-control" /></td>
                    <td class="text-left"><a href="" id="thumb-image<?php echo $image_row; ?>" data-toggle="image" class="img-thumbnail"><img src="<?php echo $banner_image['thumb']; ?>" alt="" title="" data-placeholder="<?php echo $placeholder; ?>" /></a>
                      <input type="hidden" name="banner_image[<?php echo $image_row; ?>][image]" value="<?php echo $banner_image['image']; ?>" id="input-image<?php echo $image_row; ?>" /></td>
                    <td class="text-right"><input type="text" name="banner_image[<?php echo $image_row; ?>][sort_order]" value="<?php echo $banner_image['sort_order']; ?>" placeholder="<?php echo $entry_sort_order; ?>" class="form-control" /></td>
                    <td class="text-left"><button type="button" onclick="$('#image-row<?php echo $image_row; ?>, .tooltip').remove();" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>
                  </tr>
                  <?php $image_row++; ?>
                  <?php } ?>
                </tbody>
                <tfoot>
                  <tr>
                    <td colspan="5"></td>
                    <td class="text-left"><button type="button" onclick="addImage();" data-toggle="tooltip" title="<?php echo $button_banner_add; ?>" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button></td>
                  </tr>
                </tfoot>
              </table>
            </form>
          </div>
        </div>
      </div>
      <script type="text/javascript"><!--
    var image_row = <?php echo $image_row; ?>;
    
    function addImage() {
        html  = '<tr id="image-row' + image_row + '">';
        html += '  <td class="text-left">';
        <?php foreach ($languages as $language) { ?>
        html += '    <div class="input-group">';
        html += '      <span class="input-group-addon"><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /></span><input type="text" name="banner_image[' + image_row + '][banner_image_description][<?php echo $language['language_id']; ?>][title]" value="" placeholder="<?php echo $entry_title; ?>" class="form-control" />';
        html += '    </div>';
        <?php } ?>
        html += '  </td>';    
       
        html += '  <td class="text-left">';
        <?php foreach ($languages as $language) { ?>
        html += '    <div class="input-group">';
        html += '      <span class="input-group-addon"><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /></span><textarea type"text" name="banner_image[' + image_row + '][banner_image_description][<?php echo $language['language_id']; ?>][description]" value="" placeholder="<?php echo $entry_description; ?>" class="form-control" /></textarea>';
        html += '    </div>';
        <?php } ?>
        html += '  </td>';    
        html += '  <td class="text-left"><input type="text" name="banner_image[' + image_row + '][link]" value="" placeholder="<?php echo $entry_link; ?>" class="form-control" /></td>';    
        html += '  <td class="text-left"><a href="" id="thumb-image' + image_row + '" data-toggle="image" class="img-thumbnail"><img src="<?php echo $placeholder; ?>" alt="" title="" data-placeholder="<?php echo $placeholder; ?>" /></a><input type="hidden" name="banner_image[' + image_row + '][image]" value="" id="input-image' + image_row + '" /></td>';
        html += '  <td class="text-right"><input type="text" name="banner_image[' + image_row + '][sort_order]" value="" placeholder="<?php echo $entry_sort_order; ?>" class="form-control" /></td>';
        html += '  <td class="text-left"><button type="button" onclick="$(\'#image-row' + image_row  + '\').remove();" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>';
        html += '</tr>';
        
        $('#images tbody').append(html);
        
        image_row++;
    }
    //--></script></div>
    <?php echo $footer; ?>
    
    catalog/controller/module/banner.php

    Код:
    'description'=> $result['description'],
    catalog/view/theme/*/template/module/banner.tpl

    Код:
    <?php echo $banner['description'];?>
     
  3. NinoZombie

    NinoZombie Постоялец

    Регистр.:
    27 окт 2013
    Сообщения:
    118
    Симпатии:
    29
    Попытался разобраться - ничего не вышло. Видимо от того, что усилий требуется много, но они никак не стимулируются. Может быть сразу озвучите сумму, которую готовы отдать за решение проблемы?
    Если уж сами хотите разобраться - пробуйте выводить переменную description и элемент массива
    [banner_image_description][ВАШ ЯЗЫК] с индексом description в шаблоне admin/view/template/design/banner_form.tpl