ojotceue Posted May 6, 2014 Share Posted May 6, 2014 Hi, Is it possible to set up different image for each category, when the product is added without image? For example: I have 3 categories: - strawberries, raspberries and peaches. In each of category I have several types of fruits and I dont want to add single picture to each type of fruit. I would like to set up default image for each category, which will be display when I dont add an image to product. It would be display instead of "No image available" in default theme. Link to comment Share on other sites More sharing options...
vekia Posted May 6, 2014 Share Posted May 6, 2014 by default feature like that doesnt exist. you can do it only with modification of theme file: product.tpl there is a code like {if $have_image} <span id="view_full_size"> {if $jqZoomEnabled && $have_image && !$content_only} <a class="jqzoom" title="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" rel="gal1" href="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'thickbox_default')|escape:'html':'UTF-8'}" itemprop="url"> <img itemprop="image" src="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'large_default')|escape:'html':'UTF-8'}" title="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" alt="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}"/> </a> {else} <img id="bigpic" itemprop="image" src="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'large_default')|escape:'html':'UTF-8'}" title="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" alt="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" width="{$largeSize.width}" height="{$largeSize.height}"/> {if !$content_only} <span class="span_link no-print">{l s='View larger'}</span> {/if} {/if} </span> {else} <span id="view_full_size"> <img itemprop="image" src="{$img_prod_dir}{$lang_iso}-default-large_default.jpg" id="bigpic" alt="" title="{$product->name|escape:'html':'UTF-8'}" width="{$largeSize.width}" height="{$largeSize.height}"/> {if !$content_only} <span class="span_link"> {l s='View larger'} </span> {/if} </span> {/if} you have to add additional if conditio in {else} section - where you have to check association with products, then if product is associated with category - display category image instead of <img itemprop="image" src="{$img_prod_dir}{$lang_iso}-default-large_default.jpg" id="bigpic" alt="" title="{$product->name|escape:'html':'UTF-8'}" width="{$largeSize.width}" height="{$largeSize.height}"/> Link to comment Share on other sites More sharing options...
ojotceue Posted May 7, 2014 Author Share Posted May 7, 2014 Thanks for answer @vekia Im not so smart in php, but i guess I have to use something like{if product->$category->id_category}img src="{$category->id_image}-category-default.jpg"I have no idea how to merge it to correctly working code... Link to comment Share on other sites More sharing options...
vekia Posted May 7, 2014 Share Posted May 7, 2014 it's a bit more complicated, i think what if product is associated with several categories? what then? if each of them will have "default" product picture - what picture display then? Link to comment Share on other sites More sharing options...
ojotceue Posted May 8, 2014 Author Share Posted May 8, 2014 It's a good question. I was wondering about it. But asumming, that the product is associated with only one category - is the possibility to do it? Link to comment Share on other sites More sharing options...
vekia Posted May 8, 2014 Share Posted May 8, 2014 if product will be associated with only one category - it will not be a problem :-) so, by default code looks like: {else} <span id="view_full_size"> <img itemprop="image" src="{$img_prod_dir}{$lang_iso}-default-large_default.jpg" id="bigpic" alt="" title="{$product->name|escape:'html':'UTF-8'}" width="{$largeSize.width}" height="{$largeSize.height}"/> {if !$content_only} <span class="span_link"> {l s='View larger'} </span> {/if} </span> {/if} change it to: {else} {if $product->id_category_default==2} <img id="bigpic" itemprop="image" src="http://urltopicture.com/image.jpg" title="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" alt="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" width="{$largeSize.width}" height="{$largeSize.height}"/> {elseif $product->id_category_default==4} <img id="bigpic" itemprop="image" src="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'large_default')|escape:'html':'UTF-8'}" title="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" alt="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" width="{$largeSize.width}" height="{$largeSize.height}"/> {elseif $product->id_category_default==129} <img id="bigpic" itemprop="image" src="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'large_default')|escape:'html':'UTF-8'}" title="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" alt="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" width="{$largeSize.width}" height="{$largeSize.height}"/> {else} {if !$content_only} <span class="span_link no-print">{l s='View larger'}</span> {/if} {/if} {/if} remember about personalization of if condition, you can use as many "elseif" condition as you want - this mean that you can change picture for each product in the store. Link to comment Share on other sites More sharing options...
ojotceue Posted May 8, 2014 Author Share Posted May 8, 2014 Thanks a lot vekia! I will try it. And I must try what will happen when product will be associated with more than one category- presta choose random image or crash will be occur? Link to comment Share on other sites More sharing options...
vekia Posted May 8, 2014 Share Posted May 8, 2014 website will work fine then - but script will display first possible image Link to comment Share on other sites More sharing options...
Recommended Posts