Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • Sign Up

[ДОРАБОТКА] Добавление подписи к доп картинкам


Recommended Posts

Подписывание картинок

post-506-1293741788,6129_thumb.jpg

post-506-1293741788,5917_thumb.jpg

1. Полный бекап

2. Изменить базу

в oc_product_image добавить поле image_desc (varchar(255) can be null)

3. Админка

admin/view/template/catalog/product_form.tpl

<tr>       <td class="left"><input type="hidden" name="product_image[<?php echo $image_row; ?>]" value="<?php echo $product_image['file']; ?>" id="image<?php echo $image_row; ?>"  />       	<img src="<?php echo $product_image['preview']; ?>" alt="" id="preview<?php echo $image_row; ?>" class="image" onclick="image_upload('image<?php echo $image_row; ?>', 'preview<?php echo $image_row; ?>');" /></td>       <td class="left"><a onclick="$('#image_row<?php echo $image_row; ?>').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>    </tr>
заменить на

<tr>       <td class="left"><input type="hidden" name="product_image[<?php echo $image_row; ?>]" value="<?php echo $product_image['file']; ?>" id="image<?php echo $image_row; ?>"  />	       <img src="<?php echo $product_image['preview']; ?>" alt="" id="preview<?php echo $image_row; ?>" class="image" onclick="image_upload('image<?php echo $image_row; ?>', 'preview<?php echo $image_row; ?>');" /></td>	<td><input type='text' name="image_desc[<?php echo $image_row; ?>]" value='<?php echo $product_image['image_desc']; ?>'></td>       <td class="left"><a onclick="$('#image_row<?php echo $image_row; ?>').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>    </tr>

,

function addImage() {    html  = '<tbody id="image_row' + image_row + '">';	html += '<tr>';	html += '<td class="left"><input type="hidden" name="product_image[' + image_row + ']" value="" id="image' + image_row + '" /><img src="<?php echo $no_image; ?>" alt="" id="preview' + image_row + '" class="image" onclick="image_upload('image' + image_row + '', 'preview' + image_row + '');" /></td>';	html += '<td class="left"><a onclick="$('#image_row' + image_row  + '').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>';	html += '</tr>';	html += '</tbody>';		$('#images tfoot').before(html);		image_row++;}
заменить на

function addImage() {    html  = '<tbody id="image_row' + image_row + '">';	html += '<tr>';	html += '<td class="left"><input type="hidden" name="product_image[' + image_row + ']" value="" id="image' + image_row + '" /><img src="<?php echo $no_image; ?>" alt="" id="preview' + image_row + '" class="image" onclick="image_upload('image' + image_row + '', 'preview' + image_row + '');" /></td>';	[color=#FF0000]html += '<td><input type="text" name="image_desc[' + image_row + ']" value=''></td>';[/color]	html += '<td class="left"><a onclick="$('#image_row' + image_row  + '').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>';	html += '</tr>';	html += '</tbody>';		$('#images tfoot').before(html);		image_row++;}
,

admin/controller/catalog/product.php

if (isset($product_info)) {			$results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);						foreach ($results as $result) {				if ($result['image'] && file_exists(DIR_IMAGE . $result['image'])) {					$this->data['product_images'][] = array(						'preview' => $this->model_tool_image->resize($result['image'], 100, 100),						'file'    => $result['image']					);				} else {					$this->data['product_images'][] = array(						'preview' => $this->model_tool_image->resize('no_image.jpg', 100, 100),						'file'    => $result['image']					);				}			}		}
заменить на

if (isset($product_info)) {			$results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);						foreach ($results as $result) {				if ($result['image'] && file_exists(DIR_IMAGE . $result['image'])) {					$this->data['product_images'][] = array(						'preview' => $this->model_tool_image->resize($result['image'], 100, 100),						'file'    => $result['image'],						'image_desc' => $result['image_desc']					);				} else {					$this->data['product_images'][] = array(						'preview' => $this->model_tool_image->resize('no_image.jpg', 100, 100),						'file'    => $result['image'],						'image_desc' => $result['image_desc']					);				}			}		}

admin/model/catalog/product.php

в addProduct и в editProduct

if (isset($data['product_image'])) {			foreach ($data['product_image'] as $image) {        		$this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape($image) . "'");			}		}
заменить на

$product_image_desc = array();		$i=0;		if (isset($data['product_image'])) {			foreach ($data['product_image'] as $image) {			$product_image_desc[$i][0] = $image;			$i++;			}		}		$k = $i;		$i=0;		if (isset($data['image_desc'])) {			foreach ($data['image_desc'] as $desc) {			$product_image_desc[$i][1] = $desc;			$i++;						}		}		for ($i=$k-1;$i>=0;$i--) 		{			$this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape($product_image_desc[$i][0]) . "', image_desc = '". $this->db->escape($product_image_desc[$i][1])  . "'");		}
,

public function getProductImages($product_id) {		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'");				return $query->rows;	}
заменить на

public function getProductImages($product_id) {		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "' ORDER BY product_image_id desc");				return $query->rows;	}
4. Для отображения

в catalog/model/catalog/product.php

public function getProductImages($product_id) {		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'");				return $query->rows;	}
заменить на

public function getProductImages($product_id) {		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "' ORDER BY product_image_id desc");				return $query->rows;	}
,

в catalog/controller/product/product.php

$this->data['images'] = array();						$results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);						foreach ($results as $result) {				$this->data['images'][] = array(					'popup' => $this->model_tool_image->resize($result['image'] , $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')),					'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height'))				);			}
заменить на

$this->data['images'] = array();						$results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);						foreach ($results as $result) {				$this->data['images'][] = array(					'popup' => $this->model_tool_image->resize($result['image'] , $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')),					'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height')),					'image_desc' => $result['image_desc']				);			}
в catalog/view/theme/ваша тема/template/product/product.tpl

<div id="tab_image" class="tab_page">      <?php if ($images) { ?>      <div style="display: inline-block;">        <?php foreach ($images as $image) { ?>        <div style="display: inline-block; float: left; text-align: center; margin-left: 5px; margin-right: 5px; margin-bottom: 10px;"><a href="<?php echo $image['popup']; ?>" title="<?php echo $heading_title; ?>" class="thickbox" rel="gallery"><img src="<?php echo $image['thumb']; ?>" title="<?php echo $heading_title; ?>" alt="<?php echo $heading_title; ?>" style="border: 1px solid #DDDDDD; margin-bottom: 3px;" /></a>          <span style="font-size: 11px;"><?php echo $text_enlarge; ?></span></div>        <?php } ?>      </div>      <?php } else { ?>      <div style="background: #F7F7F7; border: 1px solid #DDDDDD; padding: 10px; margin-bottom: 10px;"><?php echo $text_no_images; ?></div>      <?php } ?>    </div>
заменить на

<div id="tab_image" class="tab_page">      <?php if ($images) { ?>      <div style="display: inline-block;">        <?php foreach ($images as $image) { ?>        <div style="display: inline-block; float: left; text-align: center; margin-left: 5px; margin-right: 5px; margin-bottom: 10px;"><a href="<?php echo $image['popup']; ?>" title="<?php echo $heading_title; ?>" class="thickbox" rel="gallery"><img src="<?php echo $image['thumb']; ?>" title="<?php echo $heading_title; ?>" alt="<?php echo $heading_title; ?>" style="border: 1px solid #DDDDDD; margin-bottom: 3px;" /></a>          <span style="font-size: 11px;"><?php echo $image['image_desc']; ?></span></div>        <?php } ?>      </div>      <?php } else { ?>      <div style="background: #F7F7F7; border: 1px solid #DDDDDD; padding: 10px; margin-bottom: 10px;"><?php echo $text_no_images; ?></div>      <?php } ?>    </div>
Edited by afwollis
edit -> save
  • +1 1
Link to post
Share on other sites

было бы симпатичнее если использовать тег [ code ] [ /code ]

Link to post
Share on other sites

Перенес в раздел "Модули", поставил теги.

Link to post
Share on other sites

  • 1 month later...

:) пишу подпись, жму сохранить, перекидывает в список товаров, захожу по новой, а там пусто,куда писал :(

также перестала работать кнопка "добавить изображение " :(

в хроме:

ошибки: index.php:1027

Uncaught SyntaxError: Unexpected token ILLEGAL

[color=#FF0000]html += '<td><input type="text" name="image_desc[' + image_row + ']" value=''></td>';[/color]

Uncaught ReferenceError: addImage is not defined

(anonymous function)index.php:742

onclickindex.php:743

<td class="left"><a onclick="addImage();" class="button"><span>Добавить изображение</span></a></td>

в ИЕ:

[color=#FF0000]html += '<td><input type="text" name="image_desc[' + image_row + ']" value=''></td>';[/color]
Недопустимый знак update&token=a673496aee8d2db2918ca36d6e565edf&product_id=69, строка 929 символ 11 Edited by afwollis
edit -> save
Link to post
Share on other sites

ХЕЛП!!! Откат делать или как?

Link to post
Share on other sites

ХЕЛП!!! Откат делать или как?

да для начала откат Я выложу правленные файлы - похоже при всех этих редактированиях переносах что-то испортилось
Link to post
Share on other sites

ХЕЛП!!! Откат делать или как?

да для начала откат Я выложу правленные файлы - похоже при всех этих редактированиях переносах что-то испортилось
Вот оригинал..Если останется ошибка, скажи свою версию Opencart

picsign.zip

Link to post
Share on other sites
  • 3 months later...

Выдает ошибку: Parse error: syntax error, unexpected '>', expecting T_STRING or T_VARIABLE or '$' in /home/borus/public_html/profifoto.com.ua/catalog/controller/product/product.php on line 276

line 276:

-->	'image_desc' => $result['image_desc']

Просто нужно было удалить -->

Link to post
Share on other sites

  • 5 months later...

А как добавить переменную image_desc в файл экспорт/импорта?

Link to post
Share on other sites

Notice: Undefined offset: 1 in Z:\home\opencart\www\admin\model\catalog\product.php on line 82Warning: Cannot modify header information - headers already sent by (output started at Z:\home\opencart\www\admin\index.php:76) in Z:\home\opencart\www\system\engine\controller.php on line 27

Такую ошибку выдает

Link to post
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • 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.