Jump to content

[Solved] (Sub)Category image not display with link rewrite enabled


TheMash

Recommended Posts

Hello Prestashop users,
I'm using Prestashop since version 1.2.5 and it's one of the most (if not the most) E-Commerce I like.
Im a web designer and actually I've 4 web shops running on prestashop.

The last I've published is 1.4.3 version and I think I've found a bug.
I use it with a custom developed theme, using the default prestashop theme e totally change it grafically.

You can check this shop at this adress -> http://www.ricamissimi.com
If you enter the categories with subcategories you can notice the missing subcategory images.

The problem is...
Both locally and remote when LINK REWRITE is enabled category and subcategories images doesnt display.
With the help of Firebug, I've found the problem is on url path building.

I've changed the default "NO image available image" with customized one, simply because I didnt like it. And it works fine with link rewrite disabled.

So I investigated. The link building happen in classes/Link.php, and the file that call the class is on theme directory, category.tpl.

On row 68, themes/yourtheme/category.tpl

getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'medium')}" alt="" width="{$mediumSize.width}" height="{$mediumSize.height}" />



The function in classes/Link.php, row 247

   public function getCatImageLink($name, $id_category, $type = null)
   {
       return ($this->allow == 1) ? (__PS_BASE_URI__.'c/'.$id_category.($type ? '-'.$type : '').'/'.$name.'.jpg') : (_THEME_CAT_DIR_.$id_category.($type ? '-'.$type : '').'.jpg');
   }




So I've checked a previos version of Prestashop (1.4.2.5) to compare which differences there between the two classes and template file.
In the template, the code is the same. So the problem should be on class Link.php.
Let's compare them!

classes/Link.php, function getCatImageLink() version 1.4.3

    public function getCatImageLink($name, $id_category, $type = null)
   {
       return ($this->allow == 1) ? (__PS_BASE_URI__.'c/'.$id_category.($type ? '-'.$type : '').'/'.$name.'.jpg') : (_THEME_CAT_DIR_.$id_category.($type ? '-'.$type : '').'.jpg');
   }



classes/Link.php, function getCatImageLink() version 1.4.2.5

public function getCatImageLink($name, $id_category, $type = null)
   {
       return ($this->allow == 1) ? (__PS_BASE_URI__.$id_category.($type ? '-'.$type : '').'/'.$name.'.jpg') : (_THEME_CAT_DIR_.$id_category.($type ? '-'.$type : '').'.jpg');
   }



Can you notice the difference? Its a tiny little difference, it's after __PS_BASE_URI__.

__PS_BASE_URI__.'c/'.$id_category


__PS_BASE_URI__.$id_category



If I replace the function of the 1.4.3 version with the function of 1.4.2.5 version the category images magically appears!

48277_RXjKCFRYitSBR4BXUPdf_t

48278_gzndb5EDiR8n6XnR94Lv_t

Link to comment
Share on other sites

Here is how I solved it

With the latest version of Prestashop there is the opportunity to override the core classes without changing it directly, to avoid any modification to the Prestashop core directly.
So basically this is what I did: overrided the core class Link.php.

How to do it?

Create a file called Link.php in this path: /yourprestashopfolder/override/classes/Link.php.
If you already have a Link.php file simply append the following code.

<?php
// File: override/classes/Link.php

// Fix rewrite_url class not outputting the right url for category images when rewrite_url is enabled

class Link extends LinkCore
{

public function getCatImageLink($name, $id_category, $type = null)
   {
       return ($this->allow == 1) ? (__PS_BASE_URI__.$id_category.($type ? '-'.$type : '').'/'.$name.'.jpg') : (_THEME_CAT_DIR_.$id_category.($type ? '-'.$type : '').'.jpg');
   }

}
?>



What I did is very simple: I replaced the function with the one of the 1.4.2.5 version Prestashop, and it works.
Dont know if this can solve the problem permanently or if it can cause any malfunction to your shop... in any case one of the many advantages of override its if anything doesnt works you can fix it simply comment or deleting the overrided function or class.
Hope this helps!

Link to comment
Share on other sites

  • 2 weeks later...

On version 1.4.3, nore me this resolves the issue I have with the default image not showing up (when no image has been added), but then stops the images that HAVE been added from showing up! For some reason, in 1.4.3, I am only having an issue with the default category image not showing up, not any others!

Any ideas?

Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...

post-184562-0-63723900-1313184896_thumb.jpgpost-184562-0-63723900-1313184896_thumb.jpg

Here is how I solved it<br/><br/>With the latest version of Prestashop there is the opportunity to override the core classes without changing it directly, to avoid any modification to the Prestashop core directly.<br/>So basically this is what I did: overrided the core class Link.php.<br/><br/>How to do it?<br/><br/>Create a file called Link.php in this path: /yourprestashopfolder/override/classes/Link.php.<br/>If you already have a Link.php file simply append the following code.<br/><br/>

<br/><?php<br/>// File: override/classes/Link.php<br/><br/>// Fix rewrite_url class not outputting the right url for category images when rewrite_url is enabled<br/><br/>class Link extends LinkCore<br/>{<br/><br/>public function getCatImageLink($name, $id_category, $type = null)<br/>    {<br/>        return ($this->allow == 1) ? (__PS_BASE_URI__.$id_category.($type ? '-'.$type : '').'/'.$name.'.jpg') : (_THEME_CAT_DIR_.$id_category.($type ? '-'.$type : '').'.jpg');<br/>    }<br/><br/>}<br/>?><br/>

<br/><br/>What I did is very simple: I replaced the function with the one of the 1.4.2.5 version Prestashop, and it works.<br/>Dont know if this can solve the problem permanently or if it can cause any malfunction to your shop... in any case one of the many advantages of override its if anything doesnt works you can fix it simply comment or deleting the overrided function or class.<br/>Hope this helps!

 

 

Hi, I have a problem... I can make it show the text/name of each category or just the image. But not both.

for some reason the text gets behind the image. i reduce the image to 80x80 and nothing...

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