[SOLVED] Products: Show image from added category field

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
swanriver
Forum Members
Forum Members
Posts: 44
Joined: Sun Apr 29, 2007 5:24 pm
Location: Cape Cod, Massachusetts

[SOLVED] Products: Show image from added category field

Post by swanriver »

Hello,

I have been working on this particular problem for about a day and a half, and have searched several times for a solution in the forums. I'm almost reduced to tears, but really don't want to go there.

I have installed CalGuy's Ecommerce package, and am trying to get the Category Template in Products to run a thumbnail of a Category Image. The Category Image is set-up in "category fields" as an image field, and each category will have an image field called "catimage".

Here is my Category template:

Code: Select all

<div class="products_category_list">
{foreach from=$categorylist item='obj'}
  <div class="products_category">
    {* category fields are available as an array in $obj->fields *}
    {* i.e: $obj->fields.fieldname.field_value *}
    {if isset($obj->fields)}
    {foreach from=$obj->fields key='field_name' item='fielddata'}
      <div class="products_category_field">
        {$fielddata.field_prompt} = {$fielddata.field_value}<br/>
      </div>
    {/foreach}
    {/if}
    {if isset($obj->detail_url)}
      <a href="{$obj->detail_url}">Details For {$obj->name}</a>  
    {/if}
    <a href="{$obj->summary_url}">Products Matching {$obj->name}</a>({$obj->count})
  </div>
{/foreach}
</div>
Please note: I took out all of the edits I have made to the Category Template because they didn't work anyway.

This is how the Category Template appears on the front end:

Code: Select all

Category Image = DSC_0384.jpg
(This is link)Details For Animals   (This is link)Products Matching Animals(1)
Category Image = Sheep-BW.jpg
(This is link)Details For Black & White   (This is link)Products Matching Black & White(1)
What I would like is to have a category image appear, which user will then click on and a list of products within that category will appear. (I already have summary template working, which is weird, yeah, I know.) So why can't I get this template to work in the same way?

Any help would be truly appreciated.
Last edited by swanriver on Fri Aug 12, 2011 10:26 pm, edited 1 time in total.
swanriver
Forum Members
Forum Members
Posts: 44
Joined: Sun Apr 29, 2007 5:24 pm
Location: Cape Cod, Massachusetts

Re: Products: Show image from added category field

Post by swanriver »

Sorry. So frazzled on this one I forgot to put in proper information.

CMS Version 1.9.4.2

Installed Modules

CMSMailer 2.0.1
FileManager 1.1.0
MenuManager 1.7.6
ModuleManager 1.4.2
News 2.11.3
nuSOAP 1.0.2
Search 1.6.10
CGExtensions 1.26.4
SEOTools 1.2
FormBuilder 0.7
Orders 1.13
Products 2.13.3
PaypalGateway 2.3.5
CGSimpleSmarty 1.4.8
FrontEndUsers 1.14
CustomContent 1.7.3
CGEcommerceBase 1.3.3
Cart 1.8.1
CGPaymentGatewayBase 1.0.11
SelfRegistration 1.6.12

Any input would be really appreciated. I just can't figure this one out, hard as I have tried. Thanks!
swanriver
Forum Members
Forum Members
Posts: 44
Joined: Sun Apr 29, 2007 5:24 pm
Location: Cape Cod, Massachusetts

Re: Products: Show image from added category field

Post by swanriver »

I have tried a few things, but nothing seems to get an image to appear. Here is an updated look at the Category List Template:

Code: Select all

<div class="products_category_list">
{foreach from=$categorylist item='obj'}
  <div class="products_category">
    {* category fields are available as an array in $obj->fields *}
    {* i.e: $obj->fields.fieldname.field_value *}
    {if isset($obj->fields)}
    {foreach from=$obj->fields key='field_name' item='fielddata'}
      <div class="products_category_field">
{* ADDED *}
{foreach from=$entry->fields key='name' item='field'}   
        {if $field->type == 'image' && isset($field->thumbnail)}
          <img src="{$entry->file_location}/{$field->thumbnail}" alt="{$field->value}"/>
        {/if}
{/foreach}
{* END ADDED *}
        {$fielddata.field_prompt} = {$fielddata.field_value}
      </div>
    {/foreach}
    {/if}
    {if isset($obj->detail_url)}
      <a href="{$obj->detail_url}">Details For {$obj->name}</a>  
    {/if}
    <a href="{$obj->summary_url}">Products Matching {$obj->name}</a>({$obj->count})
  </div>
{/foreach}
</div>
Any suggestions? Should I resort to bribery?
Last edited by swanriver on Sat Aug 13, 2011 11:03 am, edited 1 time in total.
tralli

Re: Products: Show image from added category field

Post by tralli »

I don't think you can store an image for each category, but to access product image you would do it like this:

Code: Select all

<img src="{root_url}/uploads/Products/product_{$entry->id}/{$entry->fields.field_name->value}" alt="" border="0" />
replace 'field_name' with the name of your image field
swanriver
Forum Members
Forum Members
Posts: 44
Joined: Sun Apr 29, 2007 5:24 pm
Location: Cape Cod, Massachusetts

Re: Products: Show image from added category field

Post by swanriver »

Thanks tralli! You've got me thinking! A bit of my mental block has gone. Using your img tag as a basis, I put in an address to a specific photo:

Code: Select all

<img src="uploads/Products/categories/{* $entry->catid *}6/{* $entry->fields.catimage->value *}preview_DSC_0384.jpg" alt="" border="0" />
Commented out {$entry->catid} and {$entry->fields.catimage->value} because they weren't showing a value at all.

"6" is the category ID, and "preview_DSC_0384.jpg" is the file name of the image.

Now all I have to do is figure out how to call the category id and the category image. Feeling better and can now stop pulling my hair out!
tralli

Re: Products: Show image from added category field

Post by tralli »

Have you tried inserting {get_template_vars} or even {$some_array|print_r} to see what variables you have access to?
swanriver
Forum Members
Forum Members
Posts: 44
Joined: Sun Apr 29, 2007 5:24 pm
Location: Cape Cod, Massachusetts

[SOLVED] Products: Show image from added category field

Post by swanriver »

First off, thank you so very much tralli. I have finally figured it out with your help! So here is the answer (drum roll please)

Code: Select all

<img src="uploads/Products/categories/{$obj->id}/preview_{$fielddata.field_value}" alt="" border="0" />
I need to clean up the code a bit, but at least it is working as it should.

Hope this helps someone else. And tralli, if I knew where you were I would send you home baked cookies or something to show how much I appreciate your help. This really saved my bacon!

;D
tralli

Re: [SOLVED] Products: Show image from added category field

Post by tralli »

About those cookies, nah they'll get cold before they get to Iceland :)

Anyway, glad to help, I know how frusterating 3rd party addons can be that provide little or no documentations.
Post Reply

Return to “Modules/Add-Ons”