Automatic category images in XTCommerce

Not everyone who uses a XTC system has the time to set a category image for each category – just as if you have a quiet complex category structure.

Apart from that the native XTC category image function has a further problem: The images have to be uploaded for each category. What next if you used a product image for a category and the product later possibly does’nt exist in this category anymore?

That’s why i prefer the automatic output of category images. Where do this images come from? They are product images from a product within the category.

While it’s quiet complicated to extend XTC with functions like these there is another relatively comfortable way: Through Smarty plugins.

The well documented and flexible parsing engine allows to use different plugins and to extend XTC without hacking any core files.

How does it work?

Step 1/2 – install the plugin

Download the Smarty plugin here and extract the file to the directory [XTC-Wurzelverzeichnis]/includes/classes/Smarty_2.6.14/plugins/ on your server.

Schritt 2/2 – Customise your template

Open the file

[XTC-root directory]/templates/[Your Template]/module/categorie_listing/categorie_listing.html

find this line

{if $module_data.CATEGORIES_IMAGE} <a href=”{$module_data.CATEGORIES_LINK}”><img src=”{$module_data.CATEGORIES_IMAGE}” alt=”{$module_data.CATEGORIES_NAME}” /></a>{/if}

and comment it out. (Simply insert {* before and *} after)

After this line insert:

<a href=”{$module_data.CATEGORIES_LINK}”><img src=”{$module_data.CATEGORIES_LINK|auto_category_image:true}” alt=”" /></a>

and save the file.

Ready

The attribute ready stands for the automatic output. It’s your choice to set it to true to output the image at random or to false to output first found image.

Attention: This script searches the database recursively for product images. So if you have a large amount of nested sub categorys without product images within you should not use this script for perfomance reasons.

Tags: , , ,

24 Responses to “Automatic category images in XTCommerce”

  1. Webagentur Says:

    Ist auch auch möglich, in der Kategorie-Navigation vor jeden Navi-Punkt ein anderes Bild anzuzeigen?

  2. metti Says:

    Falls du die Kategorie-Navi in der Box meinst, geht das nicht so einfach, weil der Inhalt der Kategorie-Box aus einer PHP-Datei raus erstellt wird.

    Diese PHP-Datei liegt aber auch im Template-Verzeichnis (templates/dein_template/source/inc/xtc_show_category.inc.php). Die kannst du ja entsprechend anpassen und die Funktion aus dem Smarty-Plugin benutzen oder sie halt so basteln, dass die Navi auch über Smarty gerendert wird.

    Wir können dir dabei gerne helfen.
    Cheers

  3. christian Says:

    feine sache! :-)

    ich möchte aber bei einigen kategorien selber bestimmen, welche bilder da reinkommen und die auch ganz normal über den admin hochladen. die anderen kategorien möchte ich mit den passenden produktbildern aus dem ordner thumbnails befüllen.

    geht das? :-/

    besten gruss

    christian

  4. metti Says:

    Jo das geht. Kommentiere dazu nicht wie beschrieben diese Zeile:

    {if $module_data.CATEGORIES_IMAGE}
    <a href="{$module_data.CATEGORIES_LINK}" ><img src="{$module_data.CATEGORIES_IMAGE}" alt="{$module_data.CATEGORIES_NAME}" /></a>{/if}

    aus, sondern ändere das {/if} in {else}, füge danach wie beschrieben den neuen Code ein und schreib direkt danach {/if} ein.

    —-

    If you want to set category images for some categorys and let the others be chosen by this script you can manage this like that:

    {if $module_data.CATEGORIES_IMAGE} <a href="{$module_data.CATEGORIES_LINK}" rel="nofollow"><img src="{$module_data.CATEGORIES_IMAGE}" alt="{$module_data.CATEGORIES_NAME}" /></a>
    {else}
    <a href="{$module_data.CATEGORIES_LINK}"><img src="{$module_data.CATEGORIES_LINK|auto_category_image:true}" alt="" /></a>
    {/if}
  5. metti Says:

    Es gab in dem Skript bisher Probleme mit SEF-URL’s. Dieser Bug ist jetzt gefixt und der Download aktualisiert.

    There was a problem with SEF URL’s. This bug is now fixed and the download upon is updated.

  6. christian Says:

    klasse skkript. spart jede menge arbeit! danke sagt

    der

    christian

  7. Andreas Says:

    das Script funktioniert leider nicht bei aktivierung des Moduls Direct URL von http://www.bluegate.at.

    Es werden einfach irgendwelche Bilder aus dem Shop genommen nicht jedoch die aus der korrekten Kategorie.

    Nach der Deaktivierung geht alles einwandfrei.

  8. metti Says:

    Das liegt daran, dass die Kategorie-ID’s aus den Links ausgelesen werden. Ist die Kategorie-ID, wie durch das Bluegate-SEF-Modul, nicht direkt im Link enthalten, erkennt das Plugin diese natürlich nicht und gibt Bilder für die Kategorie 0 aus.

    In so einem Fall ist die schnellste Lösung, die Kategorie-ID an’s Template zu übergeben. (includes/modules/default.php::118). Und zwar so:

    ‘CATEGORIES_ID’ => ”c_’.$categories['categories_id'].’_’

    Im Template die automatischen Bilder dann so erzeugen:

    {$module_data.CATEGORIES_ID|auto_category_image:true}

  9. johnny Says:

    hallo metti,
    kann es sein das in der

    ‘CATEGORIES_ID’ => ”c_’.$categories['categories_id'].’_’

    ein Fehler ist, denn ich bekomm immer eine fehlermeldung

    johnny

  10. metti Says:

    Ja. Die Anführungszeichen hauen nicht hin. Es muss dann so aussehen:

    $categories_content[]=array(
    'CATEGORIES_NAME' => $categories['categories_name'],
    'CATEGORIES_IMAGE' => $image,
    'CATEGORIES_LINK' => xtc_href_link(FILENAME_DEFAULT, $cPath_new),
    'CATEGORIES_DESCRIPTION' => $categories['categories_description'],
    'CATEGORIES_ID' => 'c_'.$categories['categories_id'].'_'
    );
  11. Andreas Says:

    Hallo,

    wie richtet man das Script ein damit es auch mit den SEO Urls von Shopstat funktioniert?

    Die Links sehen so aus: http://www.domain.de/Kategorie/Unterkategorie:::723_606.html

    Es werden aber immer falsche Bilder verwendet.

    Grüße
    Andreas

  12. Benny Says:

    Hi,

    nutze bisher keine SEO-URL.

    Habe aber leider immernoch das Problem das die Bilder aus der Cat 0 gezogen werden, obwohl ich in der default.php “‘CATEGORIES_ID’ => ‘c_’.$categories['categories_id'].’_'” nachgepflegt habe und in der listing.html ID statt LINK nutze.

    Gibt es da eventuell etwas woran es noch liegen kann?

    Gruß,
    Benny

  13. Benny Says:

    Ok Problem gefunden ^^

    FALSCH!!!:
    ‘CATEGORIES_ID’ => ‘c_’.$categories['categories_id'].’_’

    RICHTIG!!!:
    ‘CATEGORIES_ID’ => ‘c’.$categories['categories_id'].’_’

    Bei mir (Jung/Gestalten XTC-Version) funktioniert es dann.

    Gruß Benny

  14. Benny Says:

    Hier Benny nochmal XD

    Hab da nochmal die Frage, wenn eine Cat aktuell keine Produkte erhält, das dann ein hinterlegtes Bild verwendet wird?

    Oder allgemein gesagt, wenn kein Bild gefunden wird, dann nehme das Hinterlegte Bild?

    Wäre sehr dankbar für eine Antwort.

  15. metti Says:

    Naja – meistens findet das Skript ja trotzdem Bilder. Du kannst das Bild auf jeden Fall erstmal in eine Smarty-Variable schreiben:

    {assign var=”cimage” value=$module_data.CATEGORIES_IMAGE|auto_category_image:true}

    Dann kannst du sie mit Smarty untersuchen (Mit IF)

    Sollte das nicht ausreichen, bleibt es dir ja unbenommen, die Funktion in modifier.auto_category_image.php deinen Wünschen entsprechend anzupassen.

    Gruß,
    Metti

  16. tott Says:

    Habe nach Anpassung der default.php in Zeile 18 durch überschreiben mit:
    —–
    $categories_content[]=array(’CATEGORIES_NAME’ => $categories['categories_name'],’CATEGORIES_IMAGE’ => $image,
    ‘CATEGORIES_LINK’ => xtc_href_link(FILENAME_DEFAULT, $cPath_new),’CATEGORIES_DESCRIPTION’ => $categories['categories_description'],
    ‘CATEGORIES_ID’ => ‘c_’.$categories['categories_id'].’_');
    —–
    sowie nach Änderung der categorie_listing.html

    {if $module_data.CATEGORIES_IMAGE}
    {else}

    {/if}

    leider immer noch das Problem, dass nur Bilder der Kategorie 0 angezeigt werden. Wie kann ich das Problem lösen, bzw. was habe ich falsch gemacht????
    (ich benutze SEO URL Einstellungen)

    Gruss

  17. tott Says:

    Hi,
    meine natürlich (includes/modules/default.php::Zeile 118).
    Gruss

  18. tott Says:

    Hallo- wäre schön, wenn mir Jeman helfen könnte…..
    Gruss

  19. Kello Says:

    Hallo zusammen!

    Scheint ein nettes Plug-in zu sein, nur leider bring ich’s nicht zum laufen! :-(

    In der default.php hab ich jetzt stehen:
    ‘CATEGORIES_DESCRIPTION’ => $categories['categories_description'],
    ‘CATEGORIES_ID’ => ‘c’.$categories['categories_id'].’_’);

    Und in der categorie_listing.html steht:

    Also genau so, wie’s oben beschrieben wird! Und trotzdem funkt’s leider nicht!

    Eine Idee, wpran das liegen könnte?

    Vielen Dank schon mal im Voraus!

    Beste Grüße
    Kello

  20. Kello Says:

    ups – zum reinkopieren vergessen :-)

    categorie_listing.html :

  21. Kello Says:

    ah, ok -liegt am html-code – sorry
    hier ohne html:
    src={$module_data.CATEGORIES_ID|auto_category_image:true}

  22. Gordon Says:

    Ich hatte jetzt lange an der Geschichte gessen, weil das Teil in meinem xtc wunderbar funktioniert, aber bei der XT-modified Version nicht wollte.
    Kategorien übergibt die default.php bei mir trotz Änderung wie hier beschrieben, leider nicht. Keine Ahnung, worna das liegt.

    Aber eigentlich geht es ganz einfach!
    Man muss die Smarty-Class nur anpassen, dass diese wieder richtig abfragt.

    In dem Fall der Urls in dieser Form:
    http://www.magnetpinnwand.de/Magnete:::4.html

    sehen die Links dann so aus:
    http://www.magnetpinnwand.de/Magnete/Magnet-Sets:::4_9.html

    Also muss das Script nur nach dem Unterstrich suchen und nicht nach dem “c_”

    Wie man das nun aber löst, wenn die Kategorietitel Unterstriche enthalten….

    Aber ein Ansatz ist das auf jeden Fall.

  23. vererbbare Kategoriebilder in xtModified » Produktabbildung, Abbildung, Kategorien, Kategorie, Vererbung, Darstellung » the internet experts Says:

    [...] guter Artikel inklusive Smarty-Modifier-Plugin dazu, wie eine zufällige Produktabbildung automatisch als Kategorieabbildung benutzt werden kann, finden Sie bei [...]

  24. Rene Mervyn Says:

    Very rarely I can see cool theme for wordpress. There are very nice themes, but very complicated to set up. I have installed recent versions of Designora, Businezz, Jarrah, Traction, also I have tried also BAsense – simple, but made for adsense. Not very often we can find something cool but good in settings.

Leave a Reply