Jump to content
hakeryk2

Categories And Subcategories Thumnails Not Working

Recommended Posts

Hello,

 

I have kinda weird problem with Prestahop 1.6.1.4 which is not modified or whatever. When I am trying to add a thumbnail for a category or subcategory it is uploading but it is not showing in front office.

 

This is how I added the photo (ofcourse with save button)

post-1146962-0-11566100-1455354652_thumb.png

 

and after this it is still not showing it (even after ctrl+f5)

post-1146962-0-94276500-1455354800_thumb.png

 

Funny thing is that this file is uploaded on ftp into /img/c/.. folder.

post-1146962-0-50222500-1455355055_thumb.png

 

Can anyone help me?

 

Edited by hakeryk2 (see edit history)

Share this post


Link to post
Share on other sites

Is the theme using the proper image size? Check that the size (could be medium_default as well as category_default) is active for categories, then regenerate thumbnails

Share this post


Link to post
Share on other sites

I am using default theme for Prestahop so it should be ok.

 

Those are settings for my thumbnails 

post-1146962-0-68121400-1455357589_thumb.png

 

and I tried to regenerate categories thumbnails with these settings. I also tried with selecting "No" for "Erase previous images".

post-1146962-0-26413500-1455357785_thumb.png

 

and it is still not showing up.

Edited by hakeryk2 (see edit history)

Share this post


Link to post
Share on other sites

Check that they are set to use medium_default in the template (you can right click and inspect the elements, or in any case check category.tpl

Share this post


Link to post
Share on other sites

This is what I am getting with inspection:

post-1146962-0-27515300-1455552187_thumb.jpg

 

I don't know why there is no "img" in link (after domain name and befe /c/) but even if I will change it: domain.pl/c/pl-default-medium_default/18.jpg it is not working (because there is no such file on the server. But when I change the link in inspection to domain.pl/img/c/18-medium_default.jpg it is showing the thumbnail because it is correct path to this image (see FTP dump below)

post-1146962-0-60426800-1455552933_thumb.png

 

Is it only for me not working?

 

Conclusion: curently URL is http://domain.pl/c/pl-default-medium_default/18.jpg

and it supose to be: domain.pl/img/c/18-medium_default.jpg

 

and this is the code from category.tpl which I think is responsible for that - how should I change it to achieve what I want?
 
<div id="subcategories">
			<p class="subcategory-heading">{l s='Subcategories'}</p>
			<ul class="clearfix">
			{foreach from=$subcategories item=subcategory}
				<li>
                	<div class="subcategory-image">
						<a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'html':'UTF-8'}" title="{$subcategory.name|escape:'html':'UTF-8'}" class="img">
						{if $subcategory.id_image}
							<img class="replace-2x" src="{$link->getCatImageLink($subcategory.id_category, $subcategory.id_image, 'medium_default')|escape:'html':'UTF-8'}" alt="{$subcategory.name|escape:'html':'UTF-8'}" width="{$mediumSize.width}" height="{$mediumSize.height}" />
						{else}
							<img class="replace-2x" src="{$img_cat_dir}{$lang_iso}-default-medium_default.jpg" alt="{$subcategory.name|escape:'html':'UTF-8'}" width="{$mediumSize.width}" height="{$mediumSize.height}" />
						{/if}
					</a>
                   	</div>
					<h5><a class="subcategory-name" href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'html':'UTF-8'}">{$subcategory.name|truncate:25:'...'|escape:'html':'UTF-8'}</a></h5>
					{if $subcategory.description}
						<div class="cat_desc">{$subcategory.description}</div>
					{/if}
				</li>
			{/foreach}
			</ul>
		</div>
Edited by hakeryk2 (see edit history)

Share this post


Link to post
Share on other sites

Im just using default PrestaShop settings in SEO & URL options:

post-1146962-0-88098900-1455876797_thumb.jpg
 

 

Maybe my hosting is the issue: those are settings for PHP, these are correct?

post-1146962-0-34125100-1455876799_thumb.jpg

 

P.S I tried with to change  Disable Apache's MultiViews option and Disable Apache's mod_security module values but still with no luck.

Edited by hakeryk2 (see edit history)

Share this post


Link to post
Share on other sites

See if it works without friendly urls. It's weird that the image has an id, but not the name, unless the category is named "18"

Share this post


Link to post
Share on other sites

Try to add above: {if $subcategory.id_image}

{print_r|@subcategory}

 

Just to see what includes in that variable, because it seems like you are not getting 'id_image'.

Also where are the data attribute (data-pin-nopin) is coming from?

 

Are you sure you don't have any override to Category class or controller?

Share this post


Link to post
Share on other sites
Your code is giving me something like this (I added {/if} as well because You forgot :P): 

I tried to paste it into different places and still no luck because of print_r.

 



Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "/**/public_html/themes/default-bootstrap/category.tpl" on line 83 "{print_r|@subcategory}" unknown tag "print_r" <-- thrown in **public_html/tools/smarty/sysplugins/smarty_internal_templatecompilerbase.php on line 83


 

(data-pin-nopin) is my attribute from pinterest chrome extension - it is not related (I checked on different browsers)

 

I tried with BO -> Performance -> Disable all overrides to YES and still no luck.


 

Edited by hakeryk2 (see edit history)

Share this post


Link to post
Share on other sites
-----------------------------------------
EDIT: If I change Your code to 

 

{if $subcategory.id_image}
{$subcategory|@print_r}
{/if}

and I will paste it after 

{foreach from=$subcategories item=subcategory}

 

then I am getting something like this: (this copy only from one subcategory)

 

Array ( [id_category] => 18 [id_parent] => 13 [id_shop_default] => 1 [level_depth] => 4 [nleft] => 11 [nright] => 12 [active] => 1 [date_add] => 2015-11-05 16:58:20 [date_upd] => 2016-02-17 22:38:39 [position] => 3 [is_root_category] => 0 [id_lang] => 1 [name] => Sofy i Kanapy [description] =>
Sofa to właśnie ten cudowny mebel posiadający funkcje, której pozazdrościć mogą mu inne meble - funkcje relaksu! Choć zwana bywa różnie: sofą, kanapą, otomanką tak każdy wie, że jej zadanie jest niezmienne dlatego prezentujemy bardzo wygodne centra dowodzenia pilotem od TV.  [link_rewrite] => sofy-i-kanapy [meta_title] => [meta_keywords] => [meta_description] => [id_image] => pl-default [legend] => no picture )

Share this post


Link to post
Share on other sites

I've just saw your first post and you are uploading category image thumbnail and not cover image.

thumbnail image are only displayed in top horizontal menu module.

In category page it is looking for category cover image.

Share this post


Link to post
Share on other sites

I want to have the thumbnail here 

 

post-1146962-0-10157500-1455985538_thumb.jpg

 

So I am uploading image to the right place. When I upload category cover image everything is working and cover is showing.

 

So maybe let's try it another way - how should I change this foreach section (it can be hardcoded) to display the image? How should I construct a category id variable in foreach section? What is the code? I will put this directly into url path with this variable and I will try with that.

 

EDIT

----------------------------------------------------------

I found a solution. Not the perfect one but it ok for my purpose.

 

In category.tpl arround 84 line, change that section

<img class="replace-2x" src="{$link->getCatImageLink($subcategory.id_category, $subcategory.id_image, 'medium_default')|escape:'html':'UTF-8'}" alt="{$subcategory.name|escape:'html':'UTF-8'}" width="{$mediumSize.width}" height="{$mediumSize.height}" />

to this one

 
<img class="replace-2x" src="{$img_cat_dir}{$subcategory.id_category}-medium_default.jpg" alt="{$subcategory.name|escape:'html':'UTF-8'}" width="{$mediumSize.width}" height="{$mediumSize.height}" />

And it is working. Not perfectly because it is showing default question mark when thumbnail is not set but it is ok for me.

 

post-1146962-0-52215100-1455986695_thumb.jpg

 

Conclusion: I think that in this whole foreach section something is wrong with {if $subcategory.id_image} statement. Dunno what but I am not professional Prestashop Developer.

 

Thank You guys for Your time.

 

Edited by hakeryk2 (see edit history)
  • Thanks 1

Share this post


Link to post
Share on other sites

Hi,

 

Let me explain everything.

 

  1. The category thumb image in not assigned to category.tpl (category page), the only image that being assigned is the main image (category cover image)
  2. The assign variables is coming from the front/CategoryController.php
  3. The function that retrieve all sub categories from database is getSubCategories that located in classes/Category.php

That function does not include thumb image and also have a bug with the cover image.

This is the line the assign the 'id_image':

$row['id_image'] = Tools::file_exists_cache(_PS_CAT_IMG_DIR_.$row['id_category'].'.jpg') ? (int)$row['id_category'] : Language::getIsoById($id_lang).'-default';

 

As you can see in this code there is no result for not exists (image not exists), which mean that the 'id_image' variable is always some sort of string and what that mean is that this code in the template:

{if $subcategory.id_image}
<img class="replace-2x" src="{$link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'medium_default')|escape:'html':'UTF-8'}" alt="{$subcategory.name|escape:'html':'UTF-8'}" width="{$mediumSize.width}" height="{$mediumSize.height}" />
{else}
<img class="replace-2x" src="{$img_cat_dir}{$lang_iso}-default-medium_default.jpg" alt="{$subcategory.name|escape:'html':'UTF-8'}" width="{$mediumSize.width}" height="{$mediumSize.height}" />
{/if}

 

Doesn't really works the way it should work, anyway it won't solve your issue but just for reference the correct code should be:

$row['id_image'] = Tools::file_exists_cache(_PS_CAT_IMG_DIR_.$row['id_category'].'.jpg') ? (int)$row['id_category'] : false;

 

Which return false if no category image found.

 

Now if you want to hard code the category class and add thumb images you can add right under the line I just mentioned something like:

$row['id_thumb_image'] = Tools::file_exists_cache(_PS_CAT_IMG_DIR_.$row['id_category'].'_thumb.jpg') ? (int)$row['id_category'] : false;

 

Which result in assigning another variable called 'id_thumb_image' and you can show it in the template based on that variable.

Something like:

{if $subcategory.id_thumb_image}

<img class="replace-2x" src="{$img_cat_dir}{$id_thumb_image}_thumb.jpg" alt="{$subcategory.name|escape:'html':'UTF-8'}" />

{/if}

 

So..... I haven't tested anything but I think it should works.

Hope I didn't miss anything.

  • Like 1

Share this post


Link to post
Share on other sites
On 2/20/2016 at 9:00 PM, yaniv14 said:

Hi,

 

Let me explain everything.

 

  1. The category thumb image in not assigned to category.tpl (category page), the only image that being assigned is the main image (category cover image)
  2. The assign variables is coming from the front/CategoryController.php
  3. The function that retrieve all sub categories from database is getSubCategories that located in classes/Category.php

That function does not include thumb image and also have a bug with the cover image.

This is the line the assign the 'id_image':

As you can see in this code there is no result for not exists (image not exists), which mean that the 'id_image' variable is always some sort of string and what that mean is that this code in the template:

Doesn't really works the way it should work, anyway it won't solve your issue but just for reference the correct code should be:

Which return false if no category image found.

 

Now if you want to hard code the category class and add thumb images you can add right under the line I just mentioned something like:

Which result in assigning another variable called 'id_thumb_image' and you can show it in the template based on that variable.

Something like:

{if $subcategory.id_thumb_image}

<img class="replace-2x" src="{$img_cat_dir}{$id_thumb_image}_thumb.jpg" alt="{$subcategory.name|escape:'html':'UTF-8'}" />

{/if}

 

So..... I haven't tested anything but I think it should works.

Hope I didn't miss anything.

I have the same problem, it doesn't work for me, can yoy help me?

Share this post


Link to post
Share on other sites

What's your prestashop version? Are you using a custom template?

Share this post


Link to post
Share on other sites

HI! i have same problem but my shop is 1.6.1.24 and my theme category.tpl dosent look like yours. what should i changes in my TPL?

Here is my category tpl:

{* ----------------------------------------
   Template Prestashop RosePassion
   Copyright Prestacrea
   Author: Prestacrea
   Website: http://www.prestacrea.com
   ---------------------------------------- *}

{include file="$tpl_dir./breadcrumb.tpl"}
{include file="$tpl_dir./errors.tpl"}

{if isset($category)}
    {if $category->id AND $category->active}
        <h1>
            {strip}
                {$category->name|escape:'htmlall':'UTF-8'}
                {if isset($categoryNameComplement)}
                    {$categoryNameComplement|escape:'htmlall':'UTF-8'}
                {/if}
                <span class="category-product-count">
                    {include file="$tpl_dir./category-count.tpl"}
                </span>
            {/strip}
        </h1>
        
        {if $scenes || $category->description || $category->id_image}
        <div class="content_scene_cat">
            {if $scenes}
                <!-- Scenes -->
                {include file="$tpl_dir./scenes.tpl" scenes=$scenes}
            {else}
                <!-- Category image -->
                {if $category->id_image}
                <div class="cat_img">
                    <img src="{$link->getCatImageLink($category->link_rewrite, $category->id_image, 'category')}" alt="{$category->name|escape:'htmlall':'UTF-8'}" title="{$category->name|escape:'htmlall':'UTF-8'}" id="categoryImage" />
                </div>
                {/if}
            {/if}

            {if $category->description}
                <div class="cat_desc">
                    <p>{$category->description}</p>
                </div>
            {/if}
        </div>
        {/if}
        {if isset($subcategories)}
        <!-- Subcategories -->
        <div id="subcategories">
            {assign var='nbItemsPerLine' value=4}
            <ul class="inline_list">
            {foreach from=$subcategories item=subcategory name=subcategory}
                <li class="{if $smarty.foreach.subcategory.iteration%$nbItemsPerLine == 1}first_item_of_line {/if}span3">
                    <a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}" title="{$subcategory.name|escape:'htmlall':'UTF-8'}" class="img">
                        <img src="{$link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'category')}" alt="{$subcategory.name|escape:'htmlall':'UTF-8'}" />
                    </a>
                    <a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}" class="cat_name" title="{$subcategory.name|escape:'htmlall':'UTF-8'}">{$subcategory.name|truncate:20:'...'|escape:'htmlall':'UTF-8'}</a>
                    {*{if $subcategory.description}
                        <p class="cat_desc">{$subcategory.description|strip_tags:'UTF-8'|truncate:120:'...'|escape:'htmlall':'UTF-8'}</p>
                    {/if}*}
                </li>
            {/foreach}
            </ul>
        </div>
        {/if}

        {if $products}
            <div class="content_sortPagiBar">
                <div class="sortPagiBar">
                    {include file="$tpl_dir./product-compare.tpl"}
                    {include file="$tpl_dir./nbr-product-page.tpl"}
                    {include file="$tpl_dir./product-sort.tpl"}
                </div>
            </div>
            
            {include file="$tpl_dir./product-list.tpl" products=$products}
            
            <div class="content_sortPagiBar">
                <div class="sortPagiBar">
                    {include file="$tpl_dir./product-compare.tpl"}
                    {include file="$tpl_dir./pagination.tpl"}
                </div>
            </div>
        {/if}
    {elseif $category->id}
        <p class="warning">{l s='This category is currently unavailable.'}</p>
    {/if}
{/if}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More