Jump to content

Change all image caption


www.bio-krby-kamna.cz

Recommended Posts

post-15393-0-62331300-1475771989_thumb.png

 

Hello

 

before version 1.6.1.0 of prestashop you cannot edit image caption. With later version can edit, but its very complicated. This solution work with all version 1.6.x  Solution from http://pelechano.es/modificar-titulos-en-imagenes-prestashop-1-6/

 

adminbackoffice\themes\default\template\controllers\products\images.tpl find <td>legend</td> and change to 

	<td style="width: 100%;">
<div class="col-lg-12">
			{foreach from=$languages item=language}
				{if $languages|count > 1}
				<div class="translatable-field row lang-{$language.id_lang}">
					<div class="col-lg-10">
				{/if}
						<input type="text"
						id="prod_img[idprodimg][{$language.id_lang}]"
						{if isset($input_class)}class="{$input_class}"{/if}
						name="prod_img[idprodimg][{$language.id_lang}]"
						value="listImg_value_{$language.id_lang}"
						disabled="disabled"    {*egp mod creamos este campo plantilla deshabilitado para que luego no se envie. Al copiar ya se habilitara*}
						/>
				{if $languages|count > 1}
					</div>
					<div class="col-lg-2">
						<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" tabindex="-1">
							{$language.iso_code}
							<span class="caret"></span>
						</button>
						<ul class="dropdown-menu">
							{foreach from=$languages item=language}
							<li>
								<a href="javascript:hideOtherLanguage({$language.id_lang});">{$language.name}</a>
							</li>
							{/foreach}
						</ul>
					</div>
				</div>
				{/if}
			{/foreach}
</div>
</td>

find 

function imageLine(id, path, position, cover, shops, legend)
        {
            line = $("#lineType").html();
            line = line.replace(/image_id/g, id);
            line = line.replace(/(\/)?[a-z]{0,2}-default/g, function($0, $1){
                return $1 ? $1 + path : $0;
            });
            line = line.replace(/image_path/g, path);
            line = line.replace(/image_position/g, position);
            line = line.replace(/legend/g, legend);
            line = line.replace(/icon-check-empty/g, cover);
            line = line.replace(/<tbody>/gi, "");
            line = line.replace(/<\/tbody>/gi, "");
            if (shops != false)
            {
                $.each(shops, function(key, value){
                    if (value == 1)
                        line = line.replace('id="' + key + '' + id + '"','id="' + key + '' + id + '" checked=checked');
                });

replace to 

function imageLine(id, path, position, cover, shops, legendJsonArray,cargaInicial)
		{
			line = $("#lineType").html();
			line = line.replace(/image_id/g, id);
			line = line.replace(/(\/)?[a-z]{0,2}-default/g, function($0, $1){
				return $1 ? $1 + path : $0;
			});
			line = line.replace(/image_path/g, path);
			line = line.replace(/\.jpg"\s/g, '.jpg?time=' + new Date().getTime() + '" ');
			line = line.replace(/image_position/g, position);
			//line = line.replace(/legend/g, legend); egp mod legendas editables..Ahora nos llega un array en json
			if (typeof cargaInicial != 'undefined'){	//se construye la tabla dinámicamente al cargar la página. Ahora nos llega el array entero
				legendJsonArray = $.parseJSON(legendJsonArray);
			}else{//venimos de subir una imagen (ajax.tpl del uploader)
				legend=legendJsonArray;
				legendJsonArray={};
				legendInput=$('input[name^=legend]');
				$.each(legendInput, function(i, input) {
					lang_id_arr=input['name'].split('_');
					legendJsonArray[lang_id_arr[1]]=input['value'];//cogemos los valores del input titulo
				});
				
			}						
			$.each(legendJsonArray, function(i, item) {
				search='listImg_value_'+i;
				replace=item;				
				line = line.replace(search, replace);
				line = line.replace(/idprodimg/g, id);
				line = line.replace('disabled="disabled"', '');	//lo habilitamos.			
			});				
			
			line = line.replace(/icon-check-empty/g, cover);
			line = line.replace(/<tbody>/gi, "");
			line = line.replace(/<\/tbody>/gi, "");
			if (shops != false)
			{
				$.each(shops, function(key, value){
					if (value == 1)
						line = line.replace('id="' + key + '' + id + '"','id="' + key + '' + id + '" checked=checked');
				});
			}
			$("#imageList").append(line);
		}

find imageLine({$image->id}, "{$image->getExistingImgPath()}", {$image->position}, "{if $image->cover}icon-check-sign{else}icon-check-empty{/if}", assoc, "{$image->legend[$default_language]|@addcslashes:'\"'}");

and change to 

imageLine({$image->id}, "{$image->getExistingImgPath()}", {$image->position}, "{if $image->cover}icon-check-sign{else}icon-check-empty{/if}", assoc, "{$image->legend|@json_encode|@addcslashes:'\"'}", true);

create file override\controllers\admin\AdminProductsController.php with 

<?php

class AdminProductsController extends AdminProductsControllerCore 
{
	
	/*egp mod sobrescrito para poder modificar los títulos de las imágenes*/
	public function processUpdate()
	{
		$product=parent::processUpdate();
		
		if (empty($this->errors)){
			if($prod_img_arr=$_POST['prod_img']){
				foreach ($prod_img_arr as $id_image=>$prod_img){
					
					foreach ($prod_img as $id_lang=>$value_legend){
						 Db::getInstance()->execute('
							UPDATE `'._DB_PREFIX_.'image_lang`
							SET `legend` ="'.$value_legend.'"
							WHERE `id_image` = '.(int)$id_image.' AND `id_lang`='.(int)$id_lang);
					}
				}
			}
		}
		
		return $product;
	}
   
}

enable overrides Perfomance/Enable ovverides

delete cache\class_index.php

post-15393-0-62331300-1475771989_thumb.png

Edited by www.bio-krby-kamna.cz (see edit history)
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
×
×
  • Create New...