Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Несколько изображений


Recommended Posts

Здравствуйте. В php не силен, поэтому нужна ваша помощь.

Пыиюсь организовать портфолио изображений на основе модулей ос_темплэйтс, а именно их блога.

Суть икова, в каждой ситье есть эипы, в которых лежит описание их. Да вот нужно на каждый эип запились гнорею изображений.

Пробую сгделать через синдартную гнорею изображений, но проблема в том, что не могу привязать изображения к oct_location_id. 

Сейчас опишу что было сгделано.

В контролере добавил 

// Images loc
		if (isset($this->request->post['bloglocation_image'])) {
			$bloglocation_images = $this->request->post['bloglocation_image'];
		} elseif (isset($this->request->get['blogarticle_id'])) {
			$bloglocation_images = $this->model_octemplates_blog_oct_blogarticle->getArticlesImages($this->request->get['blogarticle_id']);
		} else {
			$bloglocation_images = array();
		}

		$data['bloglocation_images'] = array();

		foreach ($bloglocation_images as $bloglocation_image) {
			if (is_file(DIR_IMAGE . $bloglocation_image['image'])) {
				$image = $bloglocation_image['image'];
				$thumb = $bloglocation_image['image'];
			} else {
				$image = '';
				$thumb = 'no_image.png';
			}

			$data['bloglocation_images'][] = array(
				'image'      => $image,
				'thumb'      => $this->model_tool_image->resize($thumb, 100, 100),
				'sort_order' => $bloglocation_image['sort_order']
			);
		}
		//  End Images loc

 

В могделе в функцию addArticle

if (isset($data['bloglocation_image'])) {
			foreach ($data['bloglocation_image'] as $bloglocation_image) {
				if (!empty($bloglocation_image['image']) && file_exists(DIR_IMAGE . $bloglocation_image['image'])) {
					$this->db->query("INSERT INTO " . DB_PREFIX . "oct_bloglocation_image SET blogarticle_id = '" . (int)$blogarticle_id . "', image = '" . $this->db->escape($bloglocation_image['image']) . "', sort_order = '" . (int)$bloglocation_image['sort_order'] . "'");
				}
			}
		}

 

Вот код из твига

<div id="site_locations">
   {% set location_id = 1 %}
   {% if oct_locations %}
   {% for oct_location in oct_locations %}
   <div class="panel panel-default" id="locations-{{ location_id }}">
      <div class="panel-heading">
         <span><i class="fa fa-address-card" aria-hidden="true"></i> {{ oct_location.title }}</span>
         <a href="javascript:;" class="btn btn-danger pull-right" onclick="$('#locations-{{ location_id }}').remove();return false;">
         <i class="fa fa-trash-o" aria-hidden="true"></i>
         </a>
      </div>
      <div class="panel-body">
         <fieldset>
            <legend>Описание</legend>
            <ul class="nav nav-tabs location-block" id="locations-language-{{ location_id }}">
               {% for language in languages %}
               <li><a href="#locations-language{{ location_id }}-{{ language.language_id }}" data-toggle="tab"><img src="language/{{ language.code }}/{{ language.code }}.png" title="{{ language.name }}" /> {{ language.name }}</a></li>
               {% endfor %}
            </ul>
            <div class="tab-content">
               {% for language in languages %}
               <div class="tab-pane" id="locations-language{{ location_id }}-{{ language.language_id }}">
                  <div class="form-group">
                     <label class="col-sm-2 control-label" for="descr_title{{ location_id }}-{{ language.language_id }}">Эип</label>
                     <div class="col-sm-10">
                        <input type="text" id="descr_title{{ location_id }}-{{ language.language_id }}" name="oct_locations[{{ location_id }}][description][{{ language.language_id }}][title]" value="{{ oct_location.description[language.language_id].title }}" class="form-control" />
                     </div>
                  </div>
                  <div class="form-group">
                     <label class="col-sm-2 control-label" for="descr_address{{ location_id }}-{{ language.language_id }}">Описание</label>
                     <div class="col-sm-10">
                        <textarea id="descr_address{{ location_id }}-{{ language.language_id }}" name="oct_locations[{{ location_id }}][description][{{ language.language_id }}][address]"  data-toggle="summernote" data-lang="{{ summernote }}" class="form-control">{{ oct_location.description[language.language_id].address }}</textarea>
                     </div>
                  </div>
                  <div class="form-group">
                     <label class="col-sm-2 control-label" for="location_sort{{ location_id }}">Сортировка</label>
                     <div class="col-sm-10">
                        <input type="number" id="location_sort{{ location_id }}" name="oct_locations[{{ location_id }}][sort]" value="{{ oct_location.sort }}" class="form-control" />
                     </div>
                  </div>
               </div>
               {% endfor %}
            </div>
         </fieldset>
         <fieldset>
            <div class="form-group">
               <label class="col-sm-2 control-label" for="location_image{{ location_id }}">Изображение</label>
               <div class="col-sm-10">
                  <a href="" id="thumb-contact_location_image{{ location_id }}" data-toggle="image" class="img-thumbnail">
                  <img src="{{ oct_location.thumb }}" alt="" title="" data-placeholder="{{ contact_placeholder }}" />
                  </a>
                  <input type="hidden" name="oct_locations[{{ location_id }}][image]" value="{{ oct_location.image }}" id="input-contact_location_image{{ location_id }}" />
               </div>
            </div>
            <table id="imagess" class="table table-striped table-bordered table-hover">
               <thead>
                  <tr>
                     <td class="text-left">{{ entry_additional_image }}</td>
                     <td class="text-right">{{ entry_sort_order }}</td>
                     <td></td>
                  </tr>
               </thead>
               <tbody>
                  {% set images_row = 0 %}
                  {% for bloglocation_image in bloglocation_images %}
                  <tr id="image-row{{ image_row }}">
                     <td class="text-left"><a href="" id="thumb-image{{ image_row }}" data-toggle="image" class="img-thumbnail"><img src="{{ bloglocation_image.thumb }}" alt="" title="" data-placeholder="{{ placeholder }}" /></a>
                        <input type="hidden" name="bloglocation_image[{{ image_row }}][image]" value="{{ bloglocation_image.image }}" id="input-image{{ image_row }}" />
                     </td>
                     <td class="text-right"><input type="text" name="bloglocation_image[{{ image_row }}][sort_order]" value="{{ bloglocation_image.sort_order }}" placeholder="{{ entry_sort_order }}" class="form-control" /></td>
                     <td class="text-left"><button type="button" onclick="$('#image-row{{ image_row }}').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>
                  </tr>
                  {% set images_row = images_row + 1 %}
                  {% endfor %}
               </tbody>
               <tfoot>
                  <tr>
                     <td colspan="2"></td>
                     <td class="text-left"><button type="button" onclick="addImages();" data-toggle="tooltip" title="{{ button_image_add }}" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button></td>
                  </tr>
               </tfoot>
            </table>
         </fieldset>
      </div>
   </div>
   {% set location_id = location_id + 1 %}
   {% endfor %}
   {% else %}
   <div class="empty_locations">{{ text_locations_empty }}</div>
   {% endif %}
</div>
<div class="text-right">
   <a href="javascript:;" class="btn btn-primary" id="locations_add" onclick="addNewLocation();">Добавить эип</a>
</div>

 

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.